[prev in list] [next in list] [prev in thread] [next in thread] 

List:       lnst-developers
Subject:    [PATCH v2 2/6] lnst-ctl: add option --dump-config
From:       olichtne () redhat ! com
Date:       2015-02-20 15:48:26
Message-ID: 1424447310-32626-2-git-send-email-olichtne () redhat ! com
[Download RAW message or body]

From: Ondrej Lichtner <olichtne@redhat.com>

This commit adds a new option for the LNST controller - --dump-config.
When this option is specified, lnst-ctl will run until all configuration
files are loaded and then dump the resulting configuration on stdout.
This is useful for debugging purposes, or when including lnst in
scripts.

Since this commit the message "Loading config file ..." is printed on
stderr so that it doesn't get mixed with the dumped configuration.

Signed-off-by: Ondrej Lichtner <olichtne@redhat.com>
---
 lnst-ctl              | 10 ++++++++++
 lnst/Common/Config.py |  2 +-
 2 files changed, 11 insertions(+), 1 deletion(-)

diff --git a/lnst-ctl b/lnst-ctl
index 128b6df..e715bb8 100755
--- a/lnst-ctl
+++ b/lnst-ctl
@@ -43,6 +43,8 @@ def usage(retval=0):
     print "  -a, --define-alias name=value   define top-level alias"
     print "  -c, --config=FILE               load additional config file"
     print "  -d, --debug                     emit debugging messages"
+    print "      --dump-config               dumps the join of all loaded " \
+              "configuration files on stdout and exits"
     print "  -h, --help                      print this message"
     print "  -m, --no-colours                disable coloured terminal output"
     print "  -o, --disable-pool-checks       don't check the availability of " \
@@ -183,6 +185,7 @@ def main():
              "define_alias=",
              "config=",
              "debug",
+             "dump-config",
              "help",
              "no-colours",
              "disable-pool-checks",
@@ -231,6 +234,7 @@ def main():
     overriden_aliases = {}
     reduce_sync = False
     multi_match = False
+    dump_config = False
     for opt, arg in opts:
         if opt in ("-d", "--debug"):
             debug += 1
@@ -258,6 +262,8 @@ def main():
             xslt_url = arg
         elif opt in ("-u", "--multi-match"):
             multi_match = True
+        elif opt in ("--dump-config"):
+            dump_config = True
 
     if config_path is not None:
         if not os.path.isfile(config_path):
@@ -269,6 +275,10 @@ def main():
     if xslt_url != None:
         lnst_config.set_option("environment", "xslt_url", xslt_url)
 
+    if dump_config:
+        print lnst_config.dump_config()
+        return RETVAL_PASS
+
     if coloured_output:
         coloured_output = not lnst_config.get_option("colours",
                                                      "disable_colours")
diff --git a/lnst/Common/Config.py b/lnst/Common/Config.py
index 2e982bf..f9c4b39 100644
--- a/lnst/Common/Config.py
+++ b/lnst/Common/Config.py
@@ -151,7 +151,7 @@ class Config():
         exp_path = os.path.expanduser(path)
         abs_path = os.path.abspath(exp_path)
         parser = ConfigParser(dict_type=dict)
-        print "Loading config file '%s'" % abs_path
+        print >> sys.stderr, "Loading config file '%s'" % abs_path
         parser.read(abs_path)
 
         sections = parser._sections
-- 
2.1.0

_______________________________________________
LNST-developers mailing list
LNST-developers@lists.fedorahosted.org
https://lists.fedorahosted.org/mailman/listinfo/lnst-developers

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic