jenkins-bot has submitted this change. ( https://gerrit.wikimedia.org/r/c/pywikibot/core/+/636009 )
Change subject: [IMPR] Use new opt options for several script ......................................................................
[IMPR] Use new opt options for several script
Change-Id: Ida35d03e44f59bd6fc3b42e6d69ead0914fc64da --- M scripts/category_redirect.py M scripts/ndashredir.py M scripts/revertbot.py 3 files changed, 16 insertions(+), 23 deletions(-)
Approvals: Xqt: Looks good to me, approved jenkins-bot: Verified
diff --git a/scripts/category_redirect.py b/scripts/category_redirect.py index 36c90cd..767c5eb 100755 --- a/scripts/category_redirect.py +++ b/scripts/category_redirect.py @@ -49,12 +49,11 @@
def __init__(self, **kwargs): """Initializer.""" - self.availableOptions.update({ + self.available_options.update({ 'tiny': False, # use Non-empty category redirects only 'delay': 7, # cool down delay in days }) super().__init__(**kwargs) - self.cooldown = self.getOption('delay') self.catprefix = self.site.namespace(14) + ':' self.log_text = [] self.edit_requests = [] @@ -110,7 +109,7 @@
def get_cat(self): """Specify the category page.""" - if self.getOption('tiny'): + if self.opt.tiny: self.cat = self.site.page_from_repository( self.tiny_cat_redirect_cat) else: @@ -177,7 +176,7 @@ def readyToEdit(self, cat): """Return True if cat not edited during cooldown period, else False.""" today = pywikibot.Timestamp.now() - deadline = today + timedelta(days=-self.cooldown) + deadline = today + timedelta(days=-self.opt.delay) if cat.editTime() is None: raise RuntimeError return (deadline > cat.editTime()) diff --git a/scripts/ndashredir.py b/scripts/ndashredir.py index d5620ac..d85e1a5 100644 --- a/scripts/ndashredir.py +++ b/scripts/ndashredir.py @@ -26,12 +26,10 @@ ¶ms; """ # -# (C) Pywikibot team, 2012-2019 +# (C) Pywikibot team, 2012-2020 # # Distributed under the terms of the MIT license. # -from __future__ import absolute_import, division, unicode_literals - import pywikibot from pywikibot import i18n, pagegenerators
@@ -62,13 +60,13 @@ @type generator: generator """ # -always option is predefined by BaseBot class - self.availableOptions.update({ + self.available_options.update({ 'summary': None, # custom bot summary 'reversed': False, # switch bot behavior })
# call initializer of the super class - super(DashRedirectBot, self).__init__(site=True, **kwargs) + super().__init__(site=True, **kwargs)
# assign the generator to the bot self.generator = generator @@ -80,7 +78,7 @@ site = self.current_page.site
# create redirect title - if not self.getOption('reversed'): + if not self.opt.reversed: redir = pywikibot.Page(site, origin.replace('–', '-') .replace('—', '-')) else: @@ -91,7 +89,7 @@ pywikibot.output('No need to process {0}, skipping...' .format(redir.title())) # suggest -reversed parameter - if '-' in origin and not self.getOption('reversed'): + if '-' in origin and not self.opt.reversed: pywikibot.output('Consider using -reversed parameter ' 'for this particular page') else: @@ -108,12 +106,8 @@ redir.title())): # If summary option is None, it takes the default # i18n summary from i18n subdirectory with summary key. - if self.getOption('summary'): - summary = self.getOption('summary') - else: - summary = i18n.twtranslate(site, - 'ndashredir-create', - {'title': origin}) + summary = self.opt.summary or i18n.twtranslate( + site, 'ndashredir-create', {'title': origin}) redir.set_redirect_target(self.current_page, create=True, summary=summary)
diff --git a/scripts/revertbot.py b/scripts/revertbot.py index 7c3446d..b5dabce 100755 --- a/scripts/revertbot.py +++ b/scripts/revertbot.py @@ -58,7 +58,7 @@ Subclass this bot and override callback to get it to do something useful. """
- availableOptions = { + available_options = { 'comment': '', 'rollback': False, 'limit': 500 @@ -81,7 +81,7 @@ if callback is None: callback = self.callback
- for item in self.get_contributions(total=self.getOption('limit')): + for item in self.get_contributions(total=self.opt.limit): if callback(item): result = self.revert(item) if result: @@ -109,15 +109,15 @@ {'revid': rev.revid, 'author': rev.user, 'timestamp': rev.timestamp}) - additional_comment = self.getOption('comment') - if additional_comment: - comment += ': ' + additional_comment + + if self.opt.comment: + comment += ': ' + self.opt.comment
pywikibot.output(color_format( '\n\n>>> {lightpurple}{0}{default} <<<', page.title(as_link=True, force_interwiki=True, textlink=True)))
- if not self.getOption('rollback'): + if not self.opt.rollback: old = page.text page.text = page.getOldVersion(rev.revid) pywikibot.showDiff(old, page.text)
pywikibot-commits@lists.wikimedia.org