Add commandline options for configuration files.
authorMatthijs Kooijman <matthijs@stdin.nl>
Thu, 10 Jun 2010 07:00:01 +0000 (09:00 +0200)
committerMatthijs Kooijman <matthijs@stdin.nl>
Thu, 10 Jun 2010 07:00:01 +0000 (09:00 +0200)
src/backupninja
src/lib/backupninja/config.py

index e351c62..a77242d 100755 (executable)
@@ -35,7 +35,30 @@ log = logging.getLogger()
 def make_option_parser():
     description = """%prog checks for scheduled actions and runs them when needed."""
     parser = optparse.OptionParser(description=description)
-
+    parser.add_option( "-c", "--confdir"
+                     , help="Load configuration from CONFIG_DIR "
+                            "instead of '%default'. When "
+                            "the --conffile or --actionsdir options "
+                            "specify relative paths, they are taken "
+                            "relative to this directory."
+                     , default="/etc/backupninja"
+                     , dest="config_dir"
+                     , metavar="CONFIG_DIR")
+    parser.add_option( "-f", "--conffile"
+                     , help="Load the main configuration from FILE instead "
+                            "of '%default'. If FILE is a relative path, it "
+                            "is interpreted relative to CONFIG_DIR."
+                     , default='backupninja.conf'
+                     , dest="global_config"
+                     , metavar="FILE")
+    parser.add_option( "-a", "--actionsdir"
+                     , help="Load action configurations from ACTIONS_DIR "
+                            "instead of '%default'. If ACTIONS_DIR is a "
+                            "relative path, it is interpreted relative to "
+                            "CONFIG_DIR."
+                     , default="actions"
+                     , dest="actions_dir"
+                     , metavar="ACTIONS_DIR")
     return parser
  
 def main(argv):
index af3d4da..0246efe 100644 (file)
@@ -37,7 +37,7 @@ def get_global_config(opts):
 
     opts are the parsed commandline options.
     """
-    global_config = os.path.join(default_config_dir, default_global_config)
+    global_config = os.path.join(opts.config_dir, opts.global_config)
     return _load_config(global_config)
 
 def get_action_config(opts, action):
@@ -48,7 +48,7 @@ def get_action_config(opts, action):
 
     opts are the parsed commandline options.
     """
-    actions_dir = os.path.join(default_config_dir, default_actions_dir)
+    actions_dir = os.path.join(opts.config_dir, opts.actions_dir)
     return _load_config(os.path.join(actions_dir, action))
 
 def list_actions(opts):
@@ -57,7 +57,7 @@ def list_actions(opts):
     list of action names that can be passed to get_action_config.
     opts are the parsed commandline options.
     """
-    actions_dir = os.path.join(default_config_dir, default_actions_dir)
+    actions_dir = os.path.join(opts.config_dir, opts.actions_dir)
     return os.listdir(actions_dir)
     
 def _load_config(filename):