jenkins-bot has submitted this change and it was merged.
Change subject: Bug 63800: Call handleArgs before GeneratorFactory
......................................................................
Bug 63800: Call handleArgs before GeneratorFactory
Bug 54540 introduced a regression in pagegenerator.py
by instantiating a Site before global argument handling,
causing arguments -family and -lang to be ignored by
the pagegenerators.
Scripts already previously fixed:
protect.py: 9af6e13adb76f7c0ac846f2148839289e2e4808f
delete.py: 0daf5b10b43bd7d380fb4b06b837cb42bdb63bb9
Updated scripts that use pagegenerators.GeneratorFactory
to call pywikibot.handleArgs before instantiating the
factory.
Removed passing around *args if they were unused.
Change-Id: I134529f3a914225d3473b95ca771cf7e7be01a36
---
M scripts/add_text.py
M scripts/basic.py
M scripts/blockpageschecker.py
M scripts/category.py
M scripts/claimit.py
M scripts/commonscat.py
M scripts/coordinate_import.py
M scripts/cosmetic_changes.py
M scripts/create_categories.py
M scripts/data_ingestion.py
M scripts/delete.py
M scripts/fixing_redirects.py
M scripts/harvest_template.py
M scripts/illustrate_wikidata.py
M scripts/imagerecat.py
M scripts/imageuncat.py
M scripts/interwiki.py
M scripts/isbn.py
M scripts/listpages.py
M scripts/lonelypages.py
M scripts/movepages.py
M scripts/newitem.py
M scripts/noreferences.py
M scripts/protect.py
M scripts/reflinks.py
M scripts/replace.py
M scripts/template.py
M scripts/touch.py
M scripts/weblinkchecker.py
29 files changed, 143 insertions(+), 86 deletions(-)
Approvals:
Xqt: Looks good to me, approved
jenkins-bot: Verified
diff --git a/scripts/add_text.py b/scripts/add_text.py
index 90c0e22..3a2f69b 100644
--- a/scripts/add_text.py
+++ b/scripts/add_text.py
@@ -291,12 +291,16 @@
talkPage = False
reorderEnabled = True
namespaces = []
- # Load a lot of default generators
- genFactory = pagegenerators.GeneratorFactory()
+
# Put the text above or below the text?
up = False
+
+ # Process global args and prepare generator args parser
+ local_args = pywikibot.handleArgs()
+ genFactory = pagegenerators.GeneratorFactory()
+
# Loading the arguments
- for arg in pywikibot.handleArgs():
+ for arg in local_args:
if arg.startswith('-textfile'):
if len(arg) == 9:
textfile = pywikibot.input(
diff --git a/scripts/basic.py b/scripts/basic.py
index 380d19e..e51c8c2 100755
--- a/scripts/basic.py
+++ b/scripts/basic.py
@@ -134,6 +134,11 @@
def main():
global site
+
+ # Process global arguments to determine desired site
+ local_args = pywikibot.handleArgs()
+ site = pywikibot.Site()
+
# This factory is responsible for processing command line arguments
# that are also used by other scripts and that determine on which pages
# to work on.
@@ -148,7 +153,7 @@
dry = False
# Parse command line arguments
- for arg in pywikibot.handleArgs():
+ for arg in local_args:
if arg.startswith("-dry"):
dry = True
else:
@@ -156,7 +161,7 @@
# -start:XYZ or -ref:Asdf was given.
if not genFactory.handleArg(arg):
pageTitleParts.append(arg)
- site = pywikibot.Site()
+
site.login()
if pageTitleParts != []:
# We will only work on a single page.
diff --git a/scripts/blockpageschecker.py b/scripts/blockpageschecker.py
index c119b4c..5962d03 100755
--- a/scripts/blockpageschecker.py
+++ b/scripts/blockpageschecker.py
@@ -223,11 +223,16 @@
protectedpages = False
protectType = 'edit'
namespace = 0
- genFactory = pagegenerators.GeneratorFactory()
+
# To prevent Infinite loops
errorCount = 0
- # Loading the default options.
- for arg in pywikibot.handleArgs():
+
+ # Process global args and prepare generator args parser
+ local_args = pywikibot.handleArgs()
+ genFactory = pagegenerators.GeneratorFactory()
+
+ # Process local args
+ for arg in local_args:
if arg == '-always':
always = True
elif arg == '-move':
diff --git a/scripts/category.py b/scripts/category.py
index 3f31054..6722aa8 100755
--- a/scripts/category.py
+++ b/scripts/category.py
@@ -947,10 +947,10 @@
rebuild = False
depth = 5
- # This factory is responsible for processing command line arguments
- # that are also used by other scripts and that determine on which pages
- # to work on.
+ # Process global args and prepare generator args parser
+ local_args = pywikibot.handleArgs(*args)
genFactory = pagegenerators.GeneratorFactory()
+
# The generator gives the pages that should be worked upon.
gen = None
@@ -962,7 +962,7 @@
create_pages = False
follow_redirects = False
deleteEmptySourceCat = True
- for arg in pywikibot.handleArgs(*args):
+ for arg in local_args:
if arg == 'add':
action = 'add'
elif arg == 'remove':
diff --git a/scripts/claimit.py b/scripts/claimit.py
index a8a0c09..bf01b55 100755
--- a/scripts/claimit.py
+++ b/scripts/claimit.py
@@ -148,9 +148,13 @@
def main():
exists_arg = ''
- gen = pagegenerators.GeneratorFactory()
commandline_claims = list()
- for arg in pywikibot.handleArgs():
+
+ # Process global args and prepare generator args parser
+ local_args = pywikibot.handleArgs()
+ gen = pagegenerators.GeneratorFactory()
+
+ for arg in local_args:
# Handle args specifying how to handle duplicate claims
if arg.startswith('-exists:'):
exists_arg = arg.split(':')[1].strip('"')
diff --git a/scripts/commonscat.py b/scripts/commonscat.py
index 68e870c..27e98a2 100755
--- a/scripts/commonscat.py
+++ b/scripts/commonscat.py
@@ -560,10 +560,12 @@
always = False
ns = []
ns.append(14)
- # Load a lot of default generators
+
+ # Process global args and prepare generator args parser
+ local_args = pywikibot.handleArgs()
genFactory = pagegenerators.GeneratorFactory()
- for arg in pywikibot.handleArgs():
+ for arg in local_args:
if arg.startswith('-summary'):
if len(arg) == 8:
summary = pywikibot.input(u'What summary do you want to use?')
diff --git a/scripts/coordinate_import.py b/scripts/coordinate_import.py
index 75343d5..e1b76bf 100644
--- a/scripts/coordinate_import.py
+++ b/scripts/coordinate_import.py
@@ -73,9 +73,11 @@
def main():
+ # Process global args and prepare generator args parser
+ local_args = pywikibot.handleArgs()
gen = pagegenerators.GeneratorFactory()
- for arg in pywikibot.handleArgs():
+ for arg in local_args:
if gen.handleArg(arg):
continue
diff --git a/scripts/cosmetic_changes.py b/scripts/cosmetic_changes.py
index 2b67cfc..080cf67 100755
--- a/scripts/cosmetic_changes.py
+++ b/scripts/cosmetic_changes.py
@@ -908,12 +908,12 @@
answer = 'y'
always = False
async = False
- # This factory is responsible for processing command line arguments
- # that are also used by other scripts and that determine on which pages
- # to work on.
+
+ # Process global args and prepare generator args parser
+ local_args = pywikibot.handleArgs()
genFactory = pagegenerators.GeneratorFactory()
- for arg in pywikibot.handleArgs():
+ for arg in local_args:
if arg.startswith('-summary:'):
editSummary = arg[len('-summary:'):]
elif arg == '-always':
diff --git a/scripts/create_categories.py b/scripts/create_categories.py
index dcd78d4..1044b28 100755
--- a/scripts/create_categories.py
+++ b/scripts/create_categories.py
@@ -65,7 +65,7 @@
pywikibot.output(u'%s already exists, skipping' % newpage.title())
-def main(args):
+def main():
'''
Main loop. Get a generator and options.
'''
@@ -74,9 +74,11 @@
basename = u''
always = False
+ # Process global args and prepare generator args parser
+ local_args = pywikibot.handleArgs()
genFactory = pagegenerators.GeneratorFactory()
- for arg in pywikibot.handleArgs():
+ for arg in local_args:
if arg == '-always':
always = True
elif arg.startswith('-parent:'):
@@ -96,4 +98,4 @@
pywikibot.output(u'All done')
if __name__ == "__main__":
- main(sys.argv[1:])
+ main()
diff --git a/scripts/data_ingestion.py b/scripts/data_ingestion.py
index b30361d..19d331b 100755
--- a/scripts/data_ingestion.py
+++ b/scripts/data_ingestion.py
@@ -284,12 +284,14 @@
else:
pywikibot.output(u'%s is not a supported source format')
-def main(args):
+def main():
generator = None;
+ # Process global args and prepare generator args parser
+ local_args = pywikibot.handleArgs()
genFactory = pagegenerators.GeneratorFactory()
- for arg in pywikibot.handleArgs():
+ for arg in local_args:
genFactory.handleArg(arg)
generator = genFactory.getCombinedGenerator()
@@ -302,7 +304,7 @@
if __name__ == "__main__":
try:
- main(sys.argv[1:])
+ main()
finally:
print "All done!"
'''
diff --git a/scripts/delete.py b/scripts/delete.py
index f380b43..e287ec9 100644
--- a/scripts/delete.py
+++ b/scripts/delete.py
@@ -80,10 +80,10 @@
generator = None
# read command line parameters
- localargs = pywikibot.handleArgs()
+ local_args = pywikibot.handleArgs()
mysite = pywikibot.Site()
- for arg in localargs:
+ for arg in local_args:
if arg == '-always':
always = True
elif arg.startswith('-summary'):
@@ -94,7 +94,7 @@
elif arg.startswith('-images'):
pywikibot.output('\n\03{lightred}-image option is deprecated. '
'Please use -imageused instead.\03{default}\n')
- localargs.append('-imageused' + arg[7:])
+ local_args.append('-imageused' + arg[7:])
elif arg.startswith('-undelete'):
undelete = True
else:
diff --git a/scripts/fixing_redirects.py b/scripts/fixing_redirects.py
index 54ef42a..e257da8 100644
--- a/scripts/fixing_redirects.py
+++ b/scripts/fixing_redirects.py
@@ -193,12 +193,11 @@
featured = False
gen = None
- # This factory is responsible for processing command line arguments
- # that are also used by other scripts and that determine on which pages
- # to work on.
+ # Process global args and prepare generator args parser
+ local_args = pywikibot.handleArgs()
genFactory = pagegenerators.GeneratorFactory()
- for arg in pywikibot.handleArgs():
+ for arg in local_args:
if arg == '-featured':
featured = True
else:
diff --git a/scripts/harvest_template.py b/scripts/harvest_template.py
index baab240..0d4979f 100755
--- a/scripts/harvest_template.py
+++ b/scripts/harvest_template.py
@@ -145,10 +145,14 @@
def main():
- gen = pg.GeneratorFactory()
commandline_arguments = list()
templateTitle = u''
- for arg in pywikibot.handleArgs():
+
+ # Process global args and prepare generator args parser
+ local_args = pywikibot.handleArgs()
+ gen = pg.GeneratorFactory()
+
+ for arg in local_args:
if arg.startswith('-template'):
if len(arg) == 9:
templateTitle = pywikibot.input(
diff --git a/scripts/illustrate_wikidata.py b/scripts/illustrate_wikidata.py
index cc80f8a..7fde432 100644
--- a/scripts/illustrate_wikidata.py
+++ b/scripts/illustrate_wikidata.py
@@ -84,10 +84,13 @@
def main():
+ # Process global args and prepare generator args parser
+ local_args = pywikibot.handleArgs()
gen = pg.GeneratorFactory()
+
wdproperty = u'P18'
- for arg in pywikibot.handleArgs():
+ for arg in local_args:
if arg.startswith('-property'):
if len(arg) == 9:
wdproperty = pywikibot.input(
diff --git a/scripts/imagerecat.py b/scripts/imagerecat.py
index 114c88d..df18464 100644
--- a/scripts/imagerecat.py
+++ b/scripts/imagerecat.py
@@ -441,20 +441,22 @@
return result
-def main(args):
+def main():
"""
Main loop. Get a generator and options. Work on all images in the generator.
"""
generator = None
onlyFilter = False
onlyUncat = False
+
+ # Process global args and prepare generator args parser
+ local_args = pywikibot.handleArgs()
genFactory = pagegenerators.GeneratorFactory()
global search_wikis
global hint_wiki
- site = pywikibot.Site(u'commons', u'commons')
- for arg in pywikibot.handleArgs():
+ for arg in local_args:
if arg == '-onlyfilter':
onlyFilter = True
elif arg == '-onlyuncat':
@@ -468,12 +470,14 @@
generator = genFactory.getCombinedGenerator()
if not generator:
+ site = pywikibot.Site(u'commons', u'commons')
generator = pagegenerators.CategorizedPageGenerator(
pywikibot.Category(site, u'Category:Media needing categories'),
recurse=True)
+
initLists()
categorizeImages(generator, onlyFilter, onlyUncat)
pywikibot.output(u'All done')
if __name__ == "__main__":
- main(sys.argv[1:])
+ main()
diff --git a/scripts/imageuncat.py b/scripts/imageuncat.py
index d1af10a..fba8163 100755
--- a/scripts/imageuncat.py
+++ b/scripts/imageuncat.py
@@ -1319,12 +1319,16 @@
Grab a bunch of images and tag them if they are not categorized.
'''
generator = None
- genFactory = pagegenerators.GeneratorFactory()
+
+ local_args = pywikibot.handleArgs(*args)
# use the default imagerepository normally commons
site = pywikibot.Site().image_repository()
+
+ genFactory = pagegenerators.GeneratorFactory(site)
+
site.login()
- for arg in pywikibot.handleArgs(*args):
+ for arg in local_args:
if arg.startswith('-yesterday'):
generator = uploadedYesterday(site)
elif arg.startswith('-recentchanges'):
diff --git a/scripts/interwiki.py b/scripts/interwiki.py
index 3edaa55..03abb5f 100755
--- a/scripts/interwiki.py
+++ b/scripts/interwiki.py
@@ -2438,12 +2438,12 @@
dumpFileName = ''
append = True
newPages = None
- # This factory is responsible for processing command line arguments
- # that are also used by other scripts and that determine on which pages
- # to work on.
+
+ # Process global args and prepare generator args parser
+ local_args = pywikibot.handleArgs()
genFactory = pagegenerators.GeneratorFactory()
- for arg in pywikibot.handleArgs():
+ for arg in local_args:
if globalvar.readOptions(arg):
continue
elif arg.startswith('-warnfile:'):
diff --git a/scripts/isbn.py b/scripts/isbn.py
index ee3d136..36ba819 100755
--- a/scripts/isbn.py
+++ b/scripts/isbn.py
@@ -1478,16 +1478,16 @@
# Which namespaces should be processed?
# default to [] which means all namespaces will be processed
namespaces = []
- # This factory is responsible for processing command line arguments
- # that are also used by other scripts and that determine on which pages
- # to work on.
- genFactory = pagegenerators.GeneratorFactory()
# Never ask before changing a page
always = False
to13 = False
format = False
- for arg in pywikibot.handleArgs():
+ # Process global args and prepare generator args parser
+ local_args = pywikibot.handleArgs()
+ genFactory = pagegenerators.GeneratorFactory()
+
+ for arg in local_args:
if arg.startswith('-namespace:'):
try:
namespaces.append(int(arg[11:]))
diff --git a/scripts/listpages.py b/scripts/listpages.py
index 233160a..3557566 100644
--- a/scripts/listpages.py
+++ b/scripts/listpages.py
@@ -31,8 +31,11 @@
notitle = False
page_get = False
+ # Process global args and prepare generator args parser
+ local_args = pywikibot.handleArgs(*args)
genFactory = GeneratorFactory()
- for arg in pywikibot.handleArgs(*args):
+
+ for arg in local_args:
if arg == '-notitle':
notitle = True
elif arg == '-get':
diff --git a/scripts/lonelypages.py b/scripts/lonelypages.py
index 820aab0..e7088b3 100644
--- a/scripts/lonelypages.py
+++ b/scripts/lonelypages.py
@@ -79,13 +79,15 @@
enablePage = None # Check if someone set an enablePage or not
limit = 50000 # Hope that there aren't so many lonely pages in a project
generator = None # Check if bot should use default generator or not
- # Load all default generators!
- genFactory = pagegenerators.GeneratorFactory()
nwpages = False # Check variable for newpages
always = False # Check variable for always
disambigPage = None # If no disambigPage given, not use it.
+
# Arguments!
- for arg in pywikibot.handleArgs():
+ local_args = pywikibot.handleArgs()
+ genFactory = pagegenerators.GeneratorFactory()
+
+ for arg in local_args:
if arg.startswith('-enable'):
if len(arg) == 7:
enablePage = pywikibot.input(
diff --git a/scripts/movepages.py b/scripts/movepages.py
index afab0ca..f23f0bf 100644
--- a/scripts/movepages.py
+++ b/scripts/movepages.py
@@ -222,12 +222,11 @@
summary = None
fromToPairs = []
- # This factory is responsible for processing command line arguments
- # that are also used by other scripts and that determine on which pages
- # to work on.
+ # Process global args and prepare generator args parser
+ local_args = pywikibot.handleArgs()
genFactory = pagegenerators.GeneratorFactory()
- for arg in pywikibot.handleArgs():
+ for arg in local_args:
if arg.startswith('-pairs'):
if len(arg) == len('-pairs'):
filename = pywikibot.input(
diff --git a/scripts/newitem.py b/scripts/newitem.py
index a4c3dc3..f674d53 100644
--- a/scripts/newitem.py
+++ b/scripts/newitem.py
@@ -89,9 +89,11 @@
pageAge = 21
lastEdit = 7
+ # Process global args and prepare generator args parser
+ local_args = pywikibot.handleArgs()
gen = pagegenerators.GeneratorFactory()
- for arg in pywikibot.handleArgs():
+ for arg in local_args:
if arg.startswith('-pageage:'):
pageAge = int(arg[9:])
elif arg.startswith('-lastedit:'):
diff --git a/scripts/noreferences.py b/scripts/noreferences.py
index 43fb040..871ed13 100755
--- a/scripts/noreferences.py
+++ b/scripts/noreferences.py
@@ -686,12 +686,12 @@
always = False
# No verbose output
verbose = True
- # This factory is responsible for processing command line arguments
- # that are also used by other scripts and that determine on which pages
- # to work on.
+
+ # Process global args and prepare generator args parser
+ local_args = pywikibot.handleArgs()
genFactory = pagegenerators.GeneratorFactory()
- for arg in pywikibot.handleArgs():
+ for arg in local_args:
if arg.startswith('-xml'):
if len(arg) == 4:
xmlFilename = i18n.input('pywikibot-enter-xml-filename')
diff --git a/scripts/protect.py b/scripts/protect.py
index dcaed46..c9fc499 100644
--- a/scripts/protect.py
+++ b/scripts/protect.py
@@ -123,11 +123,11 @@
defaultProtection = 'sysop'
# read command line parameters
- localargs = pywikibot.handleArgs(*args)
+ local_args = pywikibot.handleArgs(*args)
genFactory = pagegenerators.GeneratorFactory()
mysite = pywikibot.Site()
- for arg in localargs:
+ for arg in local_args:
if arg == '-always':
always = True
elif arg.startswith('-summary'):
@@ -138,7 +138,7 @@
elif arg.startswith('-images'):
pywikibot.output('\n\03{lightred}-image option is deprecated. '
'Please use -imagelinks instead.\03{default}\n')
- localargs.append('-imagelinks' + arg[7:])
+ local_args.append('-imagelinks' + arg[7:])
elif arg.startswith('-unprotect'):
defaultProtection = 'none'
elif arg.startswith('-edit'):
diff --git a/scripts/reflinks.py b/scripts/reflinks.py
index cf88bc8..cbe96fa 100644
--- a/scripts/reflinks.py
+++ b/scripts/reflinks.py
@@ -780,15 +780,18 @@
def main():
- genFactory = pagegenerators.GeneratorFactory()
-
xmlFilename = None
always = False
ignorepdf = False
limit = None
namespaces = []
generator = None
- for arg in pywikibot.handleArgs():
+
+ # Process global args and prepare generator args parser
+ local_args = pywikibot.handleArgs()
+ genFactory = pagegenerators.GeneratorFactory()
+
+ for arg in local_args:
if arg.startswith('-namespace:'):
try:
namespaces.append(int(arg[11:]))
diff --git a/scripts/replace.py b/scripts/replace.py
index 20582b9..186c0ff 100755
--- a/scripts/replace.py
+++ b/scripts/replace.py
@@ -478,16 +478,16 @@
allowoverlap = False
# Do not recurse replacement
recursive = False
- # This factory is responsible for processing command line arguments
- # that are also used by other scripts and that determine on which pages
- # to work on.
- genFactory = pagegenerators.GeneratorFactory()
# Between a regex and another (using -fix) sleep some time (not to waste
# too much CPU
sleep = None
# Read commandline parameters.
- for arg in pywikibot.handleArgs(*args):
+
+ local_args = pywikibot.handleArgs(*args)
+ genFactory = pagegenerators.GeneratorFactory()
+
+ for arg in local_args:
if genFactory.handleArg(arg):
continue
if arg == '-regex':
diff --git a/scripts/template.py b/scripts/template.py
index eda65eb..707716a 100755
--- a/scripts/template.py
+++ b/scripts/template.py
@@ -298,14 +298,16 @@
editSummary = ''
addedCat = ''
acceptAll = False
- genFactory = pagegenerators.GeneratorFactory()
# If xmlfilename is None, references will be loaded from the live wiki.
xmlfilename = None
user = None
skip = False
timestamp = None
+
# read command line parameters
- for arg in pywikibot.handleArgs(*args):
+ local_args = pywikibot.handleArgs(*args)
+ genFactory = pagegenerators.GeneratorFactory()
+ for arg in local_args:
if arg == '-remove':
remove = True
elif arg == '-subst':
diff --git a/scripts/touch.py b/scripts/touch.py
index ca5e743..44bb153 100755
--- a/scripts/touch.py
+++ b/scripts/touch.py
@@ -72,13 +72,17 @@
def main(*args):
gen = None
- genFactory = pagegenerators.GeneratorFactory()
options = {}
# If the user chooses to work on a single page, this temporary array is
# used to read the words from the page title. The words will later be
# joined with spaces to retrieve the full title.
pageTitle = []
- for arg in pywikibot.handleArgs(*args):
+
+ # Process global args and prepare generator args parser
+ local_args = pywikibot.handleArgs(*args)
+ genFactory = pagegenerators.GeneratorFactory()
+
+ for arg in local_args:
if genFactory.handleArg(arg):
continue
if arg.startswith("-"):
diff --git a/scripts/weblinkchecker.py b/scripts/weblinkchecker.py
index a7bb096..c5a2086 100644
--- a/scripts/weblinkchecker.py
+++ b/scripts/weblinkchecker.py
@@ -797,6 +797,8 @@
def main():
+ global day
+
gen = None
singlePageTitle = []
xmlFilename = None
@@ -804,13 +806,13 @@
# default to [] which means all namespaces will be processed
namespaces = []
HTTPignore = []
- # This factory is responsible for processing command line arguments
- # that are also used by other scripts and that determine on which pages
- # to work on.
- genFactory = pagegenerators.GeneratorFactory()
- global day
day = 7
- for arg in pywikibot.handleArgs():
+
+ # Process global args and prepare generator args parser
+ local_args = pywikibot.handleArgs()
+ genFactory = pagegenerators.GeneratorFactory()
+
+ for arg in local_args:
if arg == '-talk':
config.report_dead_links_on_talk = True
elif arg == '-notalk':
--
To view, visit
https://gerrit.wikimedia.org/r/135287
To unsubscribe, visit
https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I134529f3a914225d3473b95ca771cf7e7be01a36
Gerrit-PatchSet: 3
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Owner: John Vandenberg <jayvdb(a)gmail.com>
Gerrit-Reviewer: John Vandenberg <jayvdb(a)gmail.com>
Gerrit-Reviewer: Ladsgroup <ladsgroup(a)gmail.com>
Gerrit-Reviewer: Merlijn van Deen <valhallasw(a)arctus.nl>
Gerrit-Reviewer: Xqt <info(a)gno.de>
Gerrit-Reviewer: jenkins-bot <>