diff --git a/CHANGES.txt b/CHANGES.txt index c3347196324a062653cca676a7f83abceda23298..1e4bc8441ed8855ff0f23861889e34fee677fa0e 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -19,6 +19,11 @@ Templates * Allow use of iterators with 'list' and 'join' filters +Tools +----- + +* editexp: allow editing additional files from experiment and mkexp path + Release 1.2.0 ============= diff --git a/editexp b/editexp index 8a12379040e38c3cc6fda64d118c442bac7417ba..6a4b7fa5c42dc609c85fded3b4541fe574be264f 100755 --- a/editexp +++ b/editexp @@ -9,7 +9,7 @@ import argparse import os import update -from feedback import die +import feedback import package_info @@ -21,17 +21,43 @@ import package_info command_line = argparse.ArgumentParser(description= 'Edit experiment config for given update file') -command_line.add_argument('update', nargs='?', default='update', +command_line.add_argument('-u', '--update', default='update', help='update script file name [%(default)s]') +command_line.add_argument('-v', '--verbose', action='count', default=0, + help='enable informational output' + ', repeat for debug output') command_line.add_argument('-V', '--version', action='version', version=package_info.version) +command_line.add_argument('files', nargs='*', default=[], + help='files to edit instead of experiment config') args = command_line.parse_args() +if args.verbose: + feedback.setLevel(feedback.INFO if args.verbose == 1 else feedback.DEBUG) +feedback.debug('no debugging info available') + try: update_data = update.Update(args.update) - editor = os.environ.get('VISUAL', os.environ.get('EDITOR', 'vi')) - os.execlp(editor, editor, update_data.get_config_file()) + if not args.files: + args.files.append(update_data.get_config_file()) + files = [] + for name in args.files: + if os.path.isabs(name): + files.append(name) + else: + for dirname in update_data.mkexp_path: + if not os.path.isabs(dirname): + dirname = os.path.join(update_data.get_config_dir(), dirname) + fullname = os.path.join(dirname, name) + if os.path.exists(fullname): + files.append(fullname) + break + else: + feedback.info(f"skipping non-existent '{fullname}'") + if files: + editor = os.environ.get('VISUAL', os.environ.get('EDITOR', 'vim')) + os.execlp(editor, editor, *files) except IOError as error: - die("'{0}': {1}".format(error.filename, error.strerror)) + feedback.die("'{0}': {1}".format(error.filename, error.strerror)) diff --git a/update.py b/update.py index 4bd282fe2346ebb391ffe617ad3c340681f9e038..9953f72f5ac160b97a33015c2a4496d3f449182d 100644 --- a/update.py +++ b/update.py @@ -46,25 +46,35 @@ class Update: update_file = open(update_name) for line in update_file: + # Get original working directory match = re.match(r"cd '(.*)'$", line) if match: self.config_dir = match.group(1) - else: - # Support older update file formats - match =(re.match(r"set - '.*?' '(.*)'", line) or - 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("' '")) - break + continue + # Get original setup search path + match = re.match(r"MKEXP_PATH='(.*)'$", line) + if match: + self.mkexp_path = match.group(1).split(os.path.pathsep) + continue + # Get original command line. + # Support older update file formats + match =(re.match(r"set - '.*?' '(.*)'", line) or + 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("' '")) + break update_file.close() def get_config_dir(self): return self.config_dir + def get_mkexp_path(self): + return self.mkexp_path + def get_config_file(self): config_file = self.mkexp_args.config if not os.path.isabs(config_file):