jenkins-bot has submitted this change and it was merged.
Change subject: Enable just purging a page instead of touch it. ......................................................................
Enable just purging a page instead of touch it.
- new option -purge to purch the server's cache - derive the bot from pywikibot.Bot class - pyflake: remove obsolete "import config"
Change-Id: I5211f57fd521671bd0ec9752ec44e4a560dd91d2 --- M scripts/touch.py 1 file changed, 23 insertions(+), 10 deletions(-)
Approvals: Merlijn van Deen: Looks good to me, approved jenkins-bot: Verified
diff --git a/scripts/touch.py b/scripts/touch.py index 86571b8..228703e 100755 --- a/scripts/touch.py +++ b/scripts/touch.py @@ -10,7 +10,9 @@
¶ms;
--redir specifies that the robot should touch redirect pages; +-purge Do not touch but purge the page + +-redir specifies that the robot should work on redirect pages; otherwise, they will be skipped.
All other parameters will be regarded as a page title; in this case, the bot @@ -25,23 +27,34 @@ #
import pywikibot -from pywikibot import pagegenerators, config +from pywikibot import pagegenerators
docuReplacements = {'¶ms;': pagegenerators.parameterHelp}
-class TouchBot: - def __init__(self, generator, touch_redirects): +class TouchBot(pywikibot.Bot): + + def __init__(self, generator, **kwargs): + self.availableOptions.update({ + 'redir': False, # include redirect pages + 'purge': False, # purge only + }) + + super(TouchBot, self).__init__(**kwargs) self.generator = generator - self.touch_redirects = touch_redirects
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.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." @@ -60,7 +73,7 @@ def main(*args): gen = None genFactory = pagegenerators.GeneratorFactory() - redirs = False + options = {} # If the user chooses to work on a single page, this temporary array is # used to read the words from the page title. The words will later be # joined with spaces to retrieve the full title. @@ -68,8 +81,8 @@ for arg in pywikibot.handleArgs(*args): if genFactory.handleArg(arg): continue - if arg == '-redir': - redirs = True + if arg.startswith("-"): + options[arg[1:].lower()] = True else: pageTitle.append(arg) pywikibot.Site().login() @@ -83,7 +96,7 @@ pywikibot.showHelp() return preloadingGen = pagegenerators.PreloadingGenerator(gen) - bot = TouchBot(preloadingGen, redirs) + bot = TouchBot(preloadingGen, **options) bot.run()
pywikibot-commits@lists.wikimedia.org