Skip to content

Commit

Permalink
🌂
Browse files Browse the repository at this point in the history
  • Loading branch information
jennydaman committed Sep 17, 2021
0 parents commit fcae8ed
Show file tree
Hide file tree
Showing 17 changed files with 443 additions and 0 deletions.
20 changes: 20 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
.git/
.github/
.dockerignore
Dockerfile

*~
*.DS_Store
*.egg-info
__pycache__
docs/build
.coverage
htmlcov
venv
.docker

.idea/
.vscode/

examples/

165 changes: 165 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,165 @@
# Automatically build multi-architectural tagged container images and push them to DockerHub
# https://github.com/FNNDSC/cookiecutter-chrisapp/wiki/Automatic-Builds
#
# - targeted platforms: x86_64, PowerPC64, ARM64
# - master is built as fnndsc/pl-office-convert:latest
# - tagged commits are built as fnndsc/pl-office-convert:<tag>
# - tagged commits are also uploaded to chrisstore.co
#
# In order to use this workflow, see
# https://github.com/FNNDSC/cookiecutter-chrisapp/wiki/Automatic-Builds#steps-to-enable

name: ci

on:
push:
branches: [ master ]
tags: [ '**' ]
pull_request:
branches: [ master ]

jobs:
test:
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v2
- name: Build
run: docker build -t pl-office-convert .
- name: Run example
id: run_example
run: |
test_output=$(mktemp -d)
docker run --rm \
-v $GITHUB_WORKSPACE/examples/incoming:/incoming:ro \
-v $test_output:/outgoing:rw \
pl-office-convert /incoming /outgoing
echo "::set-output name=output_dir::test_output"
- name: Assert outputs
run: diff -rq '${{ github.workspace }}/examples/incoming' '${{ steps.run_example.outputs.output_dir }}'

publish:
if: github.event_name == 'push' || github.event_name == 'release'
runs-on: ubuntu-20.04

# we want to both push the build to DockerHub, but also
# keep a local copy so that we can run
#
# docker run fnndsc/pl-office-convert office_convert --json > OfficeConvert.json
#
# buildx currently does not support multiple output locations,
# neither can multi-architectural builds be loaded into docker.
# Here we use a local registry to cache the build.
services:
registry:
image: registry:2
ports:
- 5000:5000

steps:
- name: Get git tag
id: git_info
if: startsWith(github.ref, 'refs/tags/')
run: echo "::set-output name=tag::${GITHUB_REF##*/}"
- name: Decide image tag name
id: determine
env:
git_tag: ${{ steps.git_info.outputs.tag }}
run: |
repo="${GITHUB_REPOSITORY,,}" # to lower case
# if build triggered by tag, use tag name
tag="${git_tag:-latest}"
dock_image=$repo:$tag
echo $dock_image
echo "::set-output name=dock_image::$dock_image"
echo "::set-output name=repo::$repo"
- uses: actions/checkout@v2

# QEMU is for emulating non-x86_64 platforms
- uses: docker/setup-qemu-action@v1
# buildx is the next-generation docker image builder
- uses: docker/setup-buildx-action@v1
with:
driver-opts: network=host
# save some time during rebuilds
- name: Cache Docker layers
uses: actions/cache@v2
with:
path: /tmp/.buildx-cache
key: ${{ runner.os }}-buildx-${{ github.sha }}
restore-keys: |
${{ runner.os }}-buildx-
- name: Login to DockerHub
id: dockerhub_login
uses: docker/login-action@v1
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_PASSWORD }}

- name: Build and push
uses: docker/build-push-action@v2
id: docker_build
with:
context: .
file: ./Dockerfile
tags: |
${{ steps.determine.outputs.dock_image }}
localhost:5000/${{ steps.determine.outputs.dock_image }}
platforms: linux/amd64
push: true
cache-from: type=local,src=/tmp/.buildx-cache
cache-to: type=local,dest=/tmp/.buildx-cache

- name: Get plugin meta
id: pluginmeta
run: |
repo=${{ steps.determine.outputs.repo }}
dock_image=${{ steps.determine.outputs.dock_image }}
docker pull localhost:5000/$dock_image
docker tag localhost:5000/$dock_image $dock_image
script=$(docker inspect --format '{{ (index .Config.Cmd 0) }}' $dock_image)
json="$(docker run --rm $dock_image $script --json)"
jq <<< "$json" # pretty print in log
echo "::set-output name=json::$json"
echo "::set-output name=title::$(jq -r '.title' <<< "$json")"
- name: Update DockerHub description
uses: peter-evans/dockerhub-description@v2
continue-on-error: true # it is not crucial that this works
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_PASSWORD }}
short-description: ${{ steps.pluginmeta.outputs.title }}
readme-filepath: ./README.rst
repository: ${{ steps.determine.outputs.repo }}

- name: Upload to ChRIS Store
if: "!endsWith(steps.determine.outputs.dock_image, ':latest')"
run: |
dock_image=${{ steps.determine.outputs.dock_image }}
plname="$(sed 's/^.*\///' <<< $GITHUB_REPOSITORY)" && echo "name=$plname"
descriptor_file=$(mktemp --suffix .json)
cat > $descriptor_file << ENDOFPLUGINJSONDESCRIPTION
${{ steps.pluginmeta.outputs.json }}
ENDOFPLUGINJSONDESCRIPTION
res=$(
curl -s -u "${{ secrets.CHRIS_STORE_USER }}" "https://chrisstore.co/api/v1/plugins/" \
-H 'Accept:application/vnd.collection+json' \
-F "name=$plname" \
-F "dock_image=$dock_image" \
-F "descriptor_file=@$descriptor_file" \
-F "public_repo=https://github.com/${{ github.repository }}"
)
success=$?
echo "::debug::$res"
if [ "$success" = "0" ]; then
href="$(jq -r '.collection.items[0].href' <<< "$res")"
echo $href
echo "::set-output name=pluginurl::$href"
else
echo "::error ::Failed upload to ChRIS Store"
echo "$res"
exit $success
fi
10 changes: 10 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
*~
*.DS_Store
*.egg-info
__pycache__
docs/build
.coverage
htmlcov
.docker
.idea/
.vscode/
15 changes: 15 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
FROM docker.io/python:3.9.1-slim-buster

LABEL org.opencontainers.image.authors="FNNDSC <[email protected]>" \
org.opencontainers.image.title="Office File Converter" \
org.opencontainers.image.description="Convert Excel and ODS spreadsheets to plaintext CSV files."

WORKDIR /usr/local/src

COPY requirements.txt .
RUN pip install -r requirements.txt

COPY . .
RUN pip install .

CMD ["office_convert", "--help"]
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2021 FNNDSC / BCH

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
26 changes: 26 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Excel and ODS Spreadsheet to CSV Converter

[![Version](https://img.shields.io/docker/v/fnndsc/pl-office-convert?sort=semver)](https://hub.docker.com/r/fnndsc/pl-office-convert)
[![MIT License](https://img.shields.io/github/license/fnndsc/pl-office-convert)](https://github.com/FNNDSC/pl-office-convert/blob/master/LICENSE)
[![Build](https://github.com/FNNDSC/pl-office-convert/actions/workflows/ci.yml/badge.svg)](https://github.com/FNNDSC/pl-office-convert/actions)

`pl-office-convert` is a _ChRIS ds_ plugin which converts Excel and OpenOffice spreadsheet file
formats (`*.{xls,xlsx,ods}`) to the plaintext comma-separated values (`*.csv`) format.

## Usage

In `pl-office-convert` version 0.0.1 there are no options.
Every file in `inputdir/` ending with `.ods`, `.xlsx`, or `.xls` gets processed and written to
`outputdir/` by the same filename but with its file extension replaced with `.csv`.
Every other file in `inputdir/` is simply duplicated to `outputdir/`.

WARNING: only the first sheet of every file is converted!

```shell
singularity exec docker://docker.io/fnndsc/pl-office-convert:0.0.1 office_convert incoming/ outgoing/
```

## Planned Features

This plugin will eventually be a generic office format converter, being able to convert both ways from
office file format to plaintext and vice versa. But for now it is a simple single-purpose program.
Binary file added examples/incoming/menu.xlsx
Binary file not shown.
Binary file added examples/incoming/nonsense.ods
Binary file not shown.
3 changes: 3 additions & 0 deletions examples/outgoing/menu.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
food,price
pizza,3.0
fries,2.5
5 changes: 5 additions & 0 deletions examples/outgoing/nonsense.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
hello,how,are,you?
5,blue,arch,grape
6,red,fedora,cherry
7,green,debian,kiwi
8,purple,solus,tomato
3 changes: 3 additions & 0 deletions examples/wack/menu.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
mmmfood,price
pizza,3.0
fries,2.5
5 changes: 5 additions & 0 deletions examples/wack/nonsense.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
hello,how,are,you?
5,blue,arch,grape
6,red,fedora,cherry
7,green,debian,kiwi
8,purple,solus,tomato
Empty file added office_convert/__init__.py
Empty file.
12 changes: 12 additions & 0 deletions office_convert/__main__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
from office_convert.app import OfficeFileConverter
import logging


def main():
logging.basicConfig()
chris_app = OfficeFileConverter()
chris_app.launch()


if __name__ == "__main__":
main()
Loading

0 comments on commit fcae8ed

Please sign in to comment.