jenkins-bot has submitted this change. ( https://gerrit.wikimedia.org/r/c/pywikibot/core/+/637837 )
Change subject: [IMPR] Rewrite scripts using new option handler ......................................................................
[IMPR] Rewrite scripts using new option handler
Bug: T264721 Change-Id: Ia500074cd8cbf40e7047ea7da5efe2062d9e8bb6 --- M scripts/spamremove.py M scripts/surnames_redirects.py M scripts/table2wiki.py M scripts/template.py M scripts/touch.py M scripts/unlink.py M scripts/unusedfiles.py 7 files changed, 18 insertions(+), 18 deletions(-)
Approvals: Xqt: Looks good to me, approved jenkins-bot: Verified
diff --git a/scripts/spamremove.py b/scripts/spamremove.py index 47a11cd..ec67bad 100755 --- a/scripts/spamremove.py +++ b/scripts/spamremove.py @@ -66,7 +66,7 @@
def __init__(self, generator, spam_external_url, **kwargs): """Initializer.""" - self.availableOptions.update({ + self.available_options.update({ 'summary': None, }) super(SpamRemoveBot, self).__init__(**kwargs) @@ -99,7 +99,7 @@ if lastok is None: pywikibot.output(line) lastok = line - if self.getOption('always'): + if self.opt.always: answer = 'y' else: answer = pywikibot.input_choice( @@ -115,7 +115,7 @@ else: newtext = '\n'.join(newpage) if newtext != text: - self.put_current(newtext, summary=self.getOption('summary')) + self.put_current(newtext, summary=self.opt.summary)
def main(*args): diff --git a/scripts/surnames_redirects.py b/scripts/surnames_redirects.py index 3a422c6..e14ba51 100755 --- a/scripts/surnames_redirects.py +++ b/scripts/surnames_redirects.py @@ -46,7 +46,7 @@ @kwarg surnames-last: Redirect "Surnames, Given Names" to "Given Names Surnames". """ - self.availableOptions.update({ + self.available_options.update({ 'surnames_last': False, })
@@ -63,7 +63,7 @@ site = self.current_page.site
possible_names = [] - if self.getOption('surnames_last'): + if self.opt.surnames_last: name_parts = name.split(', ') if len(name_parts) == 2 and len(name.split(' ')) <= 3: possible_names.append('{1} {0}'.format(*name_parts)) diff --git a/scripts/table2wiki.py b/scripts/table2wiki.py index 925daa4..0e87952 100644 --- a/scripts/table2wiki.py +++ b/scripts/table2wiki.py @@ -87,7 +87,7 @@
def __init__(self, **kwargs): """Initializer.""" - self.availableOptions.update({ + self.available_options.update({ 'quiet': False, # quiet mode, less output 'skipwarning': False # on warning skip that page }) @@ -478,12 +478,12 @@ return
if warnings: - if self.getOption('always') and self.getOption('skipwarning'): + if self.opt.always and self.opt.skipwarning: pywikibot.output( 'There were {0} replacements that might lead to bad ' 'output. Skipping.'.format(warnings)) return - if not self.getOption('always'): + if not self.opt.always: pywikibot.output( 'There were {0} replacements that might lead to bad ' 'output.'.format(warnings)) @@ -501,8 +501,8 @@ {'count': warnings} ) self.put_current(new_text, summary=edit_summary, - show_diff=not (self.getOption('quiet') - and self.getOption('always'))) + show_diff=not (self.opt.quiet + and self.opt.always))
_marked_table_start_search = re.compile('<##table##', re.IGNORECASE).search diff --git a/scripts/template.py b/scripts/template.py index 0dfa0bc..adfd01b 100755 --- a/scripts/template.py +++ b/scripts/template.py @@ -182,7 +182,7 @@ names of the templates that should be removed/resolved to None. @type templates: dict """ - self.availableOptions.update({ + self.available_options.update({ 'addcat': None, 'remove': False, 'subst': False, diff --git a/scripts/touch.py b/scripts/touch.py index a6cab65..0a1c9f7 100755 --- a/scripts/touch.py +++ b/scripts/touch.py @@ -43,7 +43,7 @@
def __init__(self, generator, **kwargs) -> None: """Initialize a TouchBot instance with the options and generator.""" - self.availableOptions.update({ + self.available_options.update({ 'botflag': False, }) super().__init__(generator=generator, **kwargs) @@ -51,7 +51,7 @@ def treat(self, page) -> None: """Touch the given page.""" try: - page.touch(botflag=self.getOption('botflag')) + page.touch(botflag=self.opt.botflag) except (pywikibot.NoCreateError, pywikibot.NoPage): pywikibot.error('Page {0} does not exist.' .format(page.title(as_link=True))) @@ -69,7 +69,7 @@
def __init__(self, generator, **kwargs) -> None: """Initialize a PurgeBot instance with the options and generator.""" - self.availableOptions = { + self.available_options = { 'converttitles': None, 'forcelinkupdate': None, 'forcerecursivelinkupdate': None, diff --git a/scripts/unlink.py b/scripts/unlink.py index a1463fa..46598ce 100755 --- a/scripts/unlink.py +++ b/scripts/unlink.py @@ -45,7 +45,7 @@ super(UnlinkBot, self).__init__(**kwargs) self.pageToUnlink = pageToUnlink self.generator = pageToUnlink.getReferences( - namespaces=self.getOption('namespaces'), content=True) + namespaces=self.opt.namespaces, content=True)
@property def summary_parameters(self): diff --git a/scripts/unusedfiles.py b/scripts/unusedfiles.py index 1ccbce5..ad05f56 100755 --- a/scripts/unusedfiles.py +++ b/scripts/unusedfiles.py @@ -44,7 +44,7 @@
def __init__(self, **kwargs): """Initializer.""" - self.availableOptions.update({ + self.available_options.update({ 'nouserwarning': False # do not warn uploader }) super().__init__(**kwargs) @@ -54,7 +54,7 @@ self.template_user = i18n.translate(self.site, template_to_the_user) if not (self.template_image - and (self.template_user or self.getOption('nouserwarning'))): + and (self.template_user or self.opt.nouserwarning)): raise i18n.TranslationError('This script is not localized for {0} ' 'site.'.format(self.site))
@@ -70,7 +70,7 @@ return
self.append_text(image, '\n\n' + self.template_image) - if self.getOption('nouserwarning'): + if self.opt.nouserwarning: return uploader = image.get_file_history().pop(0)['user'] user = pywikibot.User(image.site, uploader)
pywikibot-commits@lists.wikimedia.org