jenkins-bot has submitted this change and it was merged.
Change subject: move main script to main() and remove obsolete pywikibot.stopme(). ......................................................................
move main script to main() and remove obsolete pywikibot.stopme().
In core branch pywikibot.stopme() is called by atexit library. The function is executed upon normal program termination. This patch prohibits executing it twice.
Change-Id: I57289b1ffee97d05709f5c1f961bc39ec98f7d5e --- M scripts/commons_link.py 1 file changed, 44 insertions(+), 42 deletions(-)
Approvals: Merlijn van Deen: Looks good to me, approved jenkins-bot: Verified
diff --git a/scripts/commons_link.py b/scripts/commons_link.py index 5b7f883..797d3ec 100644 --- a/scripts/commons_link.py +++ b/scripts/commons_link.py @@ -27,7 +27,7 @@ """ # # (C) Leonardo Gregianin, 2006 -# (C) Pywikibot team, 2007-2013 +# (C) Pywikibot team, 2007-2014 # # Distributed under the terms of the MIT license. # @@ -159,48 +159,50 @@ except pywikibot.LockedPage: pywikibot.output(u'Page %s is locked?!' % page.title())
-if __name__ == "__main__": + +def main(): singlepage = [] gen = None start = None - try: - action = None - for arg in pywikibot.handleArgs(): - if arg == ('pages'): - action = 'pages' - elif arg == ('categories'): - action = 'categories' - elif arg.startswith('-start:'): - start = pywikibot.Page(pywikibot.getSite(), arg[7:]) - gen = pagegenerators.AllpagesPageGenerator( - start.title(withNamespace=False), - namespace=start.namespace(), - includeredirects=False) - elif arg.startswith('-cat:'): - cat = pywikibot.Category(pywikibot.getSite(), - 'Category:%s' % arg[5:]) - gen = pagegenerators.CategorizedPageGenerator(cat) - elif arg.startswith('-ref:'): - ref = pywikibot.Page(pywikibot.getSite(), arg[5:]) - gen = pagegenerators.ReferringPageGenerator(ref) - elif arg.startswith('-link:'): - link = pywikibot.Page(pywikibot.getSite(), arg[6:]) - gen = pagegenerators.LinkedPageGenerator(link) - elif arg.startswith('-page:'): - singlepage = pywikibot.Page(pywikibot.getSite(), arg[6:]) - gen = iter([singlepage]) - #else: - #bug + action = None + for arg in pywikibot.handleArgs(): + if arg == ('pages'): + action = 'pages' + elif arg == ('categories'): + action = 'categories' + elif arg.startswith('-start:'): + start = pywikibot.Page(pywikibot.getSite(), arg[7:]) + gen = pagegenerators.AllpagesPageGenerator( + start.title(withNamespace=False), + namespace=start.namespace(), + includeredirects=False) + elif arg.startswith('-cat:'): + cat = pywikibot.Category(pywikibot.getSite(), + 'Category:%s' % arg[5:]) + gen = pagegenerators.CategorizedPageGenerator(cat) + elif arg.startswith('-ref:'): + ref = pywikibot.Page(pywikibot.getSite(), arg[5:]) + gen = pagegenerators.ReferringPageGenerator(ref) + elif arg.startswith('-link:'): + link = pywikibot.Page(pywikibot.getSite(), arg[6:]) + gen = pagegenerators.LinkedPageGenerator(link) + elif arg.startswith('-page:'): + singlepage = pywikibot.Page(pywikibot.getSite(), arg[6:]) + gen = iter([singlepage]) + #else: + #bug
- if action == 'pages': - preloadingGen = pagegenerators.PreloadingGenerator(gen) - bot = CommonsLinkBot(preloadingGen, acceptall=False) - bot.pages() - elif action == 'categories': - preloadingGen = pagegenerators.PreloadingGenerator(gen) - bot = CommonsLinkBot(preloadingGen, acceptall=False) - bot.categories() - else: - pywikibot.showHelp(u'commons_link') - finally: - pywikibot.stopme() + if action == 'pages': + preloadingGen = pagegenerators.PreloadingGenerator(gen) + bot = CommonsLinkBot(preloadingGen, acceptall=False) + bot.pages() + elif action == 'categories': + preloadingGen = pagegenerators.PreloadingGenerator(gen) + bot = CommonsLinkBot(preloadingGen, acceptall=False) + bot.categories() + else: + pywikibot.showHelp(u'commons_link') + + +if __name__ == "__main__": + main()
pywikibot-commits@lists.wikimedia.org