diff options
-rwxr-xr-x | contractor | 35 |
1 files changed, 35 insertions, 0 deletions
@@ -14,6 +14,10 @@ from subprocess import PIPE, STDOUT import yaml +# Default configuration files. +DEFAULT_CONFIGS = {os.path.expanduser("~/.config/contractor/config.yaml")} + + # The device in the manager VM for the workspace disk. WS_DEV = "/dev/vdb" @@ -648,8 +652,35 @@ def setup_logging(args): logger.setLevel(logging.DEBUG) +def load_default_config(args): + for filename in DEFAULT_CONFIGS: + if os.path.exists(filename): + load_config(filename, args) + + +def load_config(filename, args): + with open(filename) as f: + config = yaml.safe_load(f) + + keys = { + "manager_address": None, + "manager_port": None, + "manager_user": None, + "verbose": None, + "log": os.path.expanduser, + } + for key in keys: + if key in config: + func = keys[key] + if func is None: + func = lambda x: x + setattr(args, key, func(config[key])) + + def main(): p = argparse.ArgumentParser() + p.add_argument("-C", "--use-default-config", action="store_true") + p.add_argument("-c", "--config") p.add_argument("-v", "--verbose", action="store_true") p.add_argument("--log", help="log to a file") @@ -678,6 +709,10 @@ def main(): build.set_defaults(func=cmd_build, **manager_defaults) args = p.parse_args() + if args.use_default_config: + load_default_config(args) + if args.config: + load_config(args.config, args) setup_logging(args) args.func(args) |