Allow overrided options with --set to show up in --ini output
authorMarko Kreen <markokr@gmail.com>
Tue, 16 Oct 2012 11:04:45 +0000 (14:04 +0300)
committerMarko Kreen <markokr@gmail.com>
Tue, 16 Oct 2012 11:04:45 +0000 (14:04 +0300)
python/londiste.py
python/skytools/scripting.py

index b6c59e15f0cd17a3b57ebfd3b520ea3dfb755cb2..66137afcf96c24b4d2b118648548dfbea7c8acb7 100755 (executable)
@@ -60,6 +60,8 @@ cmd_handlers = (
 
 class Londiste(skytools.DBScript):
     def __init__(self, args):
+        self.full_args = args
+
         skytools.DBScript.__init__(self, 'londiste3', args)
 
         if len(self.args) < 2:
@@ -80,7 +82,7 @@ class Londiste(skytools.DBScript):
 
     def print_ini(self):
         """Let the Replicator print the default config."""
-        londiste.Replicator(['--ini'])
+        londiste.Replicator(self.full_args)
 
     def init_optparse(self, parser=None):
         p = skytools.DBScript.init_optparse(self, parser)
index 12a72da9100022af5232f6e1ace6b84074309d22..049da251c7d45d8b5cd32e4e8329bcce240ed8b1 100644 (file)
@@ -273,9 +273,6 @@ class BaseScript(object):
             self.log_level = skytools.skylog.TRACE
         elif self.options.verbose:
             self.log_level = logging.DEBUG
-        if self.options.ini:
-            self.print_ini()
-            sys.exit(0)
 
         self.cf_override = {}
         if self.options.set:
@@ -283,6 +280,10 @@ class BaseScript(object):
                 k, v = a.split('=', 1)
                 self.cf_override[k.strip()] = v.strip()
 
+        if self.options.ini:
+            self.print_ini()
+            sys.exit(0)
+
         # read config file
         self.reload()
 
@@ -331,8 +332,29 @@ class BaseScript(object):
         if pos < 0:
             return
         doc = doc[pos+2 : ].rstrip()
+        doc = skytools.dedent(doc)
+
+        # merge overrided options into output
+        for ln in doc.splitlines():
+            vals = ln.split('=', 1)
+            if len(vals) != 2:
+                print(ln)
+                continue
+
+            k = vals[0].strip()
+            v = vals[1].strip()
+            if k and k[0] == '#':
+                print(ln)
+                k = k[1:]
+                if k in self.cf_override:
+                    print('%s = %s' % (k, self.cf_override[k]))
+            elif k in self.cf_override:
+                if v:
+                    print('#' + ln)
+                print('%s = %s' % (k, self.cf_override[k]))
+            else:
+                print(ln)
 
-        print(skytools.dedent(doc))
         print('')
 
     def load_config(self):