[Pywikipedia-l] SVN: [6339] branches/rewrite/pywikibot/bot.py

russblau at svn.wikimedia.org russblau at svn.wikimedia.org
Mon Feb 9 14:41:27 UTC 2009


Revision: 6339
Author:   russblau
Date:     2009-02-09 14:41:27 +0000 (Mon, 09 Feb 2009)

Log Message:
-----------
bugfix for "-help" command line arg

Modified Paths:
--------------
    branches/rewrite/pywikibot/bot.py

Modified: branches/rewrite/pywikibot/bot.py
===================================================================
--- branches/rewrite/pywikibot/bot.py	2009-02-08 13:58:13 UTC (rev 6338)
+++ branches/rewrite/pywikibot/bot.py	2009-02-09 14:41:27 UTC (rev 6339)
@@ -239,11 +239,12 @@
         moduleName = "terminal-interface"
     nonGlobalArgs = []
     username = None
+    do_help = False
     for arg in args:
         arg = _decodeArg(arg)
         if arg == '-help':
-            showHelp()
-            sys.exit(0)
+            do_help = True
+            break
         elif arg.startswith('-family:'):
             config.family = arg[len("-family:") : ]
         elif arg.startswith('-lang:'):
@@ -367,6 +368,9 @@
         pywikibot.output(u'Pywikipediabot r%s' % m.group(1))
         pywikibot.output(u'Python %s' % sys.version)
 
+    if do_help:
+        showHelp()
+        sys.exit(0)
     pywikibot.output("handleArgs() completed.", level=DEBUG)
     return nonGlobalArgs
 
@@ -374,6 +378,12 @@
 def showHelp(name=""):
     # argument, if given, is ignored
     modname = calledModuleName()
+    if not modname:
+        try:
+            modname = sys.modules['__main__'].main.__module__
+        except NameError:
+            modname = "no_module"
+
     globalHelp =u'''\
 Global arguments available for all bots:
 
@@ -418,7 +428,7 @@
             for key, value in module.docuReplacements.iteritems():
                 helpText = helpText.replace(key, value.strip('\n\r'))
         pywikibot.output(helpText)
-    except:
+    except Exception:
         if modname:
             pywikibot.output(u'Sorry, no help available for %s' % modname)
         logging.exception('showHelp:')





More information about the Pywikipedia-l mailing list