Skip to content

Commit

Permalink
BUG: Fixed typo in configFileParser.py
Browse files Browse the repository at this point in the history
STYLE: Ran autopep8 on AutoWorkup.py
ENH: Added commandline testing for configFileParser.py
  • Loading branch information
dmwelch committed Aug 20, 2014
1 parent 7aba5b1 commit 22908e4
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 15 deletions.
21 changes: 12 additions & 9 deletions AutoWorkup/AutoWorkup.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#! /usr/bin/env python


def load_modules(modules):
""" The command 'module' is actually a script call in bash:
Expand All @@ -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???
Expand Down
23 changes: 17 additions & 6 deletions AutoWorkup/utilities/configFileParser.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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 ""

0 comments on commit 22908e4

Please sign in to comment.