Skip to content
Snippets Groups Projects
Commit c101e054 authored by Karl-Hermann Wieners's avatar Karl-Hermann Wieners
Browse files

mkexp: moved update information to separate module

parent 8eaf74d3
No related branches found
No related tags found
No related merge requests found
......@@ -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 = ' '
......
......@@ -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'],
......
'''
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)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment