John Vandenberg has uploaded a new change for review. https://gerrit.wikimedia.org/r/165452
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') Always process global arguments before local arguments, fixing bugs regarding order of arguments. Also several docstring fixes. 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, 613 insertions(+), 128 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/pywikibot/core refs/changes/52/165452/1 diff --git a/scripts/add_text.py b/scripts/add_text.py index 1d104e1..252e6ab 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.handleArgs(*args) genFactory = pagegenerators.GeneratorFactory() # Loading the arguments diff --git a/scripts/archivebot.py b/scripts/archivebot.py index 015f924..90c617e 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,8 @@ if arg.startswith(name): yield arg[len(name) + 1:] - for arg in pywikibot.handleArgs(): + local_args = pywikibot.handleArgs(*args) + for arg in local_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..245000d 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.handleArgs(*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..aa6f6b8 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.handleArgs(*args) genFactory = pagegenerators.GeneratorFactory() # Process local args diff --git a/scripts/blockreview.py b/scripts/blockreview.py index f184f57..46344f9 100644 --- a/scripts/blockreview.py +++ b/scripts/blockreview.py @@ -303,11 +303,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 + """ show = False # Parse command line arguments - for arg in pywikibot.handleArgs(): + local_args = pywikibot.handleArgs(*args) + if local_args: show = True if not show: diff --git a/scripts/capitalize_redirects.py b/scripts/capitalize_redirects.py index 0c4c7a9..c5f5676 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.handleArgs(*args) genFactory = pagegenerators.GeneratorFactory() for arg in local_args: diff --git a/scripts/catall.py b/scripts/catall.py index 9c176a9..dd9b4df 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.handleArgs(*args) for arg in local_args: if arg == '-onlynew': diff --git a/scripts/category.py b/scripts/category.py index 12beae3..452be3b 100755 --- a/scripts/category.py +++ b/scripts/category.py @@ -1072,6 +1072,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 diff --git a/scripts/category_redirect.py b/scripts/category_redirect.py index b2123b2..1cb5acb 100755 --- a/scripts/category_redirect.py +++ b/scripts/category_redirect.py @@ -417,6 +417,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 + """ a = pywikibot.handleArgs(*args) if len(a) == 1: raise RuntimeError('Unrecognized argument "%s"' % a[0]) diff --git a/scripts/cfd.py b/scripts/cfd.py index ab2b0e9..90da9df 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.handleArgs(*args) page = pywikibot.Page(pywikibot.Site(), cfdPage) diff --git a/scripts/checkimages.py b/scripts/checkimages.py index 980f3ce..b5f616d 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,8 @@ generator = None # Here below there are the parameters. - for arg in pywikibot.handleArgs(): + local_args = pywikibot.handleArgs(*args) + for arg in local_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..9e31b70 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.handleArgs(*args) gen = pagegenerators.GeneratorFactory() for arg in local_args: diff --git a/scripts/clean_sandbox.py b/scripts/clean_sandbox.py index 052ec14..47a5edb 100755 --- a/scripts/clean_sandbox.py +++ b/scripts/clean_sandbox.py @@ -272,9 +272,18 @@ 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(): + local_args = pywikibot.handleArgs(*args) + for arg in local_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..8ba3204 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.handleArgs(*args) genFactory = pagegenerators.GeneratorFactory() for arg in local_args: diff --git a/scripts/commonscat.py b/scripts/commonscat.py index 5029830..96dedfb 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.handleArgs(*args) genFactory = pagegenerators.GeneratorFactory() for arg in local_args: diff --git a/scripts/coordinate_import.py b/scripts/coordinate_import.py index 71cef9c..d031c51 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.handleArgs(*args) gen = pagegenerators.GeneratorFactory() for arg in local_args: diff --git a/scripts/cosmetic_changes.py b/scripts/cosmetic_changes.py index e758452..a79da87 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.handleArgs(*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..df750a8 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.handleArgs(*args) genFactory = pagegenerators.GeneratorFactory() for arg in local_args: diff --git a/scripts/delete.py b/scripts/delete.py index 2efe8e0..f686281 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.handleArgs(*args) genFactory = pagegenerators.GeneratorFactory() mysite = pywikibot.Site() diff --git a/scripts/disambredir.py b/scripts/disambredir.py index 4cbc419..de464c4 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.handleArgs(*args) generator = None start = local_args[0] if local_args else '!' diff --git a/scripts/editarticle.py b/scripts/editarticle.py index 74af631..fc111c6 100755 --- a/scripts/editarticle.py +++ b/scripts/editarticle.py @@ -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 98cb0a7..139543c 100644 --- a/scripts/featured.py +++ b/scripts/featured.py @@ -599,8 +599,17 @@ 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(): + local_args = pywikibot.handleArgs(*args) + for arg in local_args: if arg.startswith('-fromlang:'): options[arg[1:9]] = arg[10:].split(",") elif arg.startswith('-after:'): @@ -618,7 +627,4 @@ if __name__ == "__main__": - try: - main() - finally: - pywikibot.stopme() + main() diff --git a/scripts/fixing_redirects.py b/scripts/fixing_redirects.py index 3e13a6e..cede70d 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.handleArgs(*args) genFactory = pagegenerators.GeneratorFactory() for arg in local_args: diff --git a/scripts/flickrripper.py b/scripts/flickrripper.py index 46d3475..c093f1e 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') @@ -565,9 +573,10 @@ else: reviewer = u'' + local_args = pywikibot.handleArgs(*args) # Should be renamed to overrideLicense or something like that override = u'' - for arg in pywikibot.handleArgs(): + for arg in local_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..1d45947 100644 --- a/scripts/freebasemappingupload.py +++ b/scripts/freebasemappingupload.py @@ -96,9 +96,18 @@ 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(): + local_args = pywikibot.handleArgs(*args) + for arg in local_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..10d5efb 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.handleArgs(*args) gen = pg.GeneratorFactory() for arg in local_args: diff --git a/scripts/illustrate_wikidata.py b/scripts/illustrate_wikidata.py index 0a4dc1c..6251836 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.handleArgs(*args) gen = pg.GeneratorFactory() wdproperty = u'P18' diff --git a/scripts/image.py b/scripts/image.py index 1bcb42b..0fb191d 100644 --- a/scripts/image.py +++ b/scripts/image.py @@ -169,12 +169,21 @@ 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(): + local_args = pywikibot.handleArgs(*args) + for arg in local_args: if arg == '-always': options['always'] = True elif arg == '-loose': diff --git a/scripts/imagerecat.py b/scripts/imagerecat.py index 295bb7f..a08ab73 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.handleArgs(*args) genFactory = pagegenerators.GeneratorFactory() global search_wikis diff --git a/scripts/imagetransfer.py b/scripts/imagetransfer.py index f26e254..84eea97 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.handleArgs(*args) for arg in local_args: if arg == '-interwiki': diff --git a/scripts/imageuncat.py b/scripts/imageuncat.py index 0bcb3d9..e055f5b 100755 --- a/scripts/imageuncat.py +++ b/scripts/imageuncat.py @@ -1315,9 +1315,14 @@ 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) diff --git a/scripts/interwiki.py b/scripts/interwiki.py index ae17496..d15033b 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.handleArgs(*args) genFactory = pagegenerators.GeneratorFactory() for arg in local_args: diff --git a/scripts/isbn.py b/scripts/isbn.py index ac67dac..d759003 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.handleArgs(*args) genFactory = pagegenerators.GeneratorFactory() for arg in local_args: diff --git a/scripts/listpages.py b/scripts/listpages.py index e17c686..1eaac55 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' diff --git a/scripts/login.py b/scripts/login.py index c4ad6c3..9dbde04 100755 --- a/scripts/login.py +++ b/scripts/login.py @@ -62,11 +62,20 @@ 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): + local_args = pywikibot.handleArgs(*args) + for arg in local_args: if arg.startswith("-pass"): if len(arg) == 5: password = pywikibot.input(u'Password for all accounts (no characters will be shown):', @@ -112,5 +121,7 @@ except NoSuchSite: 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..a33fbe7 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.handleArgs(*args) genFactory = pagegenerators.GeneratorFactory() site = pywikibot.Site() diff --git a/scripts/misspelling.py b/scripts/misspelling.py index ec9644b..1dbe005 100644 --- a/scripts/misspelling.py +++ b/scripts/misspelling.py @@ -127,14 +127,23 @@ {'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(): + local_args = pywikibot.handleArgs(*args) + for arg in local_args: if arg.startswith('-always:'): always = arg[8:] elif arg.startswith('-start'): diff --git a/scripts/movepages.py b/scripts/movepages.py index 5af0ac3..90ae739 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.handleArgs(*args) genFactory = pagegenerators.GeneratorFactory() for arg in local_args: diff --git a/scripts/newitem.py b/scripts/newitem.py index b6ea11f..0b9ce27 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.handleArgs(*args) gen = pagegenerators.GeneratorFactory() options = {} diff --git a/scripts/noreferences.py b/scripts/noreferences.py index 8fece93..e923314 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.handleArgs(*args) genFactory = pagegenerators.GeneratorFactory() for arg in local_args: diff --git a/scripts/nowcommons.py b/scripts/nowcommons.py index ef6d436..939f481 100644 --- a/scripts/nowcommons.py +++ b/scripts/nowcommons.py @@ -429,10 +429,19 @@ 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(): + local_args = pywikibot.handleArgs(*args) + for arg in local_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 98df996..2d268bc 100644 --- a/scripts/pagefromfile.py +++ b/scripts/pagefromfile.py @@ -235,7 +235,15 @@ return location.end(), title, contents -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 + """ # 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. @@ -250,7 +258,8 @@ include = False notitle = False - for arg in pywikibot.handleArgs(): + local_args = pywikibot.handleArgs(*args) + for arg in local_args: if arg.startswith("-start:"): pageStartMarker = arg[7:] elif arg.startswith("-end:"): diff --git a/scripts/protect.py b/scripts/protect.py index 7a20ed1..717a9da 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 diff --git a/scripts/redirect.py b/scripts/redirect.py index d6eb487..8790a68 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,8 @@ until = '' number = None step = None - for arg in pywikibot.handleArgs(*args): + local_args = pywikibot.handleArgs(*args) + for arg in local_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 477b668..8c1cc84 100644 --- a/scripts/reflinks.py +++ b/scripts/reflinks.py @@ -781,14 +781,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.handleArgs(*args) genFactory = pagegenerators.GeneratorFactory() for arg in local_args: diff --git a/scripts/replace.py b/scripts/replace.py index 5c9e750..f0ba76e 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 diff --git a/scripts/revertbot.py b/scripts/revertbot.py index 1b6d54e..931646b 100644 --- a/scripts/revertbot.py +++ b/scripts/revertbot.py @@ -132,10 +132,19 @@ 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(): + local_args = pywikibot.handleArgs(*args) + for arg in local_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..a4e7c7d 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.handleArgs(*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..bc59411 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.handleArgs(*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..e3070d7 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 diff --git a/scripts/spamremove.py b/scripts/spamremove.py index 57c1b53..780f923 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.handleArgs(*args): if arg == "-always": always = True elif arg.startswith('-namespace:'): diff --git a/scripts/template.py b/scripts/template.py index 48763cc..33728d3 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 = {} diff --git a/scripts/templatecount.py b/scripts/templatecount.py index cd2aa01..3664fcc 100644 --- a/scripts/templatecount.py +++ b/scripts/templatecount.py @@ -107,12 +107,21 @@ 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(): + local_args = pywikibot.handleArgs(*args) + for arg in local_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..e309565 100755 --- a/scripts/touch.py +++ b/scripts/touch.py @@ -68,6 +68,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 + """ gen = None options = {} diff --git a/scripts/transferbot.py b/scripts/transferbot.py index 12590c1..ab735c5 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.handleArgs(*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..1a8161b 100755 --- a/scripts/unlink.py +++ b/scripts/unlink.py @@ -164,13 +164,22 @@ 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(): + local_args = pywikibot.handleArgs(*args) + for arg in local_args: if arg.startswith('-namespace:'): if 'namespaces' not in options: options['namespaces'] = [] diff --git a/scripts/unusedfiles.py b/scripts/unusedfiles.py index 3125e95..7dcb5a2 100644 --- a/scripts/unusedfiles.py +++ b/scripts/unusedfiles.py @@ -103,10 +103,19 @@ 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(): + local_args = pywikibot.handleArgs(*args) + for arg in local_args: if arg == '-always': options['always'] = True diff --git a/scripts/upload.py b/scripts/upload.py index aab2f62..4c45a80 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,9 @@ # process all global bot args # returns a list of non-global args, i.e. args for upload.py - for arg in pywikibot.handleArgs(*args): + local_args = pywikibot.handleArgs(*args) + + for arg in local_args: if arg: if arg.startswith('-keep'): keepFilename = True diff --git a/scripts/watchlist.py b/scripts/watchlist.py index fcb2200..37728fd 100755 --- a/scripts/watchlist.py +++ b/scripts/watchlist.py @@ -133,9 +133,16 @@ 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 + """ + local_args = pywikibot.handleArgs(*args) all = False new = False sysop = False @@ -160,7 +167,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 2a4d991..0bc4fde 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.handleArgs(*args) genFactory = pagegenerators.GeneratorFactory() for arg in local_args: diff --git a/scripts/welcome.py b/scripts/welcome.py index c603eba..e8d2c2a 100644 --- a/scripts/welcome.py +++ b/scripts/welcome.py @@ -887,8 +887,17 @@ 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 + """ + local_args = pywikibot.handleArgs(*args) + for arg in local_args: if arg.startswith('-edit'): if len(arg) == 5: globalvar.attachEditCount = int(pywikibot.input( diff --git a/tox.ini b/tox.ini index 2049adb..804c874 100644 --- a/tox.ini +++ b/tox.ini @@ -48,6 +48,7 @@ ./pywikibot/data/__init__.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: newchange Gerrit-Change-Id: I828ba3cf155fb6d3e052564d20768fdf9c3acc95 Gerrit-PatchSet: 1 Gerrit-Project: pywikibot/core Gerrit-Branch: master Gerrit-Owner: John Vandenberg <jay...@gmail.com> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits