jenkins-bot has submitted this change and it was merged.
Change subject: Remove 'page title parts' mechanism in scripts ......................................................................
Remove 'page title parts' mechanism in scripts
- catall.py - disambredir.py - imagetransfer.py (reduces one part of bug 68659, and fixes usage help in docstring) - interwiki.py - makecat.py (fixes bug 69062) - solve_disambiguation.py
Should also resolve intermittent build error: https://travis-ci.org/wikimedia/pywikibot-core/jobs/31504947
Continues: Ic5983b64cbc0cd96c98c105574ccb1db6dbaf9a6
Change-Id: I1eebb39c0c033e53bd0d240307f755076cb848ec --- M scripts/catall.py M scripts/disambredir.py M scripts/imagetransfer.py M scripts/interwiki.py M scripts/makecat.py M scripts/solve_disambiguation.py M tests/script_tests.py 7 files changed, 79 insertions(+), 100 deletions(-)
Approvals: John Vandenberg: Looks good to me, but someone else must approve Ricordisamoa: Looks good to me, approved jenkins-bot: Verified
diff --git a/scripts/catall.py b/scripts/catall.py index e908bd0..1e61f11 100755 --- a/scripts/catall.py +++ b/scripts/catall.py @@ -1,8 +1,13 @@ # -*- coding: utf-8 -*- """ -Add or change categories on a number of pages. Usage: catall.py name - goes -through pages, starting at 'name'. Provides the categories on the page and asks -whether to change them. If no starting name is provided, the bot starts at 'A'. +Add or change categories on a number of pages. + +Usage: + catall.py [start] + +Provides the categories on the page and asks whether to change them. + +If no starting name is provided, the bot starts at 'A'.
Options: -onlynew : Only run on pages that do not yet have a category. @@ -71,18 +76,15 @@
def main(): docorrections = True - start = [] + start = 'A'
- for arg in pywikibot.handleArgs(): + local_args = pywikibot.handleArgs() + + for arg in local_args: if arg == '-onlynew': docorrections = False else: - start.append(arg) - - if not start: - start = 'A' - else: - start = ' '.join(start) + start = arg
mysite = pywikibot.Site()
diff --git a/scripts/disambredir.py b/scripts/disambredir.py index 8038993..058e90a 100644 --- a/scripts/disambredir.py +++ b/scripts/disambredir.py @@ -3,6 +3,12 @@ """ Goes through the disambiguation pages, checks their links, and asks for each link that goes to a redirect page whether it should be replaced. + +Usage: + python disambredir.py [start] + +If no starting name is provided, the bot starts at '!'. + """ # # (c) André Engels and others, 2006-2009 @@ -144,21 +150,24 @@
def main(): - start = [] - for arg in pywikibot.handleArgs(): - start.append(arg) - if start: - start = " ".join(start) - else: - start = "!" + local_args = pywikibot.handleArgs() + + generator = None + start = local_args[0] if local_args else '!' + mysite = pywikibot.Site() try: + mysite.disambcategory() + except pywikibot.Error as e: + pywikibot.output(e) + else: generator = pagegenerators.CategorizedPageGenerator( mysite.disambcategory(), start=start) - except pywikibot.NoPage: - pywikibot.output( - "The bot does not know the disambiguation category for your wiki.") - raise + + if not generator: + pywikibot.showHelp() + return + # only work on articles generator = pagegenerators.NamespaceFilterPageGenerator(generator, [0]) generator = pagegenerators.PreloadingGenerator(generator) diff --git a/scripts/imagetransfer.py b/scripts/imagetransfer.py index ee869f4..aff1a39 100644 --- a/scripts/imagetransfer.py +++ b/scripts/imagetransfer.py @@ -4,7 +4,7 @@
Syntax:
- python imagetransfer.py pagename [-interwiki] [-targetLang:xx] -targetFamily:yy] + python imagetransfer.py pagename [-interwiki] [-tolang:xx] [-tofamily:yy]
Arguments:
@@ -38,7 +38,6 @@ import upload from pywikibot import config from pywikibot import i18n -from pywikibot import pagegenerators
copy_message = { 'ar': u"هذه الصورة تم نقلها من %s. الوصف الأصلي كان:\r\n\r\n%s", @@ -298,16 +297,17 @@
def main(): - # if -file is not used, this temporary array is used to read the page title. - pageTitle = [] - page = None + pageTitle = None gen = None + interwiki = False keep_name = False targetLang = None targetFamily = None
- for arg in pywikibot.handleArgs(): + local_args = pywikibot.handleArgs() + + for arg in local_args: if arg == '-interwiki': interwiki = True elif arg.startswith('-keepname'): @@ -316,29 +316,15 @@ targetLang = arg[8:] elif arg.startswith('-tofamily:'): targetFamily = arg[10:] - elif arg.startswith('-file'): - if len(arg) == 5: - filename = pywikibot.input( - u'Please enter the list's filename: ') - else: - filename = arg[6:] - gen = pagegenerators.TextfilePageGenerator(filename) - else: - pageTitle.append(arg) + elif not pageTitle: + pageTitle = arg
- if not gen: - # if the page title is given as a command line argument, - # connect the title's parts with spaces - if pageTitle != []: - pageTitle = ' '.join(pageTitle) - page = pywikibot.Page(pywikibot.Site(), pageTitle) - # if no page title was given as an argument, and none was - # read from a file, query the user - if not page: - pageTitle = pywikibot.input(u'Which page to check:') - page = pywikibot.Page(pywikibot.Site(), pageTitle) - # generator which will yield only a single Page + if pageTitle: + page = pywikibot.Page(pywikibot.Site(), pageTitle) gen = iter([page]) + else: + pywikibot.showHelp() + return
if not targetLang and not targetFamily: targetSite = pywikibot.Site('commons', 'commons') diff --git a/scripts/interwiki.py b/scripts/interwiki.py index c071d9d..595a6d9 100755 --- a/scripts/interwiki.py +++ b/scripts/interwiki.py @@ -2422,7 +2422,7 @@
def main(): - singlePageTitle = [] + singlePageTitle = '' opthintsonly = False # Which namespaces should be processed? # default to [] which means all namespaces will be processed @@ -2491,7 +2491,8 @@ until = arg[7:] else: if not genFactory.handleArg(arg): - singlePageTitle.append(arg) + if not singlePageTitle: + singlePageTitle = arg
# Do not use additional summary with autonomous mode if globalvar.autonomous: @@ -2564,7 +2565,6 @@ # TODO: filter namespaces if -namespace parameter was used readWarnfile(warnfile, bot) else: - singlePageTitle = ' '.join(singlePageTitle) if not singlePageTitle and not opthintsonly: singlePageTitle = pywikibot.input(u'Which page to check:') if singlePageTitle: diff --git a/scripts/makecat.py b/scripts/makecat.py index fe4d372..d09a5bf 100644 --- a/scripts/makecat.py +++ b/scripts/makecat.py @@ -1,9 +1,10 @@ # -*- coding: UTF-8 -*- """ -This bot takes as its argument (or, if no argument is given, asks for it), the -name of a new or existing category. It will then try to find new articles for -this category (pages linked to and from pages already in the category), asking -the user which pages to include and which not. +This bot takes as its argument the name of a new or existing category. + +It will then try to find new articles for this category +(pages linked to and from pages already in the category), +asking the user which pages to include and which not.
Arguments: -nodates automatically skip all pages that are years or dates (years @@ -39,6 +40,7 @@ __version__ = '$Id$' #
+import sys import codecs import pywikibot from pywikibot import date, pagegenerators, i18n @@ -192,7 +194,7 @@ checkbroken = True removeparent = True main = True - workingcatname = [] + workingcatname = '' tocheck = [] for arg in pywikibot.handleArgs(): if arg.startswith('-nodate'): @@ -206,13 +208,13 @@ removeparent = False elif arg.startswith('-all'): main = False - else: - workingcatname.append(arg) + elif not workingcatname: + workingcatname = arg
- if len(workingcatname) == 0: - workingcatname = pywikibot.input("Which page to start with? ") - else: - workingcatname = ' '.join(workingcatname) + if not workingcatname: + pywikibot.showHelp() + sys.exit(0) + mysite = pywikibot.Site() pywikibot.setAction(i18n.twtranslate(mysite, 'makecat-create', {'cat': workingcatname})) workingcat = pywikibot.Category(mysite, diff --git a/scripts/solve_disambiguation.py b/scripts/solve_disambiguation.py index 7476cb8..09ef8f7 100644 --- a/scripts/solve_disambiguation.py +++ b/scripts/solve_disambiguation.py @@ -3,12 +3,11 @@ """ Script to help a human solve disambiguations by presenting a set of options.
-Specify the disambiguation page on the command line, or enter it at the -prompt after starting the program. (If the disambiguation page title starts -with a '-', you cannot name it on the command line, but you can enter it at -the prompt.) The program will pick up the page, and look for all -alternative links, and show them with a number adjacent to them. It will -then automatically loop over all pages referring to the disambiguation page, +Specify the disambiguation page on the command line. + +The program will pick up the page, and look for all alternative links, +and show them with a number adjacent to them. It will then automatically +loop over all pages referring to the disambiguation page, and show 30 characters of context on each side of the reference to help you make the decision between the alternatives. It will ask you to type the number of the appropriate replacement, and perform the change. @@ -1017,19 +1016,17 @@ alternatives = [] getAlternatives = True dnSkip = False - # if the -file argument is used, page titles are dumped in this array. - # otherwise it will only contain one page. generator = None - # This temporary array is used to read the page title if one single - # page to work on is specified by the arguments. - pageTitle = [] + pageTitle = None primary = False main_only = False
# For sorting the linked pages, case can be ignored minimum = 0
- for arg in pywikibot.handleArgs(*args): + local_args = pywikibot.handleArgs(*args) + + for arg in local_args: if arg.startswith('-primary:'): primary = True getAlternatives = False @@ -1081,29 +1078,19 @@ except pywikibot.NoPage: pywikibot.output("Disambiguation category for your wiki is not known.") raise - elif arg.startswith("-"): - pywikibot.output("Unrecognized command line argument: %s" % arg) - # show help text and exit - pywikibot.showHelp() - else: - pageTitle.append(arg) + elif not pageTitle: + pageTitle = arg + site = pywikibot.Site() site.login()
- # if the disambiguation page is given as a command line argument, - # connect the title's parts with spaces - if pageTitle != []: - pageTitle = ' '.join(pageTitle) + if pageTitle: page = pywikibot.Page(pywikibot.Link(pageTitle, site)) generator = iter([page])
- # if no disambiguation page was given as an argument, and none was - # read from a file, query the user if not generator: - pageTitle = pywikibot.input( - u'On which disambiguation page do you want to work?') - page = pywikibot.Page(pywikibot.Link(pageTitle, site)) - generator = iter([page]) + pywikibot.showHelp() + return
bot = DisambiguationRobot(always, alternatives, getAlternatives, dnSkip, generator, primary, main_only, diff --git a/tests/script_tests.py b/tests/script_tests.py index 75154cc..abfdcc4 100644 --- a/tests/script_tests.py +++ b/tests/script_tests.py @@ -63,11 +63,8 @@
script_input = { 'catall': 'q\n', # q for quit - 'disambredir': '\n', # prompts for user to choose action to take 'editarticle': 'Test page\n', - 'imagetransfer': 'Test page\n', 'interwiki': 'Test page\n', - 'makecat': 'Test page\n\n', # 'misspelling': 'q\n', # pressing 'q' doesnt work. bug 68663 'replace': 'foo\nbar\n\n\n', # match, replacement, # Enter to begin, Enter for default summary. @@ -84,15 +81,14 @@ 'category_redirect', 'cfd', 'clean_sandbox', + 'disambredir', 'lonelypages', - 'makecat', 'misspelling', 'revertbot', 'noreferences', 'nowcommons', 'script_wui', 'shell', - 'solve_disambiguation', 'unusedfiles', 'upload', 'watchlist', @@ -127,7 +123,6 @@ # The following auto-run and typically cant be validated, # however these strings are very likely to exist within # the timeout of 5 seconds. - 'makecat': '(Default is [[', 'revertbot': 'Fetching new batch of contributions', 'upload': 'ERROR: Upload error', } @@ -217,15 +212,13 @@ no_args_expected_results) if script_name in ['checkimages', # bug 68613 'data_ingestion', # bug 68611 - 'disambredir', # quittable auto-run with - # highly variable output. 'flickrripper', # bug 68606 (and deps) 'imagerecat', # bug 68658 - 'imagetransfer', # bug 68659 'pagefromfile', # bug 68660 'upload', # raises custom ValueError ] or ( ((config.family != 'wikipedia' or config.mylang != 'en') and script_name == 'cfd') or + (config.family == 'wikipedia' and script_name == 'disambredir') or (config.family == 'wikipedia' and config.mylang != 'en' and script_name == 'misspelling')): dct[test_name] = unittest.expectedFailure(dct[test_name]) dct[test_name].__doc__ = \
pywikibot-commits@lists.wikimedia.org