- # Parse (possibly augmented) commandline args with argparse normally.
- #config.update(vars(args.parse_args()))
+ # Look for loadfile and read/parse it if present.
+ loadfile = None
+ saw_other_args = False
+ grab_next_arg = False
+ for arg in sys.argv[1:]:
+ if 'config_loadfile' in arg:
+ pieces = arg.split('=')
+ if len(pieces) > 1:
+ loadfile = pieces[1]
+ else:
+ grab_next_arg = True
+ elif grab_next_arg:
+ loadfile = arg
+ else:
+ saw_other_args = True
+
+ if loadfile is not None:
+ if saw_other_args:
+ msg = f'Augmenting commandline arguments with those from {loadfile}.'
+ print(msg, file=sys.stderr)
+ saved_messages.append(msg)
+ if not os.path.exists(loadfile):
+ print(f'ERROR: --config_loadfile argument must be a file, {loadfile} not found.',
+ file=sys.stderr)
+ sys.exit(-1)
+ with open(loadfile, 'r') as rf:
+ newargs = rf.readlines()
+ newargs = [arg.strip('\n') for arg in newargs if 'config_savefile' not in arg]
+ sys.argv += newargs
+
+ # Parse (possibly augmented, possibly completely overwritten)
+ # commandline args with argparse normally and populate config.