jenkins-bot has submitted this change and it was merged.
Change subject: (bugfix) imagetransfer.py: remove broken debug
......................................................................
(bugfix) imagetransfer.py: remove broken debug
In the conversion from lib_images.py to imagetransfer.py,
the following line was dropped:
imageTitle = sourceImagePage.title().encode('utf-8')
https://www.mediawiki.org/wiki/Special:Code/pywikipedia/2066
sha 9f6e1eb090ee6ee355cf65984cd3adcf851c8470
As a result, the logging of the imageTitle has referenced an
undefined variable since 2005. This debug log entry is disabled
in the code. There are also no bugs reported, so it is unlikely to
be needed.
(Porting compat Change-Id Ie044fba2e32e1f34e9d96eb4baa45bd52fc04e8b to
core)
Change-Id: I9ee8c5aa074eda4b84b81f88d3676949ed194476
---
M scripts/imagetransfer.py
1 file changed, 2 insertions(+), 5 deletions(-)
Approvals:
Xqt: Looks good to me, approved
jenkins-bot: Verified
diff --git a/scripts/imagetransfer.py b/scripts/imagetransfer.py
index 1aaa843..ec8d992 100644
--- a/scripts/imagetransfer.py
+++ b/scripts/imagetransfer.py
@@ -160,7 +160,7 @@
self.targetSite = targetSite
self.keep_name = keep_name
- def transferImage(self, sourceImagePage, debug=False):
+ def transferImage(self, sourceImagePage):
"""Gets a wikilink to an image, downloads it and its description,
and uploads it to another wikipedia.
Returns the filename which was used to upload the image
@@ -168,9 +168,6 @@
"""
sourceSite = sourceImagePage.site
- if debug:
- print "-" * 50
- print "Found image: %s" % imageTitle
url = sourceImagePage.fileUrl().encode('utf-8')
pywikibot.output(u"URL should be: %s" % url)
# localize the text that should be printed on the image description page
@@ -293,7 +290,7 @@
pywikibot.output(
u'The image is already on Wikimedia Commons.')
else:
- self.transferImage(imagelist[todo], debug=False)
+ self.transferImage(imagelist[todo])
# remove the selected image from the list
imagelist = imagelist[:todo] + imagelist[todo + 1:]
else:
--
To view, visit https://gerrit.wikimedia.org/r/135315
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I9ee8c5aa074eda4b84b81f88d3676949ed194476
Gerrit-PatchSet: 1
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Owner: 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 <>
jenkins-bot has submitted this change and it was merged.
Change subject: A simple script to help converting scripts from compat to core
......................................................................
A simple script to help converting scripts from compat to core
most of the conversions are for README-conversion.txt
Change-Id: I17e80e0fd17ec619c95d986ed210b389a0e8d73d
---
A scripts/maintenance/compat2core.py
1 file changed, 186 insertions(+), 0 deletions(-)
Approvals:
Ladsgroup: Looks good to me, approved
jenkins-bot: Verified
diff --git a/scripts/maintenance/compat2core.py b/scripts/maintenance/compat2core.py
new file mode 100644
index 0000000..fe5af47
--- /dev/null
+++ b/scripts/maintenance/compat2core.py
@@ -0,0 +1,186 @@
+#!/usr/bin/python
+# -*- coding: utf-8 -*-
+"""
+This is a helper script to convert compat 1.0 scripts to the new core 2.0
+framework.
+
+NOTE: Please be aware that this script is not be able to convert your codes
+completely. It may support you with some automatic replacements and it gives
+some warnings and hints for converting. Please refer the converting guide
+README-conversion.txt in the core framework folder and check your codes finally.
+
+The scripts asks for the .py file and converts it to
+<scriptname>-core.py in the same directory. The following options are supported:
+
+- warnonly: Do not convert the source but show warning messages. This is good
+ to check already merged scripts.
+
+usage
+
+to convert a script and show warnings about deprecated methods:
+ pwb.py maintenance/compat2core <scriptname>
+
+to show warnings about deprecated methods:
+ pwb.py maintenance/compat2core <scriptname> -warnonly
+"""
+#
+# (C) xqt, 2014
+#
+# Distributed under the terms of the MIT license.
+#
+__version__ = '$Id$'
+#
+
+import os
+import re
+import codecs
+import pywikibot
+
+# be carefull with replacement order!
+replacements = (
+ # doc strings
+ ('#\r?\n__version__',
+ '#\n# Automatically ported from compat branch by compat2core.py script\n'
+ '#\n__version__'),
+ ('Pywikipedia bot team', 'Pywikibot team'),
+ # importing changes
+ ('import wikipedia(?: as pywikibot)?', 'import pywikibot'),
+ ('(?<!from pywikibot )import (config|pagegenerators)',
+ r'from pywikibot import \1'),
+ ('(?<!from pywikibot.compat )import query',
+ 'from pywikibot.compat import query'),
+ # remove deprecated libs
+ ('import catlib\r?\n', ''),
+ ('import userlib\r?\n', ''),
+ # change wikipedia to pywikibot, exclude URLs
+ ('(?<!\.)wikipedia\.', u'pywikibot.'),
+ # site instance call
+ ('pywikibot\.getSite\s*\(\s*', 'pywikibot.Site('),
+ # lang is differen from code. We should use code in core
+ ('([Ss])ite.lang(\W*)', r'\1ite.code\2'),
+ # change compat library classes to pywikibot intrinsic classes
+ ('catlib\.Category\s*\(\s*', 'pywikibot.Category('),
+ ('catlib\.change_category\s*\((\s*)(?P<article>.+?),\s*(?P<oldcat>.+?),',
+ r'\g<article>.change_category(\1\g<oldcat>,'),
+ ('userlib\.User\s*\(\s*', 'pywikibot.User('),
+ # deprecated title methods
+ ('\.urlname\s*\(\s*\)', '.title(asUrl=True)'),
+ ('\.urlname\s*\(\s*(?:withNamespace\s*=\s*)?(True|False)+\s*\)',
+ r'.title(asUrl=True, withNamespace=\1)'),
+ ('\.titleWithoutNamespace\s*\(\s*\)', '.title(withNamespace=False)'),
+ ('\.sectionFreeTitle\s*\(\s*\)', '.title(withSection=False)'),
+ ('\.aslink\s*\(\s*\)', '.title(asLink=True)'),
+ # other deprecated methods
+ ('\.encoding\s*\(\s*\)', '.site.encoding()'),
+ # stopme() is doen by the framework itself
+ ('(\s*)try\:\s*\r?\n\s+main\(\)\s*\r?\n\s*finally\:\s*\r?\n\s+pywikibot\.stopme\(\)',
+ r'\1main()'),
+)
+
+# some warnings which must be changed manually
+warnings = (
+ ('pywikibot.setAction(',
+ 'setAction() no longer works; you must pass an explicit edit summary\n'
+ 'message to put() or put_async()'),
+ ('.removeImage(',
+ 'Page.removeImage() is deprecated and does not work at core'),
+ ('.replaceImage(',
+ 'Page.replaceImage() is deprecated and does not work at core'),
+ ('.getVersionHistory(',
+ 'Page.getVersionHistory() returns a pywikibot.Timestamp object instead of\n'
+ 'a MediaWiki one'),
+ ('.contributions(',
+ 'User.contributions() returns a pywikibot.Timestamp object instead of a\n'
+ 'MediaWiki one'),
+ ('.getFileMd5Sum(',
+ 'ImagePage.getFileMd5Sum() is deprecated should be replaced by '
+ 'getFileSHA1Sum()'),
+ (' wikipedia.',
+ '"wikipedia" library has been changed to "pywikibot".'),
+ ('from wikipedia import',
+ '"wikipedia" library has been changed to "pywikibot". Please find the\n'
+ 'right way to import your object.'),
+ ('query.GetData(',
+ 'query.GetData() should be replaced by pywikibot.data.api.Request or\n'
+ 'by a direct site request'),
+)
+
+
+class ConvertBot(object):
+
+ def __init__(self, filename=None, warnonly=False):
+ self.source = filename
+ self.warnonly = warnonly
+
+ def run(self):
+ self.get_source()
+ self.get_dest()
+ if not self.warnonly:
+ self.convert()
+ self.warning()
+
+ def get_source(self):
+ while True:
+ if self.source is None:
+ self.source = pywikibot.input(
+ 'Please input the .py file to convert '
+ '(no input to leave):')
+ if not self.source:
+ exit()
+ if not self.source.endswith(u'.py'):
+ self.source += '.py'
+ if os.path.exists(self.source):
+ break
+ self.source = os.path.join('scripts', self.source)
+ if os.path.exists(self.source):
+ break
+ pywikibot.output(u'%s does not exist. Please retry.' % self.source)
+ self.source = None
+
+ def get_dest(self):
+ self.dest = u'%s-core.%s' % tuple(self.source.rsplit(u'.', 1))
+ if not self.warnonly and pywikibot.inputChoice(
+ u'Destination file is %s.' % self.dest,
+ ['Yes', 'No'], ['y', 'n'], 'y') == 'n':
+ pywikibot.output('Quitting...')
+ exit()
+
+ def convert(self):
+ f = codecs.open(self.source, "r", "utf-8")
+ text = f.read()
+ f.close()
+ for r in replacements:
+ text = re.sub(r[0], r[1], text)
+ g = codecs.open(self.dest, "w", "utf-8")
+ g.write(text)
+ g.close()
+
+ def warning(self):
+ filename = self.source if self.warnonly else self.dest
+ g = codecs.open(filename, "r", "utf-8")
+ for i, line in enumerate(g, start=1):
+ for w in warnings:
+ if w[0] in line:
+ pywikibot.warning(u'line %d: %s>>> %s\n' % (i, line, w[1]))
+ g.close()
+
+
+def main():
+ filename = None
+ warnonly = False
+
+ # Parse command line arguments for -help option
+ for arg in pywikibot.handleArgs():
+ if arg.startswith('-warnonly'):
+ warnonly = True
+ elif not arg.startswith('-'):
+ filename = arg
+ else:
+ pywikibot.warning(arg + ' is not supported')
+ bot = ConvertBot(filename, warnonly)
+ bot.run()
+
+
+if __name__ == "__main__":
+ pywikibot.stopme() # we do not work on any site
+ main()
--
To view, visit https://gerrit.wikimedia.org/r/134600
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I17e80e0fd17ec619c95d986ed210b389a0e8d73d
Gerrit-PatchSet: 10
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Owner: Xqt <info(a)gno.de>
Gerrit-Reviewer: DrTrigon <dr.trigon(a)surfeu.ch>
Gerrit-Reviewer: Huji <huji.huji(a)gmail.com>
Gerrit-Reviewer: Ladsgroup <ladsgroup(a)gmail.com>
Gerrit-Reviewer: Legoktm <legoktm.wikipedia(a)gmail.com>
Gerrit-Reviewer: Merlijn van Deen <valhallasw(a)arctus.nl>
Gerrit-Reviewer: Russell Blau <russblau(a)imapmail.org>
Gerrit-Reviewer: Siebrand <siebrand(a)kitano.nl>
Gerrit-Reviewer: Xqt <info(a)gno.de>
Gerrit-Reviewer: jenkins-bot <>
jenkins-bot has submitted this change and it was merged.
Change subject: exclude redirects from CosmeticChangesToolkit.putSpacesInLists()
......................................................................
exclude redirects from CosmeticChangesToolkit.putSpacesInLists()
using APISite.redirectRegex(),
a regex based on the internationalized magic word 'REDIRECT'
bug: 55161
Change-Id: Ic8ef2868ef9c55a1cec57a17f5601652918a62c7
---
M scripts/cosmetic_changes.py
1 file changed, 4 insertions(+), 5 deletions(-)
Approvals:
Xqt: Looks good to me, approved
jenkins-bot: Verified
diff --git a/scripts/cosmetic_changes.py b/scripts/cosmetic_changes.py
index 2b67cfc..4a66fd4 100755
--- a/scripts/cosmetic_changes.py
+++ b/scripts/cosmetic_changes.py
@@ -66,7 +66,7 @@
"""
#
# (C) xqt, 2009-2013
-# (C) Pywikibot team, 2006-2013
+# (C) Pywikibot team, 2006-2014
#
# Distributed under the terms of the MIT license.
#
@@ -584,10 +584,9 @@
German, and French Wikipedia. It might be that it is not wanted on other
wikis. If there are any complaints, please file a bug report.
"""
- exceptions = ['comment', 'math', 'nowiki', 'pre', 'source', 'template',
- 'timeline']
- if not (self.redirect or self.template) and \
- pywikibot.calledModuleName() != 'capitalize_redirects':
+ if not self.template:
+ exceptions = ['comment', 'math', 'nowiki', 'pre', 'source', 'template',
+ 'timeline', self.site.redirectRegex()]
text = pywikibot.replaceExcept(
text,
r'(?m)^(?P<bullet>[:;]*(\*+|#+)[:;\*#]*)(?P<char>[^\s\*#:;].+?)',
--
To view, visit https://gerrit.wikimedia.org/r/135166
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: Ic8ef2868ef9c55a1cec57a17f5601652918a62c7
Gerrit-PatchSet: 2
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Owner: Ricordisamoa <ricordisamoa(a)live.it>
Gerrit-Reviewer: Ladsgroup <ladsgroup(a)gmail.com>
Gerrit-Reviewer: Merlijn van Deen <valhallasw(a)arctus.nl>
Gerrit-Reviewer: Ricordisamoa <ricordisamoa(a)live.it>
Gerrit-Reviewer: Xqt <info(a)gno.de>
Gerrit-Reviewer: jenkins-bot <>
jenkins-bot has submitted this change and it was merged.
Change subject: (bugfix) imagetransfer.py: remove broken debug
......................................................................
(bugfix) imagetransfer.py: remove broken debug
In the conversion from lib_images.py to imagetransfer.py,
the following line was dropped:
imageTitle = sourceImagePage.title().encode('utf-8')
https://www.mediawiki.org/wiki/Special:Code/pywikipedia/2066
sha 9f6e1eb090ee6ee355cf65984cd3adcf851c8470
As a result, the logging of the imageTitle has referenced an
undefined variable since 2005. This debug log entry is disabled
in the code. There are also no bugs reported, so it is unlikely to
be needed.
Change-Id: Ie044fba2e32e1f34e9d96eb4baa45bd52fc04e8b
---
M imagetransfer.py
1 file changed, 2 insertions(+), 5 deletions(-)
Approvals:
Xqt: Looks good to me, approved
jenkins-bot: Verified
diff --git a/imagetransfer.py b/imagetransfer.py
index f5979d1..3f28d83 100644
--- a/imagetransfer.py
+++ b/imagetransfer.py
@@ -160,7 +160,7 @@
self.targetSite = targetSite
self.keep_name = keep_name
- def transferImage(self, sourceImagePage, debug=False):
+ def transferImage(self, sourceImagePage):
"""Gets a wikilink to an image, downloads it and its description,
and uploads it to another wikipedia.
Returns the filename which was used to upload the image
@@ -168,9 +168,6 @@
"""
sourceSite = sourceImagePage.site()
- if debug:
- print "-" * 50
- print "Found image: %s" % imageTitle
url = sourceImagePage.fileUrl().encode('utf-8')
pywikibot.output(u"URL should be: %s" % url)
# localize the text that should be printed on the image description page
@@ -291,7 +288,7 @@
pywikibot.output(
u'The image is already on Wikimedia Commons.')
else:
- self.transferImage(imagelist[todo], debug=False)
+ self.transferImage(imagelist[todo])
# remove the selected image from the list
imagelist = imagelist[:todo] + imagelist[todo + 1:]
else:
--
To view, visit https://gerrit.wikimedia.org/r/135294
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: Ie044fba2e32e1f34e9d96eb4baa45bd52fc04e8b
Gerrit-PatchSet: 1
Gerrit-Project: pywikibot/compat
Gerrit-Branch: master
Gerrit-Owner: John Vandenberg <jayvdb(a)gmail.com>
Gerrit-Reviewer: Ladsgroup <ladsgroup(a)gmail.com>
Gerrit-Reviewer: Xqt <info(a)gno.de>
Gerrit-Reviewer: jenkins-bot <>
jenkins-bot has submitted this change and it was merged.
Change subject: harvest_template.py: improve help message
......................................................................
harvest_template.py: improve help message
Change-Id: I578a23111106d95b1aad7bbb160269b5345c62e1
---
M scripts/harvest_template.py
1 file changed, 6 insertions(+), 3 deletions(-)
Approvals:
Xqt: Looks good to me, approved
jenkins-bot: Verified
diff --git a/scripts/harvest_template.py b/scripts/harvest_template.py
index baab240..3939e9b 100755
--- a/scripts/harvest_template.py
+++ b/scripts/harvest_template.py
@@ -3,16 +3,19 @@
"""
Usage:
-python harvest_template.py -lang:nl -template:"Taxobox straalvinnige" orde P70 familie P71 geslacht P74
+python harvest_template.py <generators> -template:"..." template_parameter PID [template_parameter PID]
This will work on all pages that transclude the template in the article
namespace
-You can use any typical pagegenerator to provide with a list of pages:
+These command line parameters can be used to specify which pages to work on:
+
+¶ms;
+
+Examples:
python harvest_template.py -lang:nl -cat:Sisoridae -template:"Taxobox straalvinnige" -namespace:0 orde P70 familie P71 geslacht P74
-¶ms;
"""
#
# (C) Multichill, Amir, 2013
--
To view, visit https://gerrit.wikimedia.org/r/135297
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I578a23111106d95b1aad7bbb160269b5345c62e1
Gerrit-PatchSet: 1
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Owner: 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 <>
jenkins-bot has submitted this change and it was merged.
Change subject: harvest_template.py: template error handling
......................................................................
harvest_template.py: template error handling
- do not process pages if the template doesnt exist
- catch and warn when extract_templates_and_params cant detect
template name correctly
- do not process page template invocation when field or value is empty
Change-Id: Id83cbe01e553655f3aedbb989dd675bcae2a7327
---
M scripts/harvest_template.py
1 file changed, 14 insertions(+), 3 deletions(-)
Approvals:
Xqt: Looks good to me, approved
jenkins-bot: Verified
diff --git a/scripts/harvest_template.py b/scripts/harvest_template.py
index 0d4979f..c494355 100755
--- a/scripts/harvest_template.py
+++ b/scripts/harvest_template.py
@@ -64,8 +64,12 @@
"""
Fetches redirects of the title, so we can check against them
"""
- pywikibot.output('Finding redirects...') # Put some output here since it can take a while
temp = pywikibot.Page(pywikibot.Site(), title, ns=10)
+ if not temp.exists():
+ pywikibot.error(u'Template %s does not exist.' % temp.title())
+ exit()
+
+ pywikibot.output('Finding redirects...') # Put some output here since it can take a while
if temp.isRedirectPage():
temp = temp.getRedirectTarget()
titles = [page.title(withNamespace=False)
@@ -88,13 +92,20 @@
templates = pywikibot.extract_templates_and_params(pagetext)
for (template, fielddict) in templates:
# Clean up template
- template = pywikibot.Page(page.site, template,
- ns=10).title(withNamespace=False)
+ try:
+ template = pywikibot.Page(page.site, template,
+ ns=10).title(withNamespace=False)
+ except pywikibot.exceptions.InvalidTitle as e:
+ pywikibot.error(u"Failed parsing template; '%s' should be the template name." % template)
+ continue
# We found the template we were looking for
if template in self.templateTitles:
for field, value in fielddict.items():
field = field.strip()
value = value.strip()
+ if not field or not value:
+ continue
+
# This field contains something useful for us
if field in self.fields:
# Check if the property isn't already set
--
To view, visit https://gerrit.wikimedia.org/r/135305
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: Id83cbe01e553655f3aedbb989dd675bcae2a7327
Gerrit-PatchSet: 1
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Owner: John Vandenberg <jayvdb(a)gmail.com>
Gerrit-Reviewer: Xqt <info(a)gno.de>
Gerrit-Reviewer: jenkins-bot <>
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 <>