diff options
author | Joshua Shreve <j.a.shreve@gmail.com> | 2021-08-21 15:54:57 -0400 |
---|---|---|
committer | Joshua Shreve <j.a.shreve@gmail.com> | 2021-08-21 15:54:57 -0400 |
commit | 4c179f900053db8acb072cf6eb6e73b40293fea7 (patch) | |
tree | a4a043b49629cb897544128e73c27163d231f36c /src | |
parent | 1f6206c9fe3bc7b85dd624550020452567921400 (diff) | |
parent | 3a74bee2fcd1561f5cf23a4f57fe41062203313e (diff) |
Merge branch 'pr/30'
Diffstat (limited to 'src')
-rw-r--r-- | src/dactyl_manuform.py | 15 | ||||
-rw-r--r-- | src/generate_configuration.py | 30 |
2 files changed, 24 insertions, 21 deletions
diff --git a/src/dactyl_manuform.py b/src/dactyl_manuform.py index 0fd4be6..1dc1507 100644 --- a/src/dactyl_manuform.py +++ b/src/dactyl_manuform.py @@ -1,6 +1,7 @@ import numpy as np from numpy import pi import os.path as path +import getopt, sys import json import os @@ -23,11 +24,15 @@ import generate_configuration as cfg for item in cfg.shape_config: locals()[item] = cfg.shape_config[item] -## LOAD RUN CONFIGURATION FILE AND WRITE TO ANY VARIABLES IN FILE. -with open('run_config.json', mode='r') as fid: - data = json.load(fid) -for item in data: - locals()[item] = data[item] +## CHECK FOR CONFIG FILE AND WRITE TO ANY VARIABLES IN FILE. +opts, args = getopt.getopt(sys.argv[1:], "", ["config="]); +for opt, arg in opts: + if opt in ('--config'): + with open(os.path.join(r"..", "configs", arg + '.json'), mode='r') as fid: + data = json.load(fid) + for item in data: + locals()[item] = data[item] + # Really rough setup. Check for ENGINE, set it not present from configuration. try: diff --git a/src/generate_configuration.py b/src/generate_configuration.py index ee70e3b..79ef5b3 100644 --- a/src/generate_configuration.py +++ b/src/generate_configuration.py @@ -1,3 +1,6 @@ +import sys +import getopt +import os import json @@ -383,23 +386,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/<config_name>.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 |