dbcheck: change argument to specify a partial --yes
authorGarming Sam <garming@catalyst.net.nz>
Mon, 11 Jul 2016 03:14:47 +0000 (15:14 +1200)
committerGarming Sam <garming@samba.org>
Fri, 15 Jul 2016 08:01:30 +0000 (10:01 +0200)
Signed-off-by: Garming Sam <garming@catalyst.net.nz>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
python/samba/dbchecker.py
python/samba/netcmd/dbcheck.py

index ded4dc0a96c4b21715d1b630e93ecbaec4443520..f0c2217f68338a964618ebdb2b425fea566958e3 100644 (file)
@@ -280,14 +280,14 @@ systemFlags: -1946157056%s""" % (dn, guid_suffix),
         '''confirm a change with support for "all" '''
         if not self.fix:
             return False
-        if self.quiet:
-            return self.yes
         if getattr(self, all_attr) == 'NONE':
             return False
         if getattr(self, all_attr) == 'ALL':
             forced = True
         else:
             forced = self.yes
+        if self.quiet:
+            return forced
         c = common.confirm(msg, forced=forced, allow_all=True)
         if c == 'ALL':
             setattr(self, all_attr, 'ALL')
index 4cc0631bf768ca834110034ad99bf8074b41728a..2217366cc8db3106e3e5843206abce337e0396b9 100644 (file)
@@ -38,6 +38,21 @@ class cmd_dbcheck(Command):
         "credopts": options.CredentialsOptionsDouble,
     }
 
+    def process_yes(option, opt, value, parser):
+        assert value is None
+        done = 0
+        rargs = parser.rargs
+        if rargs:
+            arg = rargs[0]
+            if ((arg[:2] == "--" and len(arg) > 2) or
+                (arg[:1] == "-" and len(arg) > 1 and arg[1] != "-")):
+                setattr(parser.values, "yes", True)
+            else:
+                setattr(parser.values, "yes_rules", arg.split())
+                del rargs[0]
+        else:
+            setattr(parser.values, "yes", True)
+
     takes_args = ["DN?"]
 
     takes_options = [
@@ -45,7 +60,7 @@ class cmd_dbcheck(Command):
             help="Pass search scope that builds DN list. Options: SUB, ONE, BASE"),
         Option("--fix", dest="fix", default=False, action='store_true',
                help='Fix any errors found'),
-        Option("--yes", dest="yes", default=False, action='store_true',
+        Option("--yes", action='callback', callback=process_yes,
                help="don't confirm changes, just do them all as a single transaction"),
         Option("--cross-ncs", dest="cross_ncs", default=False, action='store_true',
                help="cross naming context boundaries"),
@@ -65,7 +80,7 @@ class cmd_dbcheck(Command):
             cross_ncs=False, quiet=False,
             scope="SUB", credopts=None, sambaopts=None, versionopts=None,
             attrs=None, reindex=False, force_modules=False,
-            reset_well_known_acls=False):
+            reset_well_known_acls=False, yes_rules=[]):
 
         lp = sambaopts.get_loadparm()
 
@@ -119,6 +134,12 @@ class cmd_dbcheck(Command):
                           fix=fix, yes=yes, quiet=quiet, in_transaction=started_transaction,
                           reset_well_known_acls=reset_well_known_acls)
 
+            for option in yes_rules:
+                if hasattr(chk, option):
+                    setattr(chk, option, 'ALL')
+                else:
+                    raise CommandError("Invalid fix rule %s" % option)
+
             if reindex:
                 self.outf.write("Re-indexing...\n")
                 error_count = 0