jenkins-bot has submitted this change and it was merged. ( https://gerrit.wikimedia.org/r/276426 )
Change subject: [IMPR] Stopme is done at exit time by default ......................................................................
[IMPR] Stopme is done at exit time by default
- stopme() is registered to be executed at exit time - remove stopme() from scripts
imageharvest.py: - rename main() to run_bot and use main() as usual - use fileformat as global constant - use shown and mysite as globals
standardize_interwiki.py: - use main() method as usual - remove unused parameters - remove doubled assignment to start variable
Change-Id: Ice68e65510cc29e797830a1b5cdbf957df29bb40 --- M scripts/imageharvest.py M scripts/standardize_interwiki.py 2 files changed, 29 insertions(+), 29 deletions(-)
Approvals: Merlijn van Deen: Looks good to me, approved jenkins-bot: Verified
diff --git a/scripts/imageharvest.py b/scripts/imageharvest.py index 300676d..34b5a8e 100644 --- a/scripts/imageharvest.py +++ b/scripts/imageharvest.py @@ -42,6 +42,8 @@ else: from urllib import URLopener
+fileformats = ('jpg', 'jpeg', 'png', 'gif', 'svg', 'ogg') +
def get_imagelinks(url): """Given a URL, get all images linked to by the page at that URL.""" @@ -66,7 +68,7 @@ return links
-def main(give_url, image_url, desc): +def run_bot(give_url, image_url, desc): """Run the bot.""" url = give_url image_url = '' @@ -128,7 +130,10 @@ break
-try: +def main(*args): + """Process command line arguments and invoke bot.""" + global shown + global mysite url = u'' image_url = False shown = False @@ -147,8 +152,9 @@ desc += [arg] desc = ' '.join(desc)
- fileformats = ('jpg', 'jpeg', 'png', 'gif', 'svg', 'ogg') mysite = pywikibot.Site() - main(url, image_url, desc) -finally: - pywikibot.stopme() + run_bot(url, image_url, desc) + + +if __name__ == '__main__': + main() diff --git a/scripts/standardize_interwiki.py b/scripts/standardize_interwiki.py index 55c2b14..c1b1b81 100644 --- a/scripts/standardize_interwiki.py +++ b/scripts/standardize_interwiki.py @@ -9,7 +9,7 @@ """ # # (C) Rob W.W. Hooft, 2003 -# (C) Pywikibot team, 2003-2015 +# (C) Pywikibot team, 2003-2017 # # Distributed under the terms of the MIT license. # @@ -41,27 +41,19 @@ }
-# Some parameters -options = [] -start = [] -filelist = [] -hints = {} -debug = 0 -start = '!' -nothing = False +def main(*args): + """Process command line arguments and run the script.""" + start = '!'
-# Load the default parameters and start -for arg in pywikibot.handle_args(): - if arg.startswith('-start'): - if len(arg) == 6: - start = pywikibot.input(u'From what page do you want to start?') - else: - start = arg[7:] -site = pywikibot.Site() -comm = pywikibot.translate(site, comment) - -# What follows is the main part of the code. -try: + # Load the default parameters and start + for arg in pywikibot.handle_args(): + if arg.startswith('-start'): + if len(arg) == 6: + start = pywikibot.input(u'From what page do you want to start?') + else: + start = arg[7:] + site = pywikibot.Site() + comm = pywikibot.translate(site, comment) for pl in site.allpages(start): plname = pl.title() pywikibot.output(u'\nLoading %s...' % plname) @@ -90,5 +82,7 @@ else: pywikibot.output(u'No interwiki found.') continue -finally: - pywikibot.stopme() + + +if __name__ == '__main__': + main()
pywikibot-commits@lists.wikimedia.org