python: bulk replace dict.iteritems to items for py3
[kai/samba-autobuild/.git] / python / samba / netcmd / __init__.py
index ad8143de856f074bc45fc50aefa4b7e53fba99a6..77976780150b26655678fb67cc28209563846490 100644 (file)
@@ -130,7 +130,7 @@ class Command(object):
             prog=prog,epilog=epilog)
         parser.add_options(self.takes_options)
         optiongroups = {}
-        for name, optiongroup in self.takes_optiongroups.iteritems():
+        for name, optiongroup in self.takes_optiongroups.items():
             optiongroups[name] = optiongroup(parser)
             parser.add_option_group(optiongroups[name])
         return parser, optiongroups
@@ -174,7 +174,7 @@ class Command(object):
 
         try:
             return self.run(*args, **kwargs)
-        except Exception, e:
+        except Exception as e:
             self.show_command_error(e)
             return -1
 
@@ -202,6 +202,19 @@ class SuperCommand(Command):
             return self.subcommands[subcommand]._run(
                 "%s %s" % (myname, subcommand), *args)
 
+        if subcommand == 'help':
+            # pass the request down
+            if len(args) > 0:
+                sub = self.subcommands.get(args[0])
+                if isinstance(sub, SuperCommand):
+                    return sub._run("%s %s" % (myname, args[0]), 'help',
+                                    *args[1:])
+                elif sub is not None:
+                    return sub._run("%s %s" % (myname, args[0]), '--help',
+                                    *args[1:])
+
+            subcommand = '--help'
+
         epilog = "\nAvailable subcommands:\n"
         subcmds = self.subcommands.keys()
         subcmds.sort()
@@ -230,3 +243,6 @@ class CommandError(Exception):
         self.message = message
         self.inner_exception = inner_exception
         self.exception_info = sys.exc_info()
+
+    def __repr__(self):
+        return "CommandError(%s)" % self.message