jenkins-bot has submitted this change and it was merged.
Change subject: [IMPR] Simplify arg parsing in handle_args method ......................................................................
[IMPR] Simplify arg parsing in handle_args method
- avoid length checking logic per argument - simplify logic for default values - logic and variable names are uniform for all args
Change-Id: I30818d229b1462f084faa1dc42945f11083f5e7a --- M scripts/add_text.py 1 file changed, 19 insertions(+), 31 deletions(-)
Approvals: Xqt: Looks good to me, approved Dalba: Looks good to me, but someone else must approve jenkins-bot: Verified
diff --git a/scripts/add_text.py b/scripts/add_text.py index f6049f5..4aad637 100755 --- a/scripts/add_text.py +++ b/scripts/add_text.py @@ -64,7 +64,7 @@
# # (C) Filnik, 2007-2010 -# (C) Pywikibot team, 2007-2015 +# (C) Pywikibot team, 2007-2016 # # Distributed under the terms of the MIT license. # @@ -305,42 +305,30 @@
# Loading the arguments for arg in local_args: - if arg.startswith('-textfile'): - if len(arg) == 9: - textfile = pywikibot.input( - u'Which textfile do you want to add?') - else: - textfile = arg[10:] - elif arg.startswith('-text'): - if len(arg) == 5: - addText = pywikibot.input(u'What text do you want to add?') - else: - addText = arg[6:] - elif arg.startswith('-summary'): - if len(arg) == 8: - summary = pywikibot.input(u'What summary do you want to use?') - else: - summary = arg[9:] - elif arg.startswith('-excepturl'): - if len(arg) == 10: - regexSkipUrl = pywikibot.input(u'What text should I skip?') - else: - regexSkipUrl = arg[11:] - elif arg.startswith('-except'): - if len(arg) == 7: - regexSkip = pywikibot.input(u'What text should I skip?') - else: - regexSkip = arg[8:] - elif arg == '-up': + option, sep, value = arg.partition(':') + if option == '-textfile': + textfile = value or pywikibot.input( + 'Which textfile do you want to add?') + elif option == '-text': + addText = value or pywikibot.input('What text do you want to add?') + elif option == '-summary': + summary = value or pywikibot.input( + 'What summary do you want to use?') + elif option == '-excepturl': + regexSkipUrl = value or pywikibot.input('What text should I skip?') + elif option == '-except': + regexSkip = value or pywikibot.input('What text should I skip?') + elif option == '-up': up = True - elif arg == '-noreorder': + elif option == '-noreorder': reorderEnabled = False - elif arg == '-always': + elif option == '-always': always = True - elif arg == '-talk' or arg == '-talkpage': + elif option in ('-talk', '-talkpage'): talkPage = True else: genFactory.handleArg(arg) + if textfile and not addText: with codecs.open(textfile, 'r', config.textfile_encoding) as f: addText = f.read()
pywikibot-commits@lists.wikimedia.org