jenkins-bot has submitted this change and it was merged. Change subject: pep8-ify handleArgs to be handle_args ......................................................................
pep8-ify handleArgs to be handle_args Rename the method, with args passed as a list instead of as *args, and add do_help parameter as an easy way for the caller to handle -help and also prevent sys.exit() being invoked. Change-Id: I6eb20ca4b6ba8886f2d1fb31afcb2b2f86da40df --- M pywikibot/__init__.py M pywikibot/bot.py 2 files changed, 27 insertions(+), 10 deletions(-) Approvals: John Vandenberg: Looks good to me, but someone else must approve XZise: Looks good to me, approved jenkins-bot: Verified diff --git a/pywikibot/__init__.py b/pywikibot/__init__.py index 0444a33..ad0c475 100644 --- a/pywikibot/__init__.py +++ b/pywikibot/__init__.py @@ -29,8 +29,10 @@ from pywikibot import config2 as config from pywikibot.bot import ( output, warning, error, critical, debug, stdout, exception, - input, input_choice, inputChoice, handleArgs, showHelp, ui, log, + input, input_choice, inputChoice, handle_args, showHelp, ui, log, calledModuleName, Bot, WikidataBot, QuitKeyboardInterrupt, + # the following are flagged as deprecated on usage + handleArgs, ) from pywikibot.exceptions import ( Error, InvalidTitle, BadTitle, NoPage, SectionError, @@ -66,8 +68,8 @@ 'ItemPage', 'PropertyPage', 'Claim', 'TimeStripper', 'html2unicode', 'url2unicode', 'unicode2html', 'stdout', 'output', 'warning', 'error', 'critical', 'debug', - 'exception', 'input_choice', - 'input', 'inputChoice', 'handleArgs', 'showHelp', 'ui', 'log', + 'exception', 'input_choice', 'input', 'inputChoice', + 'handle_args', 'handleArgs', 'showHelp', 'ui', 'log', 'calledModuleName', 'Bot', 'WikidataBot', 'Error', 'InvalidTitle', 'BadTitle', 'NoPage', 'SectionError', 'SiteDefinitionError', 'NoSuchSite', 'UnknownSite', 'UnknownFamily', diff --git a/pywikibot/bot.py b/pywikibot/bot.py index 3321c76..ed90608 100644 --- a/pywikibot/bot.py +++ b/pywikibot/bot.py @@ -585,16 +585,25 @@ return os.path.basename(called) -def handleArgs(*args): - """Handle standard command line arguments, return the rest as a list. +def handle_args(args=None, do_help=True): + """ + Handle standard command line arguments, and return the rest as a list. Takes the command line arguments as Unicode strings, processes all - global parameters such as -lang or -log. Returns a list of all arguments - that are not global. This makes sure that global arguments are applied - first, regardless of the order in which the arguments were given. + global parameters such as -lang or -log, initialises the logging layer, + which emits startup information into log at level 'verbose'. + + This makes sure that global arguments are applied first, + regardless of the order in which the arguments were given. args may be passed as an argument, thereby overriding sys.argv + @param args: Command line arguments + @type args: list of unicode + @param do_help: Handle parameter '-help' to show help and invoke sys.exit + @type do_help: bool + @return: list of arguments not recognised globally + @rtype: list of unicode """ # get commandline arguments if necessary if not args: @@ -609,9 +618,9 @@ moduleName = "terminal-interface" nonGlobalArgs = [] username = None - do_help = False + do_help = None if do_help else False for arg in args: - if arg == '-help': + if do_help is not False and arg == '-help': do_help = True elif arg.startswith('-family:'): config.family = arg[len("-family:"):] @@ -721,10 +730,16 @@ if do_help: showHelp() sys.exit(0) + pywikibot.debug(u"handleArgs() completed.", _logger) return nonGlobalArgs +def handleArgs(*args): + """DEPRECATED. Use handle_args().""" + return handle_args(args) + + def showHelp(module_name=None): """Show help for the Bot.""" if not module_name: -- To view, visit https://gerrit.wikimedia.org/r/165972 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: merged Gerrit-Change-Id: I6eb20ca4b6ba8886f2d1fb31afcb2b2f86da40df Gerrit-PatchSet: 2 Gerrit-Project: pywikibot/core Gerrit-Branch: master Gerrit-Owner: John Vandenberg <jay...@gmail.com> Gerrit-Reviewer: John Vandenberg <jay...@gmail.com> Gerrit-Reviewer: Ladsgroup <ladsgr...@gmail.com> Gerrit-Reviewer: Merlijn van Deen <valhall...@arctus.nl> Gerrit-Reviewer: XZise <commodorefabia...@gmx.de> Gerrit-Reviewer: jenkins-bot <> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits