jenkins-bot has submitted this change. ( https://gerrit.wikimedia.org/r/c/pywikibot/core/+/699490 )
Change subject: [IMPR] Improvements for cosmetic_changes.py ......................................................................
[IMPR] Improvements for cosmetic_changes.py
- use AutomaticTWSummaryBot - use BasicBot handle generator option - use current_page.text instead of get() method - use gen_factory.handle_args() method - use pywikibot.bot.suggest_help() result to run the bot
Change-Id: I2e5cfa4d2199447943aa4ff66df369dca52ae0b7 --- M scripts/cosmetic_changes.py 1 file changed, 23 insertions(+), 26 deletions(-)
Approvals: JJMC89: Looks good to me, approved jenkins-bot: Verified
diff --git a/scripts/cosmetic_changes.py b/scripts/cosmetic_changes.py index dfc08e2..daeb1a7 100755 --- a/scripts/cosmetic_changes.py +++ b/scripts/cosmetic_changes.py @@ -37,9 +37,13 @@ # Distributed under the terms of the MIT license. # import pywikibot -from pywikibot import config, i18n, pagegenerators +from pywikibot import config, pagegenerators from pywikibot.backports import Tuple -from pywikibot.bot import ExistingPageBot, NoRedirectPageBot +from pywikibot.bot import ( + AutomaticTWSummaryBot, + ExistingPageBot, + NoRedirectPageBot, +) from pywikibot.cosmetic_changes import CANCEL, CosmeticChangesToolkit
@@ -55,26 +59,28 @@ }
-class CosmeticChangesBot(ExistingPageBot, NoRedirectPageBot): +class CosmeticChangesBot(AutomaticTWSummaryBot, + ExistingPageBot, + NoRedirectPageBot):
"""Cosmetic changes bot."""
- def __init__(self, generator, **kwargs) -> None: + summary_key = 'cosmetic_changes-standalone' + + def __init__(self, **kwargs) -> None: """Initializer.""" self.available_options.update({ 'async': False, - 'summary': 'Robot: Cosmetic changes', + 'summary': '', 'ignore': CANCEL.MATCH, }) super().__init__(**kwargs)
- self.generator = generator - def treat_page(self) -> None: """Treat page with the cosmetic toolkit.""" cc_toolkit = CosmeticChangesToolkit(self.current_page, ignore=self.opt.ignore) - changed_text = cc_toolkit.change(self.current_page.get()) + changed_text = cc_toolkit.change(self.current_page.text) if changed_text is not False: self.put_current(new_text=changed_text, summary=self.opt.summary, @@ -92,8 +98,9 @@ options = {}
# Process global args and prepare generator args parser - local_args = pywikibot.handle_args(args) gen_factory = pagegenerators.GeneratorFactory() + local_args = pywikibot.handle_args(args) + local_args = gen_factory.handle_args(local_args)
for arg in local_args: opt, _, value = arg.partition(':') @@ -107,26 +114,16 @@ options['ignore'] = getattr(CANCEL, value) except AttributeError: raise ValueError('Unknown ignore mode {!r}!'.format(value)) - else: - gen_factory.handle_arg(arg) - - site = pywikibot.Site() - - if not options.get('summary'): - # Load default summary message. - options['summary'] = i18n.twtranslate(site, - 'cosmetic_changes-standalone')
gen = gen_factory.getCombinedGenerator(preload=True) - if gen: - if options.get('always') or config.simulate or pywikibot.input_yn( + if not pywikibot.bot.suggest_help(missing_generator=not gen) \ + and (options.get('always') + or config.simulate + or pywikibot.input_yn( warning + '\nDo you really want to continue?', - default=False, automatic_quit=False): - site.login() - bot = CosmeticChangesBot(gen, **options) - bot.run() - else: - pywikibot.bot.suggest_help(missing_generator=True) + default=False, automatic_quit=False)): + bot = CosmeticChangesBot(generator=gen, **options) + bot.run()
if __name__ == '__main__':
pywikibot-commits@lists.wikimedia.org