From 22908e47cb0cec8a1f7696fab4a1c47b441c9a1b Mon Sep 17 00:00:00 2001 From: David Welch Date: Wed, 20 Aug 2014 10:48:59 -0500 Subject: [PATCH] BUG: Fixed typo in configFileParser.py STYLE: Ran autopep8 on AutoWorkup.py ENH: Added commandline testing for configFileParser.py --- AutoWorkup/AutoWorkup.py | 21 ++++++++++++--------- AutoWorkup/utilities/configFileParser.py | 23 +++++++++++++++++------ 2 files changed, 29 insertions(+), 15 deletions(-) diff --git a/AutoWorkup/AutoWorkup.py b/AutoWorkup/AutoWorkup.py index 27fc560017..31a21b1fc8 100644 --- a/AutoWorkup/AutoWorkup.py +++ b/AutoWorkup/AutoWorkup.py @@ -1,5 +1,6 @@ #! /usr/bin/env python + def load_modules(modules): """ The command 'module' is actually a script call in bash: @@ -13,36 +14,38 @@ def load_modules(modules): def setup(argv): print "Configuring environment..." - import os, os.path + import os + import os.path from utilities.configFileParser import resolveDataSinkOption, parseFile from utilities.pathHandling import validatePath from utilities import misc - environment, experiment, pipeline, cluster = parseFile(argv["--ExperimentConfig"], argv["--pe"], argv["--workphase"]) + environment, experiment, pipeline, cluster = parseFile( + argv["--ExperimentConfig"], argv["--pe"], argv["--workphase"]) pipeline['ds_overwrite'] = resolveDataSinkOption(argv, pipeline) - if cluster is None: assert argv["--wf_template_runner"] in misc.WFRUN, \ - "wf_template_runner options for clusters can only be given when the configuration file's CLUSTER option == True" + "wf_template_runner options for clusters can only be given when the configuration file's CLUSTER option == True" os.environ['NSLOTS'] = str(misc.get_cpus(argv["--wf_template_runner"])) else: load_modules(cluster['modules']) # Load modules if not already done ## MODS PATH # print os.environ['LOADEDMODULES'] - if environment['virtualenv_dir']: ## MODS PATH - activate_this = validatePath(os.path.join(environment['virtualenv_dir'], 'bin', 'activate_this.py'), False, False) + if environment['virtualenv_dir'] is not None: # MODS PATH + activate_this = validatePath( + os.path.join(environment['virtualenv_dir'], 'bin', 'activate_this.py'), False, False) execfile(activate_this, dict(__file__=activate_this)) utilities_path = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'utilities') configure_env = validatePath(os.path.join(utilities_path, 'configure_env.py'), False, False) # Add the AutoWorkup directory to the PYTHONPATH every time - REQUIRED FOR CLUSTER DISPATCHING - environment['env']['PYTHONPATH'] = environment['env']['PYTHONPATH'] + ":" + os.path.dirname(__file__) + environment['env']['PYTHONPATH'] = environment['env']['PYTHONPATH'] + ":" + os.path.dirname(__file__) execfile(configure_env, dict(__file__=__file__, append_os_path=environment['env']['PATH'], append_sys_path=environment['env']['PYTHONPATH']) - ) ## MODS PATH + ) # MODS PATH from nipype import config config.enable_debug_mode() from utilities.package_check import verify_packages verify_packages() - if 'FREESURFER' in experiment['components']: ## FREESURFER MODS + if 'FREESURFER' in experiment['components']: # FREESURFER MODS configure_FS = validatePath(os.path.join(utilities_path, 'utilities', 'configure_FS.py'), False, False) execfile(configure_FS, dict(FS_VARS=misc.FS_VARS, env=environment['env'])) print "FREESURFER needs to check for sane environment here!" # TODO: raise warning, write method, what??? diff --git a/AutoWorkup/utilities/configFileParser.py b/AutoWorkup/utilities/configFileParser.py index 29b0a3e6b3..7ab32700d8 100644 --- a/AutoWorkup/utilities/configFileParser.py +++ b/AutoWorkup/utilities/configFileParser.py @@ -5,17 +5,18 @@ =================== Usage: - configFileParser.py [--debug] ENV FILE + configFileParser.py [--debug] ENV PHASE FILE configFileParser.py (-h | --help | -v | --version) Arguments: ENV Environment name in configuration file + PHASE Workflow phase to use: atlas-based-reference, subject-template-generation or subject-based-reference FILE Configuration file Options: -h, --help Print this and exit -v, --version Print file version and exit - --debug Run doctests for file + --debug Run doctests for file # TODO """ from ConfigParser import ConfigParser import os @@ -49,7 +50,7 @@ def parseEnvironment(parser, section): retval['prefix'] = validatePath(parser.get(section, 'MOUNT_PREFIX'), True, True) if retval['prefix'] is None: retval['prefix'] = '' - if parser.has_option(section, 'VIRTUALENV'): + if parser.has_option(section, 'VIRTUALENV_DIR'): retval['virtualenv_dir'] = validatePath(parser.get(section, 'VIRTUALENV_DIR'), False, True) else: retval['virtualenv_dir'] = None @@ -253,7 +254,17 @@ def nipype_options(args, pipeline, cluster, experiment, environment): if __name__ == "__main__": from docopt import docopt - + SILENT = True args = docopt(__doc__, version='0.1') # Get argv as dictionary - # TODO: Add and run doctests! - print parseFile(args["FILE"], args["ENV"]) + assert args["PHASE"] in ['atlas-based-reference', + 'subject-template-generation', 'subject-based-reference'], "Unknown phase!" + if args['--debug']: + # TODO: Add and run doctests! + pass + output = parseFile(args["FILE"], args["ENV"], args["PHASE"]) + from pprint import pprint + print "" + print "**** OUTPUT ****" + for d in output: + pprint(d) + print ""