jenkins-bot has submitted this change and it was merged.
Change subject: [IMPROV] TouchBot: Use new functionality
......................................................................
[IMPROV] TouchBot: Use new functionality
The TouchBot doesn't need to overwrite run() and can let the underlying
Bot class handle it. This also separates touching and purging into two
separate bots.
Change-Id: I4151d3bd298eb87933a22a9d3f72343c5f5c0e46
---
M scripts/touch.py
M tox.ini
2 files changed, 41 insertions(+), 34 deletions(-)
Approvals:
John Vandenberg: Looks good to me, approved
jenkins-bot: Verified
diff --git a/scripts/touch.py b/scripts/touch.py
index 42d112e..359d320 100755
--- a/scripts/touch.py
+++ b/scripts/touch.py
@@ -13,10 +13,10 @@
-purge Do not touch but purge the page
-redir specifies that the bot should work on redirect pages;
- otherwise, they will be skipped.
+ otherwise, they will be skipped. Cannot be used with -purge.
"""
#
-# (C) Pywikibot team, 2009-2014
+# (C) Pywikibot team, 2009-2015
#
# Distributed under the terms of the MIT license.
#
@@ -36,39 +36,44 @@
"""Page touch bot."""
def __init__(self, generator, **kwargs):
+ """Initialize a TouchBot instance with the options and
generator."""
self.availableOptions.update({
'redir': False, # include redirect pages
- 'purge': False, # purge only
})
- super(TouchBot, self).__init__(**kwargs)
- self.generator = generator
+ super(TouchBot, self).__init__(generator=generator, **kwargs)
- def run(self):
- for page in self.generator:
- if self.getOption('purge'):
- pywikibot.output(u'Page %s%s purged'
- % (page.title(asLink=True),
- "" if page.purge() else " not"))
- continue
- try:
- # get the page, and save it using the unmodified text.
- # whether or not getting a redirect throws an exception
- # depends on the variable self.touch_redirects.
- page.get(get_redirect=self.getOption('redir'))
- page.save("Pywikibot touch script")
- except pywikibot.NoPage:
- pywikibot.error(u"Page %s does not exist."
- % page.title(asLink=True))
- except pywikibot.IsRedirectPage:
- pywikibot.warning(u"Page %s is a redirect; skipping."
- % page.title(asLink=True))
- except pywikibot.LockedPage:
- pywikibot.error(u"Page %s is locked."
- % page.title(asLink=True))
- except pywikibot.PageNotSaved:
- pywikibot.error(u"Page %s not saved."
- % page.title(asLink=True))
+ def treat(self, page):
+ """Touch the given page."""
+ try:
+ # get the page, and save it using the unmodified text.
+ # whether or not getting a redirect throws an exception
+ # depends on the variable self.touch_redirects.
+ page.get(get_redirect=self.getOption('redir'))
+ page.save("Pywikibot touch script")
+ except pywikibot.NoPage:
+ pywikibot.error(u"Page %s does not exist."
+ % page.title(asLink=True))
+ except pywikibot.IsRedirectPage:
+ pywikibot.warning(u"Page %s is a redirect; skipping."
+ % page.title(asLink=True))
+ except pywikibot.LockedPage:
+ pywikibot.error(u"Page %s is locked."
+ % page.title(asLink=True))
+ except pywikibot.PageNotSaved:
+ pywikibot.error(u"Page %s not saved."
+ % page.title(asLink=True))
+
+
+class PurgeBot(pywikibot.Bot):
+
+ """Purge each page on the generator."""
+
+ def treat(self, page):
+ """Purge the given page."""
+ pywikibot.output(u'Page %s%s purged'
+ % (page.title(asLink=True),
+ "" if page.purge() else " not"))
def main(*args):
@@ -87,16 +92,17 @@
local_args = pywikibot.handle_args(args)
genFactory = pagegenerators.GeneratorFactory()
+ bot_class = TouchBot
for arg in local_args:
- if genFactory.handleArg(arg):
- continue
- if arg.startswith("-"):
+ if arg == '-purge':
+ bot_class = PurgeBot
+ elif not genFactory.handleArg(arg) and arg.startswith("-"):
options[arg[1:].lower()] = True
gen = genFactory.getCombinedGenerator()
if gen:
preloadingGen = pagegenerators.PreloadingGenerator(gen)
- bot = TouchBot(preloadingGen, **options)
+ bot = bot_class(generator=preloadingGen, **options)
pywikibot.Site().login()
bot.run()
else:
diff --git a/tox.ini b/tox.ini
index 412f9a0..9ffefe0 100644
--- a/tox.ini
+++ b/tox.ini
@@ -89,6 +89,7 @@
scripts/spamremove.py \
scripts/states_redirect.py \
scripts/template.py \
+ scripts/touch.py \
scripts/transferbot.py \
scripts/unusedfiles.py \
scripts/upload.py \
--
To view, visit
https://gerrit.wikimedia.org/r/210016
To unsubscribe, visit
https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I4151d3bd298eb87933a22a9d3f72343c5f5c0e46
Gerrit-PatchSet: 1
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Owner: XZise <CommodoreFabianus(a)gmx.de>
Gerrit-Reviewer: John Vandenberg <jayvdb(a)gmail.com>
Gerrit-Reviewer: Ladsgroup <ladsgroup(a)gmail.com>
Gerrit-Reviewer: Merlijn van Deen <valhallasw(a)arctus.nl>
Gerrit-Reviewer: XZise <CommodoreFabianus(a)gmx.de>
Gerrit-Reviewer: jenkins-bot <>