jenkins-bot has submitted this change and it was merged.
Change subject: Scripts should login after initialisation ......................................................................
Scripts should login after initialisation
The following scripts unnecessarily login early in their main() block or in the bot __init__, which may cause the bot to sleep, or raise an exception.
Two instances of that, which have resulted in 'red' travis-ci builds are the category and touch scripts:
https://travis-ci.org/wikimedia/pywikibot-core/jobs/32012605 https://travis-ci.org/wikimedia/pywikibot-core/jobs/31955520
Change-Id: I63e1699a4b70dde161c0430beaaa5ed0b44093cb --- M scripts/basic.py M scripts/blockpageschecker.py M scripts/category.py M scripts/category_redirect.py M scripts/clean_sandbox.py M scripts/cosmetic_changes.py M scripts/editarticle.py M scripts/imageuncat.py M scripts/interwiki.py M scripts/redirect.py M scripts/replace.py M scripts/solve_disambiguation.py M scripts/touch.py 13 files changed, 18 insertions(+), 16 deletions(-)
Approvals: Legoktm: Looks good to me, approved jenkins-bot: Verified
diff --git a/scripts/basic.py b/scripts/basic.py index 7a8c6c5..07d2305 100755 --- a/scripts/basic.py +++ b/scripts/basic.py @@ -159,8 +159,6 @@ else: genFactory.handleArg(arg)
- site.login() - if not gen: gen = genFactory.getCombinedGenerator() if gen: diff --git a/scripts/blockpageschecker.py b/scripts/blockpageschecker.py index 770d906..2ffc1e8 100755 --- a/scripts/blockpageschecker.py +++ b/scripts/blockpageschecker.py @@ -250,8 +250,9 @@ pywikibot.output(u"Your project is not supported by this script.\n" u"You have to edit the script and add it!") return + site = pywikibot.Site() - site.login() + if protectedpages: generator = site.protectedpages(namespace=namespace, type=protectType) # Take the right templates to use, the category and the comment diff --git a/scripts/category.py b/scripts/category.py index 2d3152b..38dddc9 100755 --- a/scripts/category.py +++ b/scripts/category.py @@ -1066,8 +1066,6 @@ else: genFactory.handleArg(arg)
- pywikibot.Site().login() - catDB = None bot = None
@@ -1141,6 +1139,8 @@ talkPages=talkPages, recurse=recurse)
if bot: + pywikibot.Site().login() + try: bot.run() except pywikibot.Error: diff --git a/scripts/category_redirect.py b/scripts/category_redirect.py index c04af67..e5a394c 100755 --- a/scripts/category_redirect.py +++ b/scripts/category_redirect.py @@ -36,13 +36,12 @@ def __init__(self): self.cooldown = 7 # days self.site = pywikibot.Site() - self.site.login() self.catprefix = self.site.namespace(14) + ":" self.log_text = [] self.edit_requests = [] self.log_page = pywikibot.Page(self.site, u"User:%(user)s/category redirect log" - % {'user': self.site.user()}) + % {'user': self.site.username()})
# Localization:
@@ -172,6 +171,7 @@ """Run the bot""" global destmap, catlist, catmap
+ # user() invokes login() user = self.site.user() problems = [] newredirs = [] diff --git a/scripts/clean_sandbox.py b/scripts/clean_sandbox.py index 6bfaecc..dbd1e24 100755 --- a/scripts/clean_sandbox.py +++ b/scripts/clean_sandbox.py @@ -158,7 +158,6 @@ self.availableOptions['delay_td'] = datetime.timedelta(minutes=d)
self.site = pywikibot.Site() - self.site.login() if self.getOption('user'): localSandboxTitle = i18n.translate(self.site, user_sandboxTemplate) @@ -178,6 +177,7 @@ sys.exit(0)
def run(self): + self.site.login() while True: wait = False now = time.strftime("%d %b %Y %H:%M:%S (UTC)", time.gmtime()) diff --git a/scripts/cosmetic_changes.py b/scripts/cosmetic_changes.py index 90c0918..6c752cc 100755 --- a/scripts/cosmetic_changes.py +++ b/scripts/cosmetic_changes.py @@ -902,7 +902,6 @@ genFactory.handleArg(arg)
site = pywikibot.Site() - site.login()
if 'comment' not in options or not options['comment']: # Load default summary message. @@ -916,6 +915,7 @@ warning + '\nDo you really want to continue?', ['yes', 'no'], ['y', 'n'], 'n') if answer == 'y': + site.login() preloadingGen = pagegenerators.PreloadingGenerator(gen) bot = CosmeticChangesBot(preloadingGen, **options) bot.run() diff --git a/scripts/editarticle.py b/scripts/editarticle.py index af1cff3..37f830a 100755 --- a/scripts/editarticle.py +++ b/scripts/editarticle.py @@ -36,7 +36,6 @@ self.set_options(*args) self.setpage() self.site = pywikibot.Site() - self.site.login()
def set_options(self, *args): """Parse commandline and set options attribute""" @@ -76,6 +75,7 @@ % fn)
def run(self): + self.site.login() try: old = self.page.get(get_redirect=self.options.edit_redirect) except pywikibot.NoPage: diff --git a/scripts/imageuncat.py b/scripts/imageuncat.py index eecc596..74dc90d 100755 --- a/scripts/imageuncat.py +++ b/scripts/imageuncat.py @@ -1327,7 +1327,6 @@
genFactory = pagegenerators.GeneratorFactory(site)
- site.login() for arg in local_args: if arg.startswith('-yesterday'): generator = uploadedYesterday(site) @@ -1342,6 +1341,7 @@ u'You have to specify the generator you want to use for the program!') else: pregenerator = pagegenerators.PreloadingGenerator(generator) + site.login() for page in pregenerator: pywikibot.output(page.title()) if page.exists() and (page.namespace() == 6) \ diff --git a/scripts/interwiki.py b/scripts/interwiki.py index 595a6d9..6760a6c 100755 --- a/scripts/interwiki.py +++ b/scripts/interwiki.py @@ -2501,7 +2501,6 @@ globalvar.summary += u'; '
site = pywikibot.Site() - site.login() # ensure that we don't try to change main page try: mainpagename = site.mediawiki_message('mainpage') @@ -2552,6 +2551,7 @@ namespace = 0 hintlessPageGen = pagegenerators.CombinedPageGenerator([hintlessPageGen, pagegenerators.AllpagesPageGenerator(nextPage, namespace, includeredirects=False)])
+ site.login() bot = InterwikiBot()
if not hintlessPageGen: diff --git a/scripts/redirect.py b/scripts/redirect.py index 7d681fc..17527aa 100755 --- a/scripts/redirect.py +++ b/scripts/redirect.py @@ -81,7 +81,6 @@ use_move_log=False, use_api=False, start=None, until=None, number=None, step=None): self.site = pywikibot.Site() - self.site.login() self.xmlFilename = xmlFilename self.namespaces = namespaces if use_api and not self.namespaces: @@ -811,6 +810,7 @@ ): pywikibot.showHelp() else: + self.site.login() gen = RedirectGenerator(xmlFilename, namespaces, offset, moved_pages, fullscan, start, until, number, step) bot = RedirectRobot(action, gen, always, number, delete) diff --git a/scripts/replace.py b/scripts/replace.py index 3bd916a..3ddc0ec 100755 --- a/scripts/replace.py +++ b/scripts/replace.py @@ -538,7 +538,7 @@ allowoverlap = True else: commandline_replacements.append(arg) - pywikibot.Site().login() + if (len(commandline_replacements) % 2): raise pywikibot.Error('require even number of replacements.') elif (len(commandline_replacements) == 2 and fix is None): @@ -681,6 +681,7 @@ preloadingGen = pagegenerators.PreloadingGenerator(gen) bot = ReplaceRobot(preloadingGen, replacements, exceptions, acceptall, allowoverlap, recursive, add_cat, sleep, edit_summary) + pywikibot.Site().login() bot.run()
diff --git a/scripts/solve_disambiguation.py b/scripts/solve_disambiguation.py index 09ef8f7..92d9d53 100644 --- a/scripts/solve_disambiguation.py +++ b/scripts/solve_disambiguation.py @@ -1082,7 +1082,6 @@ pageTitle = arg
site = pywikibot.Site() - site.login()
if pageTitle: page = pywikibot.Page(pywikibot.Link(pageTitle, site)) @@ -1092,6 +1091,8 @@ pywikibot.showHelp() return
+ site.login() + bot = DisambiguationRobot(always, alternatives, getAlternatives, dnSkip, generator, primary, main_only, minimum=minimum) diff --git a/scripts/touch.py b/scripts/touch.py index 7c22a86..4caabe1 100755 --- a/scripts/touch.py +++ b/scripts/touch.py @@ -80,11 +80,12 @@ continue if arg.startswith("-"): options[arg[1:].lower()] = True - pywikibot.Site().login() + gen = genFactory.getCombinedGenerator() if gen: preloadingGen = pagegenerators.PreloadingGenerator(gen) bot = TouchBot(preloadingGen, **options) + pywikibot.Site().login() bot.run() else: pywikibot.showHelp()
pywikibot-commits@lists.wikimedia.org