jenkins-bot has submitted this change. (
https://gerrit.wikimedia.org/r/c/pywikibot/core/+/700434 )
Change subject: [IMPR] Update bots to use update_options
......................................................................
[IMPR] Update bots to use update_options
Change-Id: I477dd22a00ff442f47d241d338e60664f6332a6e
---
M pywikibot/specialbots/_unlink.py
M scripts/category_redirect.py
M scripts/change_pagelang.py
M scripts/delete.py
M scripts/djvutext.py
M scripts/harvest_template.py
M scripts/image.py
M scripts/imagetransfer.py
M scripts/interwikidata.py
M scripts/movepages.py
M scripts/newitem.py
M scripts/noreferences.py
M scripts/nowcommons.py
M scripts/pagefromfile.py
M scripts/parser_function_count.py
M scripts/patrol.py
M scripts/protect.py
M scripts/redirect.py
M scripts/reflinks.py
M scripts/replace.py
M scripts/template.py
M scripts/touch.py
M scripts/unusedfiles.py
23 files changed, 147 insertions(+), 148 deletions(-)
Approvals:
Xqt: Looks good to me, approved
jenkins-bot: Verified
diff --git a/pywikibot/specialbots/_unlink.py b/pywikibot/specialbots/_unlink.py
index 56a6d93..ca0c114 100644
--- a/pywikibot/specialbots/_unlink.py
+++ b/pywikibot/specialbots/_unlink.py
@@ -60,14 +60,11 @@
"""A basic bot unlinking a given link from the current
page."""
- def __init__(self, **kwargs):
- """Redirect all parameters and add namespace as an available
option."""
- self.available_options.update({
- 'namespaces': [],
- # Which namespaces should be processed?
- # default to [] which means all namespaces will be processed
- })
- super().__init__(**kwargs)
+ update_options = {
+ 'namespaces': [],
+ # Which namespaces should be processed?
+ # default to [] which means all namespaces will be processed
+ }
def _create_callback(self):
"""Create a new callback instance for
replace_links."""
diff --git a/scripts/category_redirect.py b/scripts/category_redirect.py
index 944525f..7d487b5 100755
--- a/scripts/category_redirect.py
+++ b/scripts/category_redirect.py
@@ -50,12 +50,13 @@
"""Page category update bot."""
+ update_options = {
+ 'tiny': False, # use Non-empty category redirects only
+ 'delay': 7, # cool down delay in days
+ }
+
def __init__(self, **kwargs):
"""Initializer."""
- self.available_options.update({
- 'tiny': False, # use Non-empty category redirects only
- 'delay': 7, # cool down delay in days
- })
super().__init__(**kwargs)
self.catprefix = self.site.namespace(14) + ':'
self.log_text = []
diff --git a/scripts/change_pagelang.py b/scripts/change_pagelang.py
index b68eb14..ce8e85e 100755
--- a/scripts/change_pagelang.py
+++ b/scripts/change_pagelang.py
@@ -36,15 +36,14 @@
"""Change page language bot."""
+ update_options = {
+ 'never': False,
+ 'setlang': '',
+ }
+
def __init__(self, **kwargs):
"""Initializer."""
- self.available_options.update({
- 'always': False,
- 'never': False,
- 'setlang': ''
- })
super().__init__(**kwargs)
-
assert not (self.opt.always and self.opt.never), \
'Either "always" or "never" must be set but not
both'
diff --git a/scripts/delete.py b/scripts/delete.py
index 7dacb8b..b569fe5 100755
--- a/scripts/delete.py
+++ b/scripts/delete.py
@@ -127,16 +127,17 @@
"""This robot allows deletion of pages en masse."""
+ update_options = {
+ 'undelete': False,
+ 'isorphan': 0,
+ 'orphansonly': [],
+ }
+
def __init__(self, summary: str, **kwargs) -> None:
"""Initializer.
:param summary: the reason for the (un)deletion
"""
- self.available_options.update({
- 'undelete': False,
- 'isorphan': 0,
- 'orphansonly': [],
- })
super().__init__(**kwargs)
self.summary = summary
diff --git a/scripts/djvutext.py b/scripts/djvutext.py
index c2c1f9c..9c5340b 100755
--- a/scripts/djvutext.py
+++ b/scripts/djvutext.py
@@ -51,6 +51,11 @@
Works only on sites with Proofread Page extension installed.
"""
+ update_options = {
+ 'force': False,
+ 'summary': '',
+ }
+
def __init__(self, djvu, index, pages: Optional[tuple] = None, **kwargs):
"""
Initializer.
@@ -61,10 +66,6 @@
:type index: Page object
:param pages: page interval to upload (start, end)
"""
- self.available_options.update({
- 'force': False,
- 'summary': None
- })
super().__init__(site=index.site, **kwargs)
self._djvu = djvu
self._index = index
diff --git a/scripts/harvest_template.py b/scripts/harvest_template.py
index 8dab7a4..daa02d6 100755
--- a/scripts/harvest_template.py
+++ b/scripts/harvest_template.py
@@ -136,6 +136,14 @@
"""A bot to add Wikidata claims."""
+ update_options = {
+ 'always': True,
+ 'create': False,
+ 'exists': '',
+ 'islink': False,
+ 'multi': False,
+ }
+
def __init__(self, template_title, fields, **kwargs) -> None:
"""Initializer.
@@ -154,13 +162,6 @@
single parameter
:type multi: bool
"""
- self.available_options.update({
- 'always': True,
- 'create': False,
- 'exists': '',
- 'islink': False,
- 'multi': False,
- })
super().__init__(**kwargs)
# TODO: Make it a list including the redirects to the template
self.fields = {}
diff --git a/scripts/image.py b/scripts/image.py
index 76e30ea..bad0300 100755
--- a/scripts/image.py
+++ b/scripts/image.py
@@ -54,6 +54,11 @@
"""This bot will replace or remove all occurrences of an old
image."""
+ update_options = {
+ 'summary': '',
+ 'loose': False,
+ }
+
def __init__(self, generator, old_image: str,
new_image: Optional[str] = None, **kwargs):
"""
@@ -65,11 +70,6 @@
:param new_image: the title of the new image (without namespace), or
None if you want to remove the image
"""
- self.available_options.update({
- 'summary': None,
- 'loose': False,
- })
-
SingleSiteBot.__init__(self, generator=generator, **kwargs)
self.old_image = old_image
diff --git a/scripts/imagetransfer.py b/scripts/imagetransfer.py
index 5767ede..abfb70e 100755
--- a/scripts/imagetransfer.py
+++ b/scripts/imagetransfer.py
@@ -138,6 +138,14 @@
"""Image transfer bot."""
+ update_options = {
+ 'ignore_warning': False, # not implemented yet
+ 'interwiki': False,
+ 'keepname': False,
+ 'target': None,
+ 'force_if_shared': False,
+ }
+
def __init__(self, **kwargs):
"""Initializer.
@@ -155,14 +163,6 @@
wiki)
:type force_if_shared: boolean
"""
- self.available_options.update({
- 'ignore_warning': False, # not implemented yet
- 'interwiki': False,
- 'keepname': False,
- 'target': None,
- 'force_if_shared': False,
- })
-
super().__init__(**kwargs)
if self.opt.target is None:
self.opt.target = self.site.image_repository()
diff --git a/scripts/interwikidata.py b/scripts/interwikidata.py
index ed08045..2557e39 100755
--- a/scripts/interwikidata.py
+++ b/scripts/interwikidata.py
@@ -53,15 +53,16 @@
"""The bot for interwiki."""
+ update_options = {
+ 'clean': False,
+ 'create': False,
+ 'merge': False,
+ 'summary': '',
+ 'ignore_ns': False, # used by interwikidata_tests only
+ }
+
def __init__(self, **kwargs) -> None:
"""Initialize the bot."""
- self.available_options.update({
- 'clean': False,
- 'create': False,
- 'merge': False,
- 'summary': None,
- 'ignore_ns': False, # used by interwikidata_tests only
- })
super().__init__(**kwargs)
if not self.site.has_data_repository:
raise ValueError('{site} does not have a data repository, use '
diff --git a/scripts/movepages.py b/scripts/movepages.py
index eadd26a..3095006 100755
--- a/scripts/movepages.py
+++ b/scripts/movepages.py
@@ -52,17 +52,17 @@
"""Page move bot."""
+ update_options = {
+ 'prefix': '',
+ 'noredirect': False,
+ 'movetalkpage': True,
+ 'skipredirects': False,
+ 'summary': '',
+ }
+
def __init__(self, **kwargs) -> None:
"""Initializer."""
- self.available_options.update({
- 'prefix': None,
- 'noredirect': False,
- 'movetalkpage': True,
- 'skipredirects': False,
- 'summary': None,
- })
super().__init__(**kwargs)
-
self.appendAll = False
self.regexAll = False
self.noNamespace = False
diff --git a/scripts/newitem.py b/scripts/newitem.py
index 2621957..570eb9c 100755
--- a/scripts/newitem.py
+++ b/scripts/newitem.py
@@ -47,17 +47,16 @@
"""A bot to create new items."""
treat_missing_item = True
+ update_options = {
+ 'always': True,
+ 'lastedit': 7,
+ 'pageage': 21,
+ 'touch': 'newly', # Can be False, newly (pages linked to newly
+ # created items) or True (touch all pages)
+ }
def __init__(self, **kwargs) -> None:
"""Only accepts options defined in
available_options."""
- self.available_options.update({
- 'always': True,
- 'lastedit': 7,
- 'pageage': 21,
- 'touch': 'newly', # Can be False, newly (pages linked to
newly
- # created items) or True (touch all pages)
- })
-
super().__init__(**kwargs)
self._skipping_templates = {}
diff --git a/scripts/noreferences.py b/scripts/noreferences.py
index 69692bf..cfc59ad 100755
--- a/scripts/noreferences.py
+++ b/scripts/noreferences.py
@@ -516,12 +516,13 @@
"""References section bot."""
+ update_options = {
+ 'verbose': True,
+ }
+
@remove_last_args(['gen'])
def __init__(self, **kwargs) -> None:
"""Initializer."""
- self.available_options.update({
- 'verbose': True,
- })
super().__init__(**kwargs)
self.refR = _ref_regex
diff --git a/scripts/nowcommons.py b/scripts/nowcommons.py
index e3580a9..927f901 100755
--- a/scripts/nowcommons.py
+++ b/scripts/nowcommons.py
@@ -179,16 +179,16 @@
"""Bot to delete migrated files."""
+ update_options = {
+ 'replace': False,
+ 'replacealways': False,
+ 'replaceloose': False,
+ 'replaceonly': False,
+ }
+
def __init__(self, **kwargs):
"""Initializer."""
- self.available_options.update({
- 'replace': False,
- 'replacealways': False,
- 'replaceloose': False,
- 'replaceonly': False,
- })
super().__init__(**kwargs)
-
self.site = pywikibot.Site()
if not self.site.has_image_repository:
sys.exit('There must be a file repository to run this script')
diff --git a/scripts/pagefromfile.py b/scripts/pagefromfile.py
index d81f430..e868e80 100755
--- a/scripts/pagefromfile.py
+++ b/scripts/pagefromfile.py
@@ -93,20 +93,19 @@
"""
+ update_options = {
+ 'force': False,
+ 'append': None,
+ 'summary': '',
+ 'minor': False,
+ 'autosummary': False,
+ 'nocontent': '',
+ 'redirect': True,
+ 'showdiff': False,
+ }
+
def __init__(self, **kwargs) -> None:
"""Initializer."""
- self.available_options.update({
- 'always': True,
- 'force': False,
- 'append': None,
- 'summary': None,
- 'minor': False,
- 'autosummary': False,
- 'nocontent': '',
- 'redirect': True,
- 'showdiff': False,
- })
-
super().__init__(**kwargs)
self.available_options.update(
{'always': not self.opt.showdiff})
diff --git a/scripts/parser_function_count.py b/scripts/parser_function_count.py
index dff8971..4bf7898 100755
--- a/scripts/parser_function_count.py
+++ b/scripts/parser_function_count.py
@@ -67,18 +67,18 @@
"""Bot class used for obtaining Parser function
Count."""
+ update_options = {
+ 'atleast': None,
+ 'first': None,
+ 'nosort': False,
+ 'save': None,
+ 'start': '!',
+ 'upload': None,
+ }
+
def __init__(self, **kwargs):
"""Initializer."""
- self.available_options.update({
- 'atleast': None,
- 'first': None,
- 'nosort': False,
- 'save': None,
- 'start': '!',
- 'upload': None,
- })
super().__init__(**kwargs)
-
editcomment = {
# This will be used for uploading the list to your wiki.
'en':
diff --git a/scripts/patrol.py b/scripts/patrol.py
index 43801e4..a1cd050 100755
--- a/scripts/patrol.py
+++ b/scripts/patrol.py
@@ -74,6 +74,12 @@
"""Bot marks the edits as patrolled based on info obtained by
whitelist."""
+ update_options = {
+ 'ask': False,
+ 'whitelist': None,
+ 'versionchecktime': 300,
+ 'autopatroluserns': False,
+ }
# Localised name of the whitelist page
whitelist_subpage_name = {
'en': 'patrol_whitelist',
@@ -88,12 +94,6 @@
:keyword autopatroluserns: Takes user consent to automatically patrol
:keyword versionchecktime: Check versionchecktime lapse in sec
"""
- self.available_options.update({
- 'ask': False,
- 'whitelist': None,
- 'versionchecktime': 300,
- 'autopatroluserns': False
- })
super().__init__(**kwargs)
self.site = site or pywikibot.Site()
self.recent_gen = True
diff --git a/scripts/protect.py b/scripts/protect.py
index a73bb5f..dcf1096 100755
--- a/scripts/protect.py
+++ b/scripts/protect.py
@@ -71,6 +71,11 @@
"""This bot allows protection of pages en masse."""
+ update_options = {
+ 'summary': '',
+ 'expiry': '',
+ }
+
def __init__(self, protections, **kwargs):
"""
Create a new ProtectionRobot.
@@ -79,10 +84,6 @@
:type protections: dict
:param kwargs: additional arguments directly feed to super().__init__()
"""
- self.available_options.update({
- 'summary': None,
- 'expiry': None,
- })
super().__init__(**kwargs)
self.protections = protections
diff --git a/scripts/redirect.py b/scripts/redirect.py
index 1b9930f..077990f 100755
--- a/scripts/redirect.py
+++ b/scripts/redirect.py
@@ -377,15 +377,15 @@
"""Redirect bot."""
+ update_options = {
+ 'limit': float('inf'),
+ 'delete': False,
+ 'sdtemplate': '',
+ }
+
def __init__(self, action, **kwargs) -> None:
"""Initializer."""
- self.available_options.update({
- 'limit': float('inf'),
- 'delete': False,
- 'sdtemplate': None,
- })
super().__init__(**kwargs)
-
# connect the action treat to treat_page method called by treat
if action == 'double':
self.treat_page = self.fix_1_double_redirect
diff --git a/scripts/reflinks.py b/scripts/reflinks.py
index a627dae..fd599a4 100755
--- a/scripts/reflinks.py
+++ b/scripts/reflinks.py
@@ -406,14 +406,14 @@
"""References bot."""
+ update_options = {
+ 'ignorepdf': False,
+ 'limit': 0, # stop after n modified pages
+ 'summary': '',
+ }
+
def __init__(self, **kwargs):
"""Initializer."""
- self.available_options.update({
- 'ignorepdf': False, # boolean
- 'limit': 0, # int, stop after n modified pages
- 'summary': '',
- })
-
super().__init__(**kwargs)
self._use_fake_user_agent = config.fake_user_agent_default.get(
'reflinks', False)
diff --git a/scripts/replace.py b/scripts/replace.py
index f558502..000c8f1 100755
--- a/scripts/replace.py
+++ b/scripts/replace.py
@@ -522,16 +522,17 @@
about the missing site
"""
+ update_options = {
+ 'addcat': None,
+ 'allowoverlap': False,
+ 'recursive': False,
+ 'sleep': 0.0,
+ 'summary': '',
+ }
+
@deprecated_args(acceptall='always', addedCat='addcat')
def __init__(self, generator, replacements, exceptions=None, **kwargs):
"""Initializer."""
- self.available_options.update({
- 'addcat': None,
- 'allowoverlap': False,
- 'recursive': False,
- 'sleep': 0.0,
- 'summary': None,
- })
super().__init__(generator=generator, **kwargs)
for i, replacement in enumerate(replacements):
diff --git a/scripts/template.py b/scripts/template.py
index b346071..d71e404 100755
--- a/scripts/template.py
+++ b/scripts/template.py
@@ -123,6 +123,13 @@
"""This bot will replace, remove or subst all occurrences of a
template."""
+ update_options = {
+ 'addcat': None,
+ 'remove': False,
+ 'subst': False,
+ 'summary': '',
+ }
+
def __init__(self, generator, templates: dict, **kwargs) -> None:
"""
Initializer.
@@ -133,13 +140,6 @@
their replacements. If remove or subst is True, it maps the
names of the templates that should be removed/resolved to None.
"""
- self.available_options.update({
- 'addcat': None,
- 'remove': False,
- 'subst': False,
- 'summary': None,
- })
-
SingleSiteBot.__init__(self, **kwargs)
self.templates = templates
diff --git a/scripts/touch.py b/scripts/touch.py
index 2e693a6..5a68ff0 100755
--- a/scripts/touch.py
+++ b/scripts/touch.py
@@ -45,12 +45,9 @@
"""Page touch bot."""
- def __init__(self, **kwargs) -> None:
- """Initialize a TouchBot instance with the options and
generator."""
- self.available_options.update({
- 'botflag': False,
- })
- super().__init__(**kwargs)
+ update_options = {
+ 'botflag': False,
+ }
def treat(self, page) -> None:
"""Touch the given page."""
diff --git a/scripts/unusedfiles.py b/scripts/unusedfiles.py
index ac2b95d..77dfc6d 100755
--- a/scripts/unusedfiles.py
+++ b/scripts/unusedfiles.py
@@ -46,14 +46,14 @@
"""Unused files bot."""
summary_key = 'unusedfiles-comment'
+ update_options = {
+ 'nouserwarning': False, # do not warn uploader
+ 'filetemplate': '',
+ 'usertemplate': '',
+ }
def __init__(self, **kwargs):
"""Initializer."""
- self.available_options.update({
- 'nouserwarning': False, # do not warn uploader
- 'filetemplate': '',
- 'usertemplate': '',
- })
super().__init__(**kwargs)
# handle the custom templates
--
To view, visit
https://gerrit.wikimedia.org/r/c/pywikibot/core/+/700434
To unsubscribe, or for help writing mail filters, visit
https://gerrit.wikimedia.org/r/settings
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Change-Id: I477dd22a00ff442f47d241d338e60664f6332a6e
Gerrit-Change-Number: 700434
Gerrit-PatchSet: 1
Gerrit-Owner: JJMC89 <JJMC89.Wikimedia(a)gmail.com>
Gerrit-Reviewer: Xqt <info(a)gno.de>
Gerrit-Reviewer: jenkins-bot
Gerrit-MessageType: merged