diff --git a/getconfig b/getconfig index c94a10c045d2649135923306d6ea3654d81d77e2..ed438f7d1a451c86b751fbfce2868e5a4ca10c64 100755 --- a/getconfig +++ b/getconfig @@ -6,13 +6,11 @@ # import argparse -import os -import re import sys from configobj import ConfigObj -import expargparse +import update from feedback import die import package_info @@ -31,39 +29,13 @@ command_line.add_argument('-V', '--version', action='version', args = command_line.parse_args() -# Check mkexp command line - -mkexp_line = expargparse.MkexpArgumentParser() - -# Experiment configuration - -config_dir = '' -config_file = '' -config_dicts = [] - try: - update_file = open(args.update) - - for line in update_file: - match = re.match(r"^cd '(.*)'$", line) - if match: - config_dir = match.group(1) - else: - match = re.match(r"^exec '.*?' '(.*)'", line) - if match: - mkexp_args = mkexp_line.parse_args(match.group(1).split("' '")) - config_file = mkexp_args.config - config_dicts = expargparse.assigns_to_dicts(mkexp_args) - - update_file.close() + update_data = update.Update(args.update) except IOError as error: die("'{0}': {1}".format(error.filename, error.strerror)) -if not os.path.isabs(config_file): - config_file = os.path.join(config_dir, config_file) - -config_data = ConfigObj(config_file, interpolation=False) -for d in config_dicts: +config_data = ConfigObj(update_data.get_config_file(), interpolation=False) +for d in update_data.get_config_dicts(): config_data.merge(d) config_data.indent_type = ' ' diff --git a/setup.py b/setup.py index 89dbbb72ed1d343d637d83c1bff4df5a803211f3..3f090404858eac47d44f93755b550c91c5208b40 100644 --- a/setup.py +++ b/setup.py @@ -9,7 +9,7 @@ setup( author = 'Karl-Hermann Wieners', author_email = 'karl-hermann.wieners@mpimet.mpg.de', url = 'http://code.mpimet.mpg.de/projects/esmenv', - py_modules = ['_version', 'configobj', 'validate', 'feedback', 'expargparse', 'expconfig', 'files', 'package_info'], + py_modules = ['_version', 'configobj', 'validate', 'feedback', 'expargparse', 'expconfig', 'files', 'package_info', 'update'], scripts = ['mkexp', 'getexp', 'rmexp', 'diffexp', 'diffpath', 'cpexp', 'cppath', 'duexp', 'getconfig'], data_files = [('share/doc/'+package_info.name, ['doc/mkexp.pdf', 'mkexp.bash'])], platforms = ['Posix'], diff --git a/update.py b/update.py new file mode 100644 index 0000000000000000000000000000000000000000..89ab734a3c9d9eb25c130f77bdef9e96b0de4894 --- /dev/null +++ b/update.py @@ -0,0 +1,48 @@ +''' +Module for 'update' information generated by mkexp tool. + +$Id update.py -1 2019-06-28 10:10:05Z m221078 $ +''' + +import os +import re + +import expargparse + +class Update: + '''Object containing 'update' information generated by mkexp tool + ''' + def __init__(self, update_name): + + # Experiment configuration + + self.config_dir = None + self.mkexp_args = None + + # Read data from update file + + update_file = open(update_name) + + for line in update_file: + match = re.match(r"^cd '(.*)'$", line) + if match: + self.config_dir = match.group(1) + else: + match = re.match(r"^exec '.*?' '(.*)'", line) + if match: + # Check mkexp command line + mkexp_line = expargparse.MkexpArgumentParser() + self.mkexp_args = \ + mkexp_line.parse_args(match.group(1).split("' '")) + + update_file.close() + + def get_config_file(self): + config_file = self.mkexp_args.config + if not os.path.isabs(config_file): + config_file = os.path.join(self.config_dir, config_file) + return config_file + + def get_config_dicts(self): + return expargparse.assigns_to_dicts(self.mkexp_args) +