From 50f64bc155f46c10c1bdad6a6ea92a7e7d9f23ee Mon Sep 17 00:00:00 2001 From: Harsha Kethineni Date: Mon, 25 Jun 2018 12:11:26 -0500 Subject: [PATCH 1/2] use python to parse configs --- Dockerfile | 4 ++-- manifest.json | 7 ++++--- run | 56 --------------------------------------------------- run.py | 15 ++++++++++++++ 4 files changed, 21 insertions(+), 61 deletions(-) delete mode 100755 run create mode 100644 run.py diff --git a/Dockerfile b/Dockerfile index c169d74..a34cbab 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,6 +1,6 @@ # curate-bids -FROM flywheel/bids-client:0.6.2 +FROM flywheel/bids-client:0.6.3 MAINTAINER Flywheel # Install JQ to parse config file @@ -9,7 +9,7 @@ RUN apk add --no-cache jq # Make directory for flywheel spec (v0) ENV FLYWHEEL /flywheel/v0 RUN mkdir -p ${FLYWHEEL} -COPY run ${FLYWHEEL}/run +COPY run.py ${FLYWHEEL}/run.py COPY manifest.json ${FLYWHEEL}/manifest.json # Set the entrypoint diff --git a/manifest.json b/manifest.json index 0328795..3a8b972 100644 --- a/manifest.json +++ b/manifest.json @@ -6,9 +6,9 @@ "maintainer": "Flywheel ", "source": "https://github.com/flywheel-apps/curate-bids", "url": "http://bids.neuroimaging.io/", - "version": "0.6.2", + "version": "0.6.3", "custom": { - "docker-image": "flywheel/curate-bids:v0.6.2" + "docker-image": "flywheel/curate-bids:v0.6.3" }, "license": "BSD-3-Clause", "inputs": { @@ -22,5 +22,6 @@ "type": "boolean", "default": false } - } + }, + "command": "python run.py" } diff --git a/run b/run deleted file mode 100755 index fd2cc8a..0000000 --- a/run +++ /dev/null @@ -1,56 +0,0 @@ -#! /bin/bash -# -# Run script for flywheel/curate-bids Gear -# Authorship: Jennifer Reiter - -# Define directory names and containers - -FLYWHEEL_BASE=/flywheel/v0 -CONFIG_FILE=$FLYWHEEL_BASE/config.json - - -############################################################################## -# Parse configuration options - -# If config.json exists, then we parse config file and cast vals to ENV Vars -# (Flywheel gear run). Otherwise we parse manifest.json and cast the values to -# ENV Vars from manifest (Docker run) Note value.default is used to grab the -# configured defaults. - -if [[ -f $CONFIG_FILE ]]; then - eval $(jq -r '.config | to_entries[] | "config_\(.key)=\"\(.value)\""' $CONFIG_FILE) -else - CONFIG_FILE=$FLYWHEEL_BASE/manifest.json - eval $(jq -r '.config | to_entries[] | "config_\(.key)=\(.value.default)"' $CONFIG_FILE) -fi - -# Get API KEY -APIKEY=$(jq -r '.inputs.api_key.key' $CONFIG_FILE) - -# Get Session ID -CONFIG_SESSIONID=$(jq -r '.destination.id' $CONFIG_FILE) - -# Boolean parsing of reset config option -if [[ $config_reset == 'true' ]]; then - RESET_FLAG='--reset' -else - RESET_FLAG='' -fi - -############################################################################## -# Notify User that BIDS curation is being run on project label -echo "BIDS Curation templates are being run on entire Project for session: $CONFIG_SESSIONID" - -# Run curate_bids python script -curate_bids --api-key $APIKEY --session "$CONFIG_SESSIONID" ${RESET_FLAG} -curate_exit_status=$? - -############################################################################## -# Handle Exit status -if [[ $curate_exit_status == 0 ]]; then - echo -e "${CONTAINER} Success!" - exit 0 -else - echo "${CONTAINER} Something went wrong! Curate BIDS exited non-zero!" - exit 1 -fi diff --git a/run.py b/run.py new file mode 100644 index 0000000..d8e1adf --- /dev/null +++ b/run.py @@ -0,0 +1,15 @@ +import json +from flywheel_bids.curate_bids import main_with_args + +if __name__ == '__main__': + + # Grab Config + config = '/flywheel/v0/config.json' + with open(config) as configFile: + CONFIG = json.load(configFile) + + api_key = CONFIG['inputs']['api_key']['key'] + session_id = CONFIG['destination']['id'] + reset = CONFIG['config']['reset'] + + main_with_args(api_key, session_id, reset) From bf52e2da00d9663108698221a77652c00017d81d Mon Sep 17 00:00:00 2001 From: Harsha Kethineni Date: Mon, 25 Jun 2018 12:43:44 -0500 Subject: [PATCH 2/2] Style changes --- run.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/run.py b/run.py index d8e1adf..9bd8f92 100644 --- a/run.py +++ b/run.py @@ -4,12 +4,12 @@ if __name__ == '__main__': # Grab Config - config = '/flywheel/v0/config.json' - with open(config) as configFile: - CONFIG = json.load(configFile) + CONFIG_FILE_PATH = '/flywheel/v0/config.json' + with open(CONFIG_FILE_PATH) as config_file: + config = json.load(CONFIG_FILE) - api_key = CONFIG['inputs']['api_key']['key'] - session_id = CONFIG['destination']['id'] - reset = CONFIG['config']['reset'] + api_key = config['inputs']['api_key']['key'] + session_id = config['destination']['id'] + reset = config['config']['reset'] main_with_args(api_key, session_id, reset)