From 3a74bee2fcd1561f5cf23a4f57fe41062203313e Mon Sep 17 00:00:00 2001 From: Edward Date: Thu, 19 Aug 2021 15:40:34 -0400 Subject: allow multiple config files generate_configuration.py now only generates a configuration file; it no longer also runs dactyl_manuform.py. it will save the generated configuration file to the configs directory, and it will be named according to the config_name. passing a --config= argument to the script will set the config_name and save_dir. dactyl_manuform.py now also accepts a --config= argument. if non is passed, the default values from generate_configuration.py are used. otherwise, the defaults will be overridden by the values from the config specified. because of these changes, i removed run_config.json. it should have default values anyway, so it seemed reduandant and confusing. the run command has also been updated to allow for the config changes, and some bugs have also been fixed. --- src/generate_configuration.py | 30 ++++++++++++++---------------- 1 file changed, 14 insertions(+), 16 deletions(-) (limited to 'src/generate_configuration.py') diff --git a/src/generate_configuration.py b/src/generate_configuration.py index e2d71b0..08d02ff 100644 --- a/src/generate_configuration.py +++ b/src/generate_configuration.py @@ -1,3 +1,6 @@ +import sys +import getopt +import os import json @@ -301,23 +304,18 @@ shape_config = { #################################### def save_config(): - print("Saving Configuration") - with open('run_config.json', mode='w') as fid: - json.dump(shape_config, fid, indent=4) - -def update_config(fname, fname_out=None): - if fname_out is None: - fname_out == "updated_config.json" - # Open existing config, update with any new parameters, and save to updated_config.json - with open(fname, mode='r') as fid: - last_shape_config = json.load(fid) - shape_config.update(last_shape_config) - - with open(fname_out, mode='w') as fid: + # Check to see if the user has specified an alternate config + opts, args = getopt.getopt(sys.argv[1:], "", ["config="]); + for opt, arg in opts: + if opt in ('--config'): + # If a config file was specified, set the config_name and save_dir + shape_config['save_dir'] = arg + shape_config['config_name'] = arg + + # Write the config to ./configs/.json + with open(os.path.join(r"..", "configs", shape_config['config_name'] + '.json'), mode='w') as fid: json.dump(shape_config, fid, indent=4) if __name__ == '__main__': - save_config() - from dactyl_manuform import * - run() \ No newline at end of file + save_config() \ No newline at end of file -- cgit v1.2.3-70-g09d2