diff --git a/lvmsnapshot.py b/lvmsnapshot.py index 75177bbb1c07f6fcb88867e2edc962e9d348dea7..3d304390e4565d3bb7f8448b46fcd4360e2c386b 100644 --- a/lvmsnapshot.py +++ b/lvmsnapshot.py @@ -46,15 +46,16 @@ class Config: periods = {} @staticmethod - def load(): + def load(config_path=None): import toml - config_path = "config.toml" - global_config_path = "/etc/lvm-snapshot.toml" - ENV_VAR = "LVM_SNAPSHOT_CONFIG" - if not os.path.isfile(config_path) and os.path.isfile(global_config_path): - config_path = global_config_path - if ENV_VAR in os.environ: - config_path = os.environ[ENV_VAR] + if config_path is None: + config_path = "config.toml" + global_config_path = "/etc/lvm-snapshot.toml" + ENV_VAR = "LVM_SNAPSHOT_CONFIG" + if not os.path.isfile(config_path) and os.path.isfile(global_config_path): + config_path = global_config_path + if ENV_VAR in os.environ: + config_path = os.environ[ENV_VAR] with open(config_path, "r") as config_file: return toml.load(config_file) @@ -429,7 +430,8 @@ operations = { def main(): import argparse parser = argparse.ArgumentParser(description="Manage snapshots of thin LVM volumes") - parser.add_argument("command", choices=["list", "update", "mount", "unmount"], default="list") + parser.add_argument("command", choices=["list", "update", "mount", "unmount"], default="list", nargs="?") + parser.add_argument("--config", help="path to config file", required=False) parser.add_argument("--verbose", "-v", action="count", help="do not redirect the command output to /dev/null") args = parser.parse_args() loglevels = { @@ -440,7 +442,7 @@ def main(): } loglevel = loglevels[min(3, max(0, args.verbose or 0))] logging.basicConfig(level=loglevel) - Config.parse(Config.load()) + Config.parse(Config.load(args.config)) operations[args.command]()