1 """ @file LoadConfig.py 2 Defines the CrombieTools.LoadConfig package 3 @author Daniel Abercrombie <dabercro@mit.edu> 5 @package CrombieTools.LoadConfig 6 Package that loads local [configuration files](@ref envconfig) into environment. 14 """Sources bash files and loads the resulting environment into os.environ 16 @param configs is a list of file names that should be searched for. 17 A string for a single configuration file is also accepted. 19 if type(configs) == str:
21 elif type(configs) == list:
22 for config
in configs:
23 if os.path.exists(config):
24 configContents = subprocess.Popen([
'bash',
'-c',
'source ' + config +
'; env'],
25 stdout = subprocess.PIPE)
26 for line
in configContents.stdout:
27 if type(line) == bytes:
28 (key,sep,value) = line.decode(
'utf-8').partition(
'=')
29 elif type(line) == str:
30 (key,sep,value) = line.partition(
'=')
32 print(
'Not sure how to handle subprocess output. Contact Dan.')
34 os.environ[str(key)] = str(value).
strip(
'\n')
36 configContents.communicate()
38 print 'You passed an invalid argument type to CrombieTools.LoadConfig.LoadEnv()' 43 """Loads and returns a python file named in the environment as a module. 45 @param EnvVarName is an environment variable containing the name of a local .py file. 46 @returns the module handler from importing the .py file. 48 if not os.environ.get(EnvVarName) ==
None:
49 if os.path.exists(os.environ[EnvVarName]):
50 return __import__(os.environ[EnvVarName].
strip(
'.py'), globals(), locals(), [], -1)
54 """List of configuration files that this module tries to load automatically.""" 55 CrombieConfigs = [
'CrombieAnalysisConfig.sh',
'CrombiePlotterConfig.sh',
'CrombieSlimmingConfig.sh']
59 """ Sub module set by the [$CrombieCutsFile](@ref envconfig) environment variable."""