XZise has submitted this change and it was merged.
Change subject: Standardise script main()
......................................................................
Standardise script main()
Allow scripts to be invoked with command line options from within
Python, such as <module>.main('-simulate')
Use new handle_args, and process global arguments before local arguments.
Also add docstrings to main() functions.
Not ready to be standardised:
makecat
casechecker
data_ingestion
Change-Id: I828ba3cf155fb6d3e052564d20768fdf9c3acc95
---
M scripts/add_text.py
M scripts/archivebot.py
M scripts/basic.py
M scripts/blockpageschecker.py
M scripts/blockreview.py
M scripts/capitalize_redirects.py
M scripts/catall.py
M scripts/category.py
M scripts/category_redirect.py
M scripts/cfd.py
M scripts/checkimages.py
M scripts/claimit.py
M scripts/clean_sandbox.py
M scripts/commons_link.py
M scripts/commonscat.py
M scripts/coordinate_import.py
M scripts/cosmetic_changes.py
M scripts/create_categories.py
M scripts/delete.py
M scripts/disambredir.py
M scripts/editarticle.py
M scripts/featured.py
M scripts/fixing_redirects.py
M scripts/flickrripper.py
M scripts/freebasemappingupload.py
M scripts/harvest_template.py
M scripts/illustrate_wikidata.py
M scripts/image.py
M scripts/imagerecat.py
M scripts/imagetransfer.py
M scripts/imageuncat.py
M scripts/interwiki.py
M scripts/isbn.py
M scripts/listpages.py
M scripts/login.py
M scripts/lonelypages.py
M scripts/misspelling.py
M scripts/movepages.py
M scripts/newitem.py
M scripts/noreferences.py
M scripts/nowcommons.py
M scripts/pagefromfile.py
M scripts/protect.py
M scripts/redirect.py
M scripts/reflinks.py
M scripts/replace.py
M scripts/revertbot.py
M scripts/script_wui.py
M scripts/selflink.py
M scripts/solve_disambiguation.py
M scripts/spamremove.py
M scripts/template.py
M scripts/templatecount.py
M scripts/touch.py
M scripts/transferbot.py
M scripts/unlink.py
M scripts/unusedfiles.py
M scripts/upload.py
M scripts/watchlist.py
M scripts/weblinkchecker.py
M scripts/welcome.py
M tox.ini
62 files changed, 603 insertions(+), 140 deletions(-)
Approvals:
John Vandenberg: Looks good to me, but someone else must approve
XZise: Looks good to me, approved
diff --git a/scripts/add_text.py b/scripts/add_text.py
index 1d104e1..8979dba 100644
--- a/scripts/add_text.py
+++ b/scripts/add_text.py
@@ -275,7 +275,15 @@
return (text, newtext, always)
-def main():
+def main(*args):
+ """
+ Process command line arguments and invoke bot.
+
+ If args is an empty list, sys.argv is used.
+
+ @param args: command line arguments
+ @type args: list of unicode
+ """
# If none, the var is setted only for check purpose.
summary = None
addText = None
@@ -292,7 +300,7 @@
up = False
# Process global args and prepare generator args parser
- local_args = pywikibot.handleArgs()
+ local_args = pywikibot.handle_args(args)
genFactory = pagegenerators.GeneratorFactory()
# Loading the arguments
diff --git a/scripts/archivebot.py b/scripts/archivebot.py
index 015f924..63f5090 100644
--- a/scripts/archivebot.py
+++ b/scripts/archivebot.py
@@ -524,7 +524,15 @@
self.page.update(comment)
-def main():
+def main(*args):
+ """
+ Process command line arguments and invoke bot.
+
+ If args is an empty list, sys.argv is used.
+
+ @param args: command line arguments
+ @type args: list of unicode
+ """
filename = None
pagename = None
namespace = None
@@ -537,7 +545,7 @@
if arg.startswith(name):
yield arg[len(name) + 1:]
- for arg in pywikibot.handleArgs():
+ for arg in pywikibot.handle_args(args):
for v in if_arg_value(arg, '-file'):
filename = v
for v in if_arg_value(arg, '-locale'):
diff --git a/scripts/basic.py b/scripts/basic.py
index 99f83f1..c1af240 100755
--- a/scripts/basic.py
+++ b/scripts/basic.py
@@ -136,10 +136,17 @@
return False
-def main():
- """ Process command line arguments and invoke BasicBot. """
+def main(*args):
+ """
+ Process command line arguments and invoke bot.
+
+ If args is an empty list, sys.argv is used.
+
+ @param args: command line arguments
+ @type args: list of unicode
+ """
# Process global arguments to determine desired site
- local_args = pywikibot.handleArgs()
+ local_args = pywikibot.handle_args(args)
# This factory is responsible for processing command line arguments
# that are also used by other scripts and that determine on which pages
diff --git a/scripts/blockpageschecker.py b/scripts/blockpageschecker.py
index 70c5fdf..fd548af 100755
--- a/scripts/blockpageschecker.py
+++ b/scripts/blockpageschecker.py
@@ -205,8 +205,15 @@
editor.edit(page.text)
-def main():
- """Main Function."""
+def main(*args):
+ """
+ Process command line arguments and perform task.
+
+ If args is an empty list, sys.argv is used.
+
+ @param args: command line arguments
+ @type args: list of unicode
+ """
# Loading the comments
global categoryToCheck, project_inserted
# always, define a generator to understand if the user sets one,
@@ -223,7 +230,7 @@
errorCount = 0
# Process global args and prepare generator args parser
- local_args = pywikibot.handleArgs()
+ local_args = pywikibot.handle_args(args)
genFactory = pagegenerators.GeneratorFactory()
# Process local args
diff --git a/scripts/blockreview.py b/scripts/blockreview.py
index f184f57..f3f9c98 100644
--- a/scripts/blockreview.py
+++ b/scripts/blockreview.py
@@ -303,11 +303,19 @@
return True
-def main():
+def main(*args):
+ """
+ Process command line arguments and invoke bot.
+
+ If args is an empty list, sys.argv is used.
+
+ @param args: command line arguments
+ @type args: list of unicode
+ """
show = False
# Parse command line arguments
- for arg in pywikibot.handleArgs():
+ if pywikibot.handle_args(args):
show = True
if not show:
diff --git a/scripts/capitalize_redirects.py b/scripts/capitalize_redirects.py
index 0c4c7a9..d646b38 100644
--- a/scripts/capitalize_redirects.py
+++ b/scripts/capitalize_redirects.py
@@ -87,10 +87,18 @@
pywikibot.output(u"An error occurred, skipping...")
-def main():
+def main(*args):
+ """
+ Process command line arguments and invoke bot.
+
+ If args is an empty list, sys.argv is used.
+
+ @param args: command line arguments
+ @type args: list of unicode
+ """
options = {}
- local_args = pywikibot.handleArgs()
+ local_args = pywikibot.handle_args(args)
genFactory = pagegenerators.GeneratorFactory()
for arg in local_args:
diff --git a/scripts/catall.py b/scripts/catall.py
index 9c176a9..dbd1705 100755
--- a/scripts/catall.py
+++ b/scripts/catall.py
@@ -72,11 +72,19 @@
comment=i18n.twtranslate(site.code, 'catall-changing'))
-def main():
+def main(*args):
+ """
+ Process command line arguments and perform task.
+
+ If args is an empty list, sys.argv is used.
+
+ @param args: command line arguments
+ @type args: list of unicode
+ """
docorrections = True
start = 'A'
- local_args = pywikibot.handleArgs()
+ local_args = pywikibot.handle_args(args)
for arg in local_args:
if arg == '-onlynew':
diff --git a/scripts/category.py b/scripts/category.py
index 429fc8a..ce88daa 100755
--- a/scripts/category.py
+++ b/scripts/category.py
@@ -1034,6 +1034,14 @@
def main(*args):
+ """
+ Process command line arguments and invoke bot.
+
+ If args is an empty list, sys.argv is used.
+
+ @param args: command line arguments
+ @type args: list of unicode
+ """
fromGiven = False
toGiven = False
batchMode = False
@@ -1053,7 +1061,7 @@
depth = 5
# Process global args and prepare generator args parser
- local_args = pywikibot.handleArgs(*args)
+ local_args = pywikibot.handle_args(args)
genFactory = pagegenerators.GeneratorFactory()
# The generator gives the pages that should be worked upon.
diff --git a/scripts/category_redirect.py b/scripts/category_redirect.py
index b6e946f..cb5d321 100755
--- a/scripts/category_redirect.py
+++ b/scripts/category_redirect.py
@@ -416,7 +416,15 @@
def main(*args):
- a = pywikibot.handleArgs(*args)
+ """
+ Process command line arguments and invoke bot.
+
+ If args is an empty list, sys.argv is used.
+
+ @param args: command line arguments
+ @type args: list of unicode
+ """
+ a = pywikibot.handle_args(args)
if len(a) == 1:
raise RuntimeError('Unrecognized argument "%s"' % a[0])
elif a:
diff --git a/scripts/cfd.py b/scripts/cfd.py
index ab2b0e9..c29e19d 100644
--- a/scripts/cfd.py
+++ b/scripts/cfd.py
@@ -54,8 +54,16 @@
return self.result
-def main():
- pywikibot.handleArgs()
+def main(*args):
+ """
+ Process command line arguments and perform task.
+
+ If args is an empty list, sys.argv is used.
+
+ @param args: command line arguments
+ @type args: list of unicode
+ """
+ pywikibot.handle_args(args)
page = pywikibot.Page(pywikibot.Site(), cfdPage)
diff --git a/scripts/checkimages.py b/scripts/checkimages.py
index 980f3ce..ff56c81 100644
--- a/scripts/checkimages.py
+++ b/scripts/checkimages.py
@@ -1761,8 +1761,15 @@
return True
-def main():
- """Main function."""
+def main(*args):
+ """
+ Process command line arguments and invoke bot.
+
+ If args is an empty list, sys.argv is used.
+
+ @param args: command line arguments
+ @type args: list of unicode
+ """
# Command line configurable parameters
repeat = True # Restart after having check all the images?
limit = 80 # How many images check?
@@ -1781,7 +1788,7 @@
generator = None
# Here below there are the parameters.
- for arg in pywikibot.handleArgs():
+ for arg in pywikibot.handle_args(args):
if arg.startswith('-limit'):
if len(arg) == 7:
limit = int(pywikibot.input(
diff --git a/scripts/claimit.py b/scripts/claimit.py
index d389c93..108f2f7 100755
--- a/scripts/claimit.py
+++ b/scripts/claimit.py
@@ -149,12 +149,20 @@
return True
-def main():
+def main(*args):
+ """
+ Process command line arguments and invoke bot.
+
+ If args is an empty list, sys.argv is used.
+
+ @param args: command line arguments
+ @type args: list of unicode
+ """
exists_arg = ''
commandline_claims = list()
# Process global args and prepare generator args parser
- local_args = pywikibot.handleArgs()
+ local_args = pywikibot.handle_args(args)
gen = pagegenerators.GeneratorFactory()
for arg in local_args:
diff --git a/scripts/clean_sandbox.py b/scripts/clean_sandbox.py
index 052ec14..ee1666d 100755
--- a/scripts/clean_sandbox.py
+++ b/scripts/clean_sandbox.py
@@ -272,9 +272,17 @@
time.sleep(self.getOption('hours') * 60 * 60)
-def main():
+def main(*args):
+ """
+ Process command line arguments and invoke bot.
+
+ If args is an empty list, sys.argv is used.
+
+ @param args: command line arguments
+ @type args: list of unicode
+ """
opts = {}
- for arg in pywikibot.handleArgs():
+ for arg in pywikibot.handle_args(args):
if arg.startswith('-hours:'):
opts['hours'] = float(arg[7:])
opts['no_repeat'] = False
diff --git a/scripts/commons_link.py b/scripts/commons_link.py
index 45887c0..690d1e1 100644
--- a/scripts/commons_link.py
+++ b/scripts/commons_link.py
@@ -107,10 +107,18 @@
pywikibot.output(u'Page %s is locked' % page.title())
-def main():
+def main(*args):
+ """
+ Process command line arguments and invoke bot.
+
+ If args is an empty list, sys.argv is used.
+
+ @param args: command line arguments
+ @type args: list of unicode
+ """
options = {}
- local_args = pywikibot.handleArgs()
+ local_args = pywikibot.handle_args(args)
genFactory = pagegenerators.GeneratorFactory()
for arg in local_args:
diff --git a/scripts/commonscat.py b/scripts/commonscat.py
index 5029830..760a5cc 100755
--- a/scripts/commonscat.py
+++ b/scripts/commonscat.py
@@ -498,9 +498,14 @@
return u''
-def main():
- """ Parse the command line arguments and get a pagegenerator to work on.
- Iterate through all the pages.
+def main(*args):
+ """
+ Process command line arguments and invoke bot.
+
+ If args is an empty list, sys.argv is used.
+
+ @param args: command line arguments
+ @type args: list of unicode
"""
summary = None
generator = None
@@ -510,7 +515,7 @@
ns.append(14)
# Process global args and prepare generator args parser
- local_args = pywikibot.handleArgs()
+ local_args = pywikibot.handle_args(args)
genFactory = pagegenerators.GeneratorFactory()
for arg in local_args:
diff --git a/scripts/coordinate_import.py b/scripts/coordinate_import.py
index 71cef9c..0febc70 100644
--- a/scripts/coordinate_import.py
+++ b/scripts/coordinate_import.py
@@ -101,9 +101,17 @@
pywikibot.output(u'Skipping unsupported globe: %s' % e.args)
-def main():
+def main(*args):
+ """
+ Process command line arguments and invoke bot.
+
+ If args is an empty list, sys.argv is used.
+
+ @param args: command line arguments
+ @type args: list of unicode
+ """
# Process global args and prepare generator args parser
- local_args = pywikibot.handleArgs()
+ local_args = pywikibot.handle_args(args)
gen = pagegenerators.GeneratorFactory()
for arg in local_args:
diff --git a/scripts/cosmetic_changes.py b/scripts/cosmetic_changes.py
index e758452..1c827fb 100755
--- a/scripts/cosmetic_changes.py
+++ b/scripts/cosmetic_changes.py
@@ -919,12 +919,20 @@
% page.title(asLink=True))
-def main():
+def main(*args):
+ """
+ Process command line arguments and invoke bot.
+
+ If args is an empty list, sys.argv is used.
+
+ @param args: command line arguments
+ @type args: list of unicode
+ """
answer = 'y'
options = {}
# Process global args and prepare generator args parser
- local_args = pywikibot.handleArgs()
+ local_args = pywikibot.handle_args(args)
genFactory = pagegenerators.GeneratorFactory()
for arg in local_args:
@@ -967,7 +975,4 @@
pywikibot.showHelp()
if __name__ == "__main__":
- try:
- main()
- finally:
- pywikibot.stopme()
+ main()
diff --git a/scripts/create_categories.py b/scripts/create_categories.py
index 7294a57..568219c 100755
--- a/scripts/create_categories.py
+++ b/scripts/create_categories.py
@@ -72,14 +72,21 @@
self.create_category(page)
-def main():
- """Main loop. Get a generator and options."""
+def main(*args):
+ """
+ Process command line arguments and invoke bot.
+
+ If args is an empty list, sys.argv is used.
+
+ @param args: command line arguments
+ @type args: list of unicode
+ """
parent = None
basename = None
options = {}
# Process global args and prepare generator args parser
- local_args = pywikibot.handleArgs()
+ local_args = pywikibot.handle_args(args)
genFactory = pagegenerators.GeneratorFactory()
for arg in local_args:
diff --git a/scripts/delete.py b/scripts/delete.py
index 2efe8e0..2b5c329 100644
--- a/scripts/delete.py
+++ b/scripts/delete.py
@@ -75,14 +75,22 @@
page.delete(self.summary, not self.getOption('always'))
-def main():
+def main(*args):
+ """
+ Process command line arguments and invoke bot.
+
+ If args is an empty list, sys.argv is used.
+
+ @param args: command line arguments
+ @type args: list of unicode
+ """
pageName = ''
summary = None
generator = None
options = {}
# read command line parameters
- local_args = pywikibot.handleArgs()
+ local_args = pywikibot.handle_args(args)
genFactory = pagegenerators.GeneratorFactory()
mysite = pywikibot.Site()
diff --git a/scripts/disambredir.py b/scripts/disambredir.py
index 4cbc419..3413dde 100644
--- a/scripts/disambredir.py
+++ b/scripts/disambredir.py
@@ -149,8 +149,16 @@
page.put(text, comment)
-def main():
- local_args = pywikibot.handleArgs()
+def main(*args):
+ """
+ Process command line arguments and invoke bot.
+
+ If args is an empty list, sys.argv is used.
+
+ @param args: command line arguments
+ @type args: list of unicode
+ """
+ local_args = pywikibot.handle_args(args)
generator = None
start = local_args[0] if local_args else '!'
diff --git a/scripts/editarticle.py b/scripts/editarticle.py
index 9e4e16a..d9ffe13 100755
--- a/scripts/editarticle.py
+++ b/scripts/editarticle.py
@@ -40,7 +40,7 @@
def set_options(self, *args):
"""Parse commandline and set options attribute."""
my_args = []
- for arg in pywikibot.handleArgs(*args):
+ for arg in pywikibot.handle_args(args):
my_args.append(arg)
parser = optparse.OptionParser()
parser.add_option("-r", "--edit_redirect", action="store_true",
@@ -97,6 +97,14 @@
def main(*args):
+ """
+ Process command line arguments and invoke bot.
+
+ If args is an empty list, sys.argv is used.
+
+ @param args: command line arguments
+ @type args: list of unicode
+ """
app = ArticleEditor(*args)
app.run()
diff --git a/scripts/featured.py b/scripts/featured.py
index 59a4d4b..7413860 100644
--- a/scripts/featured.py
+++ b/scripts/featured.py
@@ -598,8 +598,16 @@
def main(*args):
+ """
+ Process command line arguments and invoke bot.
+
+ If args is an empty list, sys.argv is used.
+
+ @param args: command line arguments
+ @type args: list of unicode
+ """
options = {}
- for arg in pywikibot.handleArgs():
+ for arg in pywikibot.handle_args(args):
if arg.startswith('-fromlang:'):
options[arg[1:9]] = arg[10:].split(",")
elif arg.startswith('-after:'):
@@ -617,7 +625,4 @@
if __name__ == "__main__":
- try:
- main()
- finally:
- pywikibot.stopme()
+ main()
diff --git a/scripts/fixing_redirects.py b/scripts/fixing_redirects.py
index 3e13a6e..8a7fa0f 100644
--- a/scripts/fixing_redirects.py
+++ b/scripts/fixing_redirects.py
@@ -187,12 +187,20 @@
pywikibot.error('unable to put %s' % page)
-def main():
+def main(*args):
+ """
+ Process command line arguments and invoke bot.
+
+ If args is an empty list, sys.argv is used.
+
+ @param args: command line arguments
+ @type args: list of unicode
+ """
featured = False
gen = None
# Process global args and prepare generator args parser
- local_args = pywikibot.handleArgs()
+ local_args = pywikibot.handle_args(args)
genFactory = pagegenerators.GeneratorFactory()
for arg in local_args:
diff --git a/scripts/flickrripper.py b/scripts/flickrripper.py
index 46d3475..eaff57e 100644
--- a/scripts/flickrripper.py
+++ b/scripts/flickrripper.py
@@ -517,7 +517,15 @@
return
-def main():
+def main(*args):
+ """
+ Process command line arguments and invoke bot.
+
+ If args is an empty list, sys.argv is used.
+
+ @param args: command line arguments
+ @type args: list of unicode
+ """
# Get the api key
if not config.flickr['api_key']:
pywikibot.output('Flickr api key not found! Get yourself an api key')
@@ -567,7 +575,7 @@
# Should be renamed to overrideLicense or something like that
override = u''
- for arg in pywikibot.handleArgs():
+ for arg in pywikibot.handle_args(args):
if arg.startswith('-group_id'):
if len(arg) == 9:
group_id = pywikibot.input(u'What is the group_id of the
pool?')
diff --git a/scripts/freebasemappingupload.py b/scripts/freebasemappingupload.py
index 59be5ce..b021abd 100644
--- a/scripts/freebasemappingupload.py
+++ b/scripts/freebasemappingupload.py
@@ -96,9 +96,17 @@
pywikibot.output('Claim added!')
-def main():
+def main(*args):
+ """
+ Process command line arguments and invoke bot.
+
+ If args is an empty list, sys.argv is used.
+
+ @param args: command line arguments
+ @type args: list of unicode
+ """
filename = 'fb2w.nt.gz' # Default filename
- for arg in pywikibot.handleArgs():
+ for arg in pywikibot.handle_args(args):
if arg.startswith('-filename'):
filename = arg[11:]
bot = FreebaseMapperRobot(filename)
diff --git a/scripts/harvest_template.py b/scripts/harvest_template.py
index cdb1275..60b5b2f 100755
--- a/scripts/harvest_template.py
+++ b/scripts/harvest_template.py
@@ -180,12 +180,20 @@
claim.addSource(source, bot=True)
-def main():
+def main(*args):
+ """
+ Process command line arguments and invoke bot.
+
+ If args is an empty list, sys.argv is used.
+
+ @param args: command line arguments
+ @type args: list of unicode
+ """
commandline_arguments = list()
template_title = u''
# Process global args and prepare generator args parser
- local_args = pywikibot.handleArgs()
+ local_args = pywikibot.handle_args(args)
gen = pg.GeneratorFactory()
for arg in local_args:
diff --git a/scripts/illustrate_wikidata.py b/scripts/illustrate_wikidata.py
index 0a4dc1c..3d9b737 100644
--- a/scripts/illustrate_wikidata.py
+++ b/scripts/illustrate_wikidata.py
@@ -86,9 +86,17 @@
newclaim.addSource(source, bot=True)
-def main():
+def main(*args):
+ """
+ Process command line arguments and invoke bot.
+
+ If args is an empty list, sys.argv is used.
+
+ @param args: command line arguments
+ @type args: list of unicode
+ """
# Process global args and prepare generator args parser
- local_args = pywikibot.handleArgs()
+ local_args = pywikibot.handle_args(args)
gen = pg.GeneratorFactory()
wdproperty = u'P18'
diff --git a/scripts/image.py b/scripts/image.py
index 1bcb42b..68eb89f 100644
--- a/scripts/image.py
+++ b/scripts/image.py
@@ -169,12 +169,20 @@
replaceBot.run()
-def main():
+def main(*args):
+ """
+ Process command line arguments and invoke bot.
+
+ If args is an empty list, sys.argv is used.
+
+ @param args: command line arguments
+ @type args: list of unicode
+ """
old_image = None
new_image = None
options = {}
- for arg in pywikibot.handleArgs():
+ for arg in pywikibot.handle_args(args):
if arg == '-always':
options['always'] = True
elif arg == '-loose':
diff --git a/scripts/imagerecat.py b/scripts/imagerecat.py
index 295bb7f..8a8558d 100644
--- a/scripts/imagerecat.py
+++ b/scripts/imagerecat.py
@@ -440,14 +440,21 @@
return result
-def main():
- """Main loop. Get a generator and options. Work on all images in the
generator."""
+def main(*args):
+ """
+ Process command line arguments and invoke bot.
+
+ If args is an empty list, sys.argv is used.
+
+ @param args: command line arguments
+ @type args: list of unicode
+ """
generator = None
onlyFilter = False
onlyUncat = False
# Process global args and prepare generator args parser
- local_args = pywikibot.handleArgs()
+ local_args = pywikibot.handle_args(args)
genFactory = pagegenerators.GeneratorFactory()
global search_wikis
diff --git a/scripts/imagetransfer.py b/scripts/imagetransfer.py
index f26e254..587502b 100644
--- a/scripts/imagetransfer.py
+++ b/scripts/imagetransfer.py
@@ -298,7 +298,15 @@
pywikibot.output(u'No such image number.')
-def main():
+def main(*args):
+ """
+ Process command line arguments and invoke bot.
+
+ If args is an empty list, sys.argv is used.
+
+ @param args: command line arguments
+ @type args: list of unicode
+ """
pageTitle = None
gen = None
@@ -307,7 +315,7 @@
targetLang = None
targetFamily = None
- local_args = pywikibot.handleArgs()
+ local_args = pywikibot.handle_args(args)
for arg in local_args:
if arg == '-interwiki':
diff --git a/scripts/imageuncat.py b/scripts/imageuncat.py
index 0bcb3d9..cc2aa9b 100755
--- a/scripts/imageuncat.py
+++ b/scripts/imageuncat.py
@@ -1315,12 +1315,17 @@
def main(*args):
- '''
- Grab a bunch of images and tag them if they are not categorized.
- '''
+ """
+ Process command line arguments and invoke bot.
+
+ If args is an empty list, sys.argv is used.
+
+ @param args: command line arguments
+ @type args: list of unicode
+ """
generator = None
- local_args = pywikibot.handleArgs(*args)
+ local_args = pywikibot.handle_args(args)
# use the default imagerepository normally commons
site = pywikibot.Site().image_repository()
diff --git a/scripts/interwiki.py b/scripts/interwiki.py
index f415cb7..61bc6b0 100755
--- a/scripts/interwiki.py
+++ b/scripts/interwiki.py
@@ -2417,7 +2417,15 @@
bot.add(page, hints=hintStrings)
-def main():
+def main(*args):
+ """
+ Process command line arguments and invoke bot.
+
+ If args is an empty list, sys.argv is used.
+
+ @param args: command line arguments
+ @type args: list of unicode
+ """
singlePageTitle = ''
opthintsonly = False
# Which namespaces should be processed?
@@ -2436,7 +2444,7 @@
newPages = None
# Process global args and prepare generator args parser
- local_args = pywikibot.handleArgs()
+ local_args = pywikibot.handle_args(args)
genFactory = pagegenerators.GeneratorFactory()
for arg in local_args:
diff --git a/scripts/isbn.py b/scripts/isbn.py
index ac67dac..2a22aaa 100755
--- a/scripts/isbn.py
+++ b/scripts/isbn.py
@@ -1417,11 +1417,19 @@
self.treat(page)
-def main():
+def main(*args):
+ """
+ Process command line arguments and invoke bot.
+
+ If args is an empty list, sys.argv is used.
+
+ @param args: command line arguments
+ @type args: list of unicode
+ """
options = {}
# Process global args and prepare generator args parser
- local_args = pywikibot.handleArgs()
+ local_args = pywikibot.handle_args(args)
genFactory = pagegenerators.GeneratorFactory()
for arg in local_args:
diff --git a/scripts/listpages.py b/scripts/listpages.py
index e17c686..0580a54 100644
--- a/scripts/listpages.py
+++ b/scripts/listpages.py
@@ -142,7 +142,14 @@
def main(*args):
- """Main function."""
+ """
+ Process command line arguments and invoke bot.
+
+ If args is an empty list, sys.argv is used.
+
+ @param args: command line arguments
+ @type args: list of unicode
+ """
gen = None
notitle = False
fmt = '1'
@@ -150,7 +157,7 @@
page_get = False
# Process global args and prepare generator args parser
- local_args = pywikibot.handleArgs(*args)
+ local_args = pywikibot.handle_args(args)
genFactory = GeneratorFactory()
for arg in local_args:
diff --git a/scripts/login.py b/scripts/login.py
index adb7a12..71cdbb2 100755
--- a/scripts/login.py
+++ b/scripts/login.py
@@ -62,11 +62,19 @@
def main(*args):
+ """
+ Process command line arguments and invoke bot.
+
+ If args is an empty list, sys.argv is used.
+
+ @param args: command line arguments
+ @type args: list of unicode
+ """
password = None
sysop = False
logall = False
logout = False
- for arg in pywikibot.handleArgs(*args):
+ for arg in pywikibot.handle_args(args):
if arg.startswith("-pass"):
if len(arg) == 5:
password = pywikibot.input(u'Password for all accounts (no
characters will be shown):',
@@ -112,5 +120,7 @@
except SiteDefinitionError:
pywikibot.output(u'%s.%s is not a valid site, please remove it'
u' from your config' % (lang, familyName))
+
+
if __name__ == "__main__":
main()
diff --git a/scripts/lonelypages.py b/scripts/lonelypages.py
index f956d2a..89695bc 100644
--- a/scripts/lonelypages.py
+++ b/scripts/lonelypages.py
@@ -189,10 +189,18 @@
self.userPut(page, oldtxt, newtxt, comment=self.comment)
-def main():
+def main(*args):
+ """
+ Process command line arguments and invoke bot.
+
+ If args is an empty list, sys.argv is used.
+
+ @param args: command line arguments
+ @type args: list of unicode
+ """
options = {}
- local_args = pywikibot.handleArgs()
+ local_args = pywikibot.handle_args(args)
genFactory = pagegenerators.GeneratorFactory()
site = pywikibot.Site()
diff --git a/scripts/misspelling.py b/scripts/misspelling.py
index ec9644b..2865c81 100644
--- a/scripts/misspelling.py
+++ b/scripts/misspelling.py
@@ -127,14 +127,22 @@
{'page': disambPage.title()})
-def main():
+def main(*args):
+ """
+ Process command line arguments and invoke bot.
+
+ If args is an empty list, sys.argv is used.
+
+ @param args: command line arguments
+ @type args: list of unicode
+ """
# the option that's always selected when the bot wonders what to do with
# a link. If it's None, the user is prompted (default behaviour).
always = None
main_only = False
firstPageTitle = None
- for arg in pywikibot.handleArgs():
+ for arg in pywikibot.handle_args(args):
if arg.startswith('-always:'):
always = arg[8:]
elif arg.startswith('-start'):
diff --git a/scripts/movepages.py b/scripts/movepages.py
index 5af0ac3..7c2c6ac 100644
--- a/scripts/movepages.py
+++ b/scripts/movepages.py
@@ -197,14 +197,22 @@
self.treat(page)
-def main():
+def main(*args):
+ """
+ Process command line arguments and invoke bot.
+
+ If args is an empty list, sys.argv is used.
+
+ @param args: command line arguments
+ @type args: list of unicode
+ """
gen = None
oldName = None
options = {}
fromToPairs = []
# Process global args and prepare generator args parser
- local_args = pywikibot.handleArgs()
+ local_args = pywikibot.handle_args(args)
genFactory = pagegenerators.GeneratorFactory()
for arg in local_args:
diff --git a/scripts/newitem.py b/scripts/newitem.py
index b6ea11f..a756921 100644
--- a/scripts/newitem.py
+++ b/scripts/newitem.py
@@ -118,9 +118,17 @@
page.put(page.text)
-def main():
+def main(*args):
+ """
+ Process command line arguments and invoke bot.
+
+ If args is an empty list, sys.argv is used.
+
+ @param args: command line arguments
+ @type args: list of unicode
+ """
# Process global args and prepare generator args parser
- local_args = pywikibot.handleArgs()
+ local_args = pywikibot.handle_args(args)
gen = pagegenerators.GeneratorFactory()
options = {}
diff --git a/scripts/noreferences.py b/scripts/noreferences.py
index 8fece93..0c5ff7c 100755
--- a/scripts/noreferences.py
+++ b/scripts/noreferences.py
@@ -650,11 +650,19 @@
pywikibot.output(u'Skipping %s (locked page)' %
page.title())
-def main():
+def main(*args):
+ """
+ Process command line arguments and invoke bot.
+
+ If args is an empty list, sys.argv is used.
+
+ @param args: command line arguments
+ @type args: list of unicode
+ """
options = {}
# Process global args and prepare generator args parser
- local_args = pywikibot.handleArgs()
+ local_args = pywikibot.handle_args(args)
genFactory = pagegenerators.GeneratorFactory()
for arg in local_args:
diff --git a/scripts/nowcommons.py b/scripts/nowcommons.py
index ef6d436..dc16bd0 100644
--- a/scripts/nowcommons.py
+++ b/scripts/nowcommons.py
@@ -429,10 +429,18 @@
continue
-def main():
+def main(*args):
+ """
+ Process command line arguments and invoke bot.
+
+ If args is an empty list, sys.argv is used.
+
+ @param args: command line arguments
+ @type args: list of unicode
+ """
options = {}
- for arg in pywikibot.handleArgs():
+ for arg in pywikibot.handle_args(args):
if arg.startswith('-') and \
arg[1:] in ('always', 'replace', 'replaceloose', 'replaceonly'):
options[arg[1:]] = True
diff --git a/scripts/pagefromfile.py b/scripts/pagefromfile.py
index dc50d89..cf067ba 100644
--- a/scripts/pagefromfile.py
+++ b/scripts/pagefromfile.py
@@ -241,8 +241,15 @@
return location.end(), title, contents
-def main():
- """Main function."""
+def main(*args):
+ """
+ Process command line arguments and invoke bot.
+
+ If args is an empty list, sys.argv is used.
+
+ @param args: command line arguments
+ @type args: list of unicode
+ """
# Adapt these to the file you are using. 'pageStartMarker' and
# 'pageEndMarker' are the beginning and end of each entry. Take text that
# should be included and does not occur elsewhere in the text.
@@ -257,7 +264,7 @@
include = False
notitle = False
- for arg in pywikibot.handleArgs():
+ for arg in pywikibot.handle_args(args):
if arg.startswith("-start:"):
pageStartMarker = arg[7:]
elif arg.startswith("-end:"):
diff --git a/scripts/protect.py b/scripts/protect.py
index 7a20ed1..0a4279f 100644
--- a/scripts/protect.py
+++ b/scripts/protect.py
@@ -138,6 +138,14 @@
def main(*args):
+ """
+ Process command line arguments and invoke bot.
+
+ If args is an empty list, sys.argv is used.
+
+ @param args: command line arguments
+ @type args: list of unicode
+ """
options = {}
message_properties = {}
generator = None
@@ -152,7 +160,7 @@
}
# read command line parameters
- local_args = pywikibot.handleArgs(*args)
+ local_args = pywikibot.handle_args(args)
genFactory = pagegenerators.GeneratorFactory()
site = pywikibot.Site()
diff --git a/scripts/redirect.py b/scripts/redirect.py
index d6eb487..2f3d087 100755
--- a/scripts/redirect.py
+++ b/scripts/redirect.py
@@ -711,6 +711,14 @@
def main(*args):
+ """
+ Process command line arguments and invoke bot.
+
+ If args is an empty list, sys.argv is used.
+
+ @param args: command line arguments
+ @type args: list of unicode
+ """
options = {}
# what the bot should do (either resolve double redirs, or delete broken
# redirs)
@@ -731,7 +739,7 @@
until = ''
number = None
step = None
- for arg in pywikibot.handleArgs(*args):
+ for arg in pywikibot.handle_args(args):
if arg == 'double' or arg == 'do':
action = 'double'
elif arg == 'broken' or arg == 'br':
diff --git a/scripts/reflinks.py b/scripts/reflinks.py
index f0b7d61..2404093 100644
--- a/scripts/reflinks.py
+++ b/scripts/reflinks.py
@@ -768,14 +768,22 @@
return
-def main():
+def main(*args):
+ """
+ Process command line arguments and invoke bot.
+
+ If args is an empty list, sys.argv is used.
+
+ @param args: command line arguments
+ @type args: list of unicode
+ """
xmlFilename = None
options = {}
namespaces = []
generator = None
# Process global args and prepare generator args parser
- local_args = pywikibot.handleArgs()
+ local_args = pywikibot.handle_args(args)
genFactory = pagegenerators.GeneratorFactory()
for arg in local_args:
diff --git a/scripts/replace.py b/scripts/replace.py
index 5c9e750..da332cf 100755
--- a/scripts/replace.py
+++ b/scripts/replace.py
@@ -438,6 +438,14 @@
def main(*args):
+ """
+ Process command line arguments and invoke bot.
+
+ If args is an empty list, sys.argv is used.
+
+ @param args: command line arguments
+ @type args: list of unicode
+ """
add_cat = None
gen = None
# summary message
@@ -485,7 +493,7 @@
# Read commandline parameters.
- local_args = pywikibot.handleArgs(*args)
+ local_args = pywikibot.handle_args(args)
genFactory = pagegenerators.GeneratorFactory()
for arg in local_args:
diff --git a/scripts/revertbot.py b/scripts/revertbot.py
index 1b6d54e..7c28df2 100644
--- a/scripts/revertbot.py
+++ b/scripts/revertbot.py
@@ -132,10 +132,18 @@
return False
-def main():
+def main(*args):
+ """
+ Process command line arguments and invoke bot.
+
+ If args is an empty list, sys.argv is used.
+
+ @param args: command line arguments
+ @type args: list of unicode
+ """
user = None
rollback = False
- for arg in pywikibot.handleArgs():
+ for arg in pywikibot.handle_args(args):
if arg.startswith('-username'):
if len(arg) == 9:
user = pywikibot.input(
diff --git a/scripts/script_wui.py b/scripts/script_wui.py
index 9d0aab2..d3a2c82 100755
--- a/scripts/script_wui.py
+++ b/scripts/script_wui.py
@@ -274,10 +274,18 @@
# comment = pywikibot.translate(self.site.lang,
bot_config['msg']))
-def main():
+def main(*args):
+ """
+ Process command line arguments and invoke bot.
+
+ If args is an empty list, sys.argv is used.
+
+ @param args: command line arguments
+ @type args: list of unicode
+ """
global __simulate, __sys_argv
- for arg in pywikibot.handleArgs():
+ for arg in pywikibot.handle_args(args):
pywikibot.showHelp('script_wui')
return
@@ -295,5 +303,4 @@
raise
if __name__ == "__main__":
- # run bot
main()
diff --git a/scripts/selflink.py b/scripts/selflink.py
index 8ce58e2..fdbc920 100644
--- a/scripts/selflink.py
+++ b/scripts/selflink.py
@@ -183,11 +183,19 @@
self.treat(page)
-def main():
+def main(*args):
+ """
+ Process command line arguments and invoke bot.
+
+ If args is an empty list, sys.argv is used.
+
+ @param args: command line arguments
+ @type args: list of unicode
+ """
# Page generator
gen = None
# Process global args and prepare generator args parser
- local_args = pywikibot.handleArgs()
+ local_args = pywikibot.handle_args(args)
genFactory = GeneratorFactory()
botArgs = {}
@@ -207,7 +215,4 @@
bot.run()
if __name__ == "__main__":
- try:
- main()
- finally:
- pywikibot.stopme()
+ main()
diff --git a/scripts/solve_disambiguation.py b/scripts/solve_disambiguation.py
index c6d86a2..1c70083 100644
--- a/scripts/solve_disambiguation.py
+++ b/scripts/solve_disambiguation.py
@@ -1006,6 +1006,14 @@
def main(*args):
+ """
+ Process command line arguments and invoke bot.
+
+ If args is an empty list, sys.argv is used.
+
+ @param args: command line arguments
+ @type args: list of unicode
+ """
# the option that's always selected when the bot wonders what to do with
# a link. If it's None, the user is prompted (default behaviour).
always = None
@@ -1020,7 +1028,7 @@
# For sorting the linked pages, case can be ignored
minimum = 0
- local_args = pywikibot.handleArgs(*args)
+ local_args = pywikibot.handle_args(args)
for arg in local_args:
if arg.startswith('-primary:'):
diff --git a/scripts/spamremove.py b/scripts/spamremove.py
index 57c1b53..f4156bf 100755
--- a/scripts/spamremove.py
+++ b/scripts/spamremove.py
@@ -37,11 +37,19 @@
from pywikibot.editor import TextEditor
-def main():
+def main(*args):
+ """
+ Process command line arguments and perform task.
+
+ If args is an empty list, sys.argv is used.
+
+ @param args: command line arguments
+ @type args: list of unicode
+ """
always = False
namespaces = []
spamSite = ''
- for arg in pywikibot.handleArgs():
+ for arg in pywikibot.handle_args(args):
if arg == "-always":
always = True
elif arg.startswith('-namespace:'):
diff --git a/scripts/template.py b/scripts/template.py
index 48763cc..bd3fc40 100755
--- a/scripts/template.py
+++ b/scripts/template.py
@@ -292,6 +292,14 @@
def main(*args):
+ """
+ Process command line arguments and invoke bot.
+
+ If args is an empty list, sys.argv is used.
+
+ @param args: command line arguments
+ @type args: list of unicode
+ """
templateNames = []
templates = {}
options = {}
@@ -302,7 +310,7 @@
timestamp = None
# read command line parameters
- local_args = pywikibot.handleArgs(*args)
+ local_args = pywikibot.handle_args(args)
genFactory = pagegenerators.GeneratorFactory()
for arg in local_args:
if arg == '-remove':
diff --git a/scripts/templatecount.py b/scripts/templatecount.py
index cd2aa01..b26c37d 100644
--- a/scripts/templatecount.py
+++ b/scripts/templatecount.py
@@ -107,12 +107,20 @@
yield template, transcludingArray
-def main():
+def main(*args):
+ """
+ Process command line arguments and invoke bot.
+
+ If args is an empty list, sys.argv is used.
+
+ @param args: command line arguments
+ @type args: list of unicode
+ """
operation = None
argsList = []
namespaces = []
- for arg in pywikibot.handleArgs():
+ for arg in pywikibot.handle_args(args):
if arg in ('-count', '-list'):
operation = arg[1:]
elif arg.startswith('-namespace:'):
diff --git a/scripts/touch.py b/scripts/touch.py
index 4caabe1..3d696a6 100755
--- a/scripts/touch.py
+++ b/scripts/touch.py
@@ -68,11 +68,19 @@
def main(*args):
+ """
+ Process command line arguments and invoke bot.
+
+ If args is an empty list, sys.argv is used.
+
+ @param args: command line arguments
+ @type args: list of unicode
+ """
gen = None
options = {}
# Process global args and prepare generator args parser
- local_args = pywikibot.handleArgs(*args)
+ local_args = pywikibot.handle_args(args)
genFactory = pagegenerators.GeneratorFactory()
for arg in local_args:
diff --git a/scripts/transferbot.py b/scripts/transferbot.py
index 12590c1..594ba59 100644
--- a/scripts/transferbot.py
+++ b/scripts/transferbot.py
@@ -77,8 +77,16 @@
pass
-def main():
- tohandle = pywikibot.handleArgs()
+def main(*args):
+ """
+ Process command line arguments and invoke bot.
+
+ If args is an empty list, sys.argv is used.
+
+ @param args: command line arguments
+ @type args: list of unicode
+ """
+ local_args = pywikibot.handle_args(args)
fromsite = pywikibot.Site()
tolang = fromsite.code
@@ -89,7 +97,7 @@
genFactory = pagegenerators.GeneratorFactory()
- for arg in tohandle:
+ for arg in local_args:
if genFactory.handleArg(arg):
gen_args.append(arg)
continue
diff --git a/scripts/unlink.py b/scripts/unlink.py
index b9525ce..ee0796a 100755
--- a/scripts/unlink.py
+++ b/scripts/unlink.py
@@ -164,13 +164,21 @@
pywikibot.output(u"Page %s is locked?!" % page.title(asLink=True))
-def main():
+def main(*args):
+ """
+ Process command line arguments and invoke bot.
+
+ If args is an empty list, sys.argv is used.
+
+ @param args: command line arguments
+ @type args: list of unicode
+ """
# This temporary string is used to read the title
# of the page that should be unlinked.
page_title = None
options = {}
- for arg in pywikibot.handleArgs():
+ for arg in pywikibot.handle_args(args):
if arg.startswith('-namespace:'):
if 'namespaces' not in options:
options['namespaces'] = []
diff --git a/scripts/unusedfiles.py b/scripts/unusedfiles.py
index 3125e95..bf17f78 100644
--- a/scripts/unusedfiles.py
+++ b/scripts/unusedfiles.py
@@ -103,10 +103,18 @@
self.userPut(page, oldtext, text, comment=self.summary)
-def main():
+def main(*args):
+ """
+ Process command line arguments and invoke bot.
+
+ If args is an empty list, sys.argv is used.
+
+ @param args: command line arguments
+ @type args: list of unicode
+ """
options = {}
- for arg in pywikibot.handleArgs():
+ for arg in pywikibot.handle_args(args):
if arg == '-always':
options['always'] = True
diff --git a/scripts/upload.py b/scripts/upload.py
index aab2f62..22d1f12 100755
--- a/scripts/upload.py
+++ b/scripts/upload.py
@@ -319,6 +319,14 @@
def main(*args):
+ """
+ Process command line arguments and invoke bot.
+
+ If args is an empty list, sys.argv is used.
+
+ @param args: command line arguments
+ @type args: list of unicode
+ """
url = u''
description = []
keepFilename = False
@@ -331,7 +339,7 @@
# process all global bot args
# returns a list of non-global args, i.e. args for upload.py
- for arg in pywikibot.handleArgs(*args):
+ for arg in pywikibot.handle_args(args):
if arg:
if arg.startswith('-keep'):
keepFilename = True
diff --git a/scripts/watchlist.py b/scripts/watchlist.py
index 140b858..2414c82 100755
--- a/scripts/watchlist.py
+++ b/scripts/watchlist.py
@@ -133,13 +133,19 @@
refresh(pywikibot.Site(lang, family))
-def main():
- """ Script entry point. """
- local_args = pywikibot.handleArgs()
+def main(*args):
+ """
+ Process command line arguments and invoke bot.
+
+ If args is an empty list, sys.argv is used.
+
+ @param args: command line arguments
+ @type args: list of unicode
+ """
all = False
new = False
sysop = False
- for arg in local_args:
+ for arg in pywikibot.handle_args(args):
if arg in ('-all', '-update'):
all = True
elif arg == '-new':
@@ -160,7 +166,4 @@
pywikibot.output(pageName, toStdout=True)
if __name__ == "__main__":
- try:
- main()
- finally:
- pywikibot.stopme()
+ main()
diff --git a/scripts/weblinkchecker.py b/scripts/weblinkchecker.py
index 80d7415..062f883 100644
--- a/scripts/weblinkchecker.py
+++ b/scripts/weblinkchecker.py
@@ -801,7 +801,15 @@
return c.check()
-def main():
+def main(*args):
+ """
+ Process command line arguments and invoke bot.
+
+ If args is an empty list, sys.argv is used.
+
+ @param args: command line arguments
+ @type args: list of unicode
+ """
gen = None
xmlFilename = None
# Which namespaces should be processed?
@@ -811,7 +819,7 @@
day = 7
# Process global args and prepare generator args parser
- local_args = pywikibot.handleArgs()
+ local_args = pywikibot.handle_args(args)
genFactory = pagegenerators.GeneratorFactory()
for arg in local_args:
diff --git a/scripts/welcome.py b/scripts/welcome.py
index 3ae71b0..e0805ce 100644
--- a/scripts/welcome.py
+++ b/scripts/welcome.py
@@ -887,8 +887,16 @@
globalvar = Global()
-def main():
- for arg in pywikibot.handleArgs():
+def main(*args):
+ """
+ Process command line arguments and invoke bot.
+
+ If args is an empty list, sys.argv is used.
+
+ @param args: command line arguments
+ @type args: list of unicode
+ """
+ for arg in pywikibot.handle_args(args):
if arg.startswith('-edit'):
if len(arg) == 5:
globalvar.attachEditCount = int(pywikibot.input(
diff --git a/tox.ini b/tox.ini
index f722b37..359851b 100644
--- a/tox.ini
+++ b/tox.ini
@@ -53,6 +53,7 @@
./pywikibot/data/api.py \
./pywikibot/userinterfaces/transliteration.py \
./pywikibot/userinterfaces/terminal_interface.py \
+ ./scripts/category.py \
./scripts/claimit.py \
./scripts/coordinate_import.py \
./scripts/harvest_template.py \
--
To view, visit https://gerrit.wikimedia.org/r/165452
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I828ba3cf155fb6d3e052564d20768fdf9c3acc95
Gerrit-PatchSet: 4
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Owner: John Vandenberg <[email protected]>
Gerrit-Reviewer: John Vandenberg <[email protected]>
Gerrit-Reviewer: Ladsgroup <[email protected]>
Gerrit-Reviewer: Merlijn van Deen <[email protected]>
Gerrit-Reviewer: XZise <[email protected]>
Gerrit-Reviewer: jenkins-bot <>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits