From b0695678295f9c647311df5b95cfe1f3a33fa651 Mon Sep 17 00:00:00 2001
From: FSMPI Admin-Team <admin@fsmpi.rwth-aachen.de>
Date: Mon, 12 Jun 2017 15:30:19 +0200
Subject: [PATCH] Configurable config file path

---
 lvmsnapshot.py | 22 ++++++++++++----------
 1 file changed, 12 insertions(+), 10 deletions(-)

diff --git a/lvmsnapshot.py b/lvmsnapshot.py
index 75177bb..3d30439 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]()
     
-- 
GitLab