jenkins-bot has submitted this change and it was merged. ( https://gerrit.wikimedia.org/r/283410 )
Change subject: [IMPR] Subclass PiperBot from AutomaticTWSummaryBot ......................................................................
[IMPR] Subclass PiperBot from AutomaticTWSummaryBot
- Subclass PiperBot from AutomaticTWSummaryBot - 'always' option is already defined in BaseBot - use local_args to parse local command line args only - simplify arg parsing - update some doc strings
Change-Id: I86cea24b75a3351742724a7eb683ca38fcb11fef --- M scripts/piper.py 1 file changed, 25 insertions(+), 23 deletions(-)
Approvals: Dalba: Looks good to me, approved jenkins-bot: Verified
diff --git a/scripts/piper.py b/scripts/piper.py index f42f917..d15e4c8 100755 --- a/scripts/piper.py +++ b/scripts/piper.py @@ -27,10 +27,9 @@ -filter: Filter the article text through this program, can be given multiple times to filter through multiple programs in the order which they are given - """ # -# (C) Pywikibot team, 2008-2015 +# (C) Pywikibot team, 2008-2017 # # Distributed under the terms of the MIT license. # @@ -45,8 +44,9 @@
import pywikibot
-from pywikibot import i18n, pagegenerators -from pywikibot.bot import MultipleSitesBot, ExistingPageBot, NoRedirectPageBot +from pywikibot import pagegenerators +from pywikibot.bot import (MultipleSitesBot, ExistingPageBot, + NoRedirectPageBot, AutomaticTWSummaryBot)
# This is required for the text that is shown when you run this script # with the parameter -help. @@ -55,23 +55,30 @@ }
-class PiperBot(MultipleSitesBot, ExistingPageBot, NoRedirectPageBot): +class PiperBot(MultipleSitesBot, ExistingPageBot, NoRedirectPageBot, + AutomaticTWSummaryBot):
"""Bot for munging text using external filtering programs.""" + + summary_key = 'piper-edit-summary'
def __init__(self, generator, **kwargs): """ Constructor.
@param generator: The page generator that determines on which pages - to work on. + to work on. + @type generator: generator """ self.availableOptions.update({ - 'always': False, 'filters': [], - 'comment': None, }) super(PiperBot, self).__init__(generator=generator, **kwargs) + + @property + def summary_parameters(self): + """Return the filter parameter.""" + return {'filters': ', '.join(self.getOption('filters'))}
def pipe(self, program, text): """Pipe a given text through a given program. @@ -97,7 +104,7 @@ return unicode_text
def treat_page(self): - """Load the given page, does some changes, and saves it.""" + """Load the given page, do some changes, and save it.""" # Load the page text = self.current_page.text
@@ -106,27 +113,27 @@ text = self.pipe(program, text)
# only save if something was changed - self.put_current(text, summary=self.getOption('comment')) + self.put_current(text)
def main(*args): """Create and run a PiperBot instance from the given command arguments.""" + local_args = pywikibot.handle_args(args) + # This factory is responsible for processing command line arguments # that are also used by other scripts and that determine on which pages # to work on. genFactory = pagegenerators.GeneratorFactory() - # The generator gives the pages that should be worked upon. - gen = None # The program to pipe stuff through filters = [] options = {}
# Parse command line arguments - for arg in pywikibot.handle_args(args): - if arg.startswith("-filter:"): - prog = arg[8:] - filters.append(prog) - elif arg.startswith("-always"): + for arg in local_args: + option, sep, value = arg.partition(':') + if option == '-filter': + filters.append(value) + elif option == '-always': options['always'] = True else: # check if a standard argument like @@ -134,13 +141,8 @@ genFactory.handleArg(arg)
options['filters'] = filters - s = ', '.join(options['filters']) - options['comment'] = i18n.twtranslate(pywikibot.Site().lang, - 'piper-edit-summary', - {'filters': s})
- if not gen: - gen = genFactory.getCombinedGenerator() + gen = genFactory.getCombinedGenerator() if gen: # The preloading generator is responsible for downloading multiple # pages from the wiki simultaneously.
pywikibot-commits@lists.wikimedia.org