jenkins-bot has submitted this change. ( https://gerrit.wikimedia.org/r/c/pywikibot/core/+/731267 )
Change subject: [IMPR] Provide ConfigParserBot for several scripts
......................................................................
[IMPR] Provide ConfigParserBot for several scripts
Bug: T223778
Change-Id: I218439e25468957f9aecc389a23cf49f727efcaa
---
M scripts/blockpageschecker.py
M scripts/category_redirect.py
M scripts/change_pagelang.py
M scripts/commonscat.py
M scripts/coordinate_import.py
M scripts/djvutext.py
M scripts/download_dump.py
M scripts/harvest_template.py
M scripts/interwikidata.py
M scripts/nowcommons.py
M scripts/protect.py
M scripts/reflinks.py
M scripts/unusedfiles.py
13 files changed, 192 insertions(+), 61 deletions(-)
Approvals:
Xqt: Looks good to me, approved
jenkins-bot: Verified
diff --git a/scripts/blockpageschecker.py b/scripts/blockpageschecker.py
index b5186c3..b48f6a2 100755
--- a/scripts/blockpageschecker.py
+++ b/scripts/blockpageschecker.py
@@ -175,7 +175,11 @@
class CheckerBot(ConfigParserBot, ExistingPageBot, SingleSiteBot):
- """Bot to remove stale protection templates from unprotected pages."""
+ """Bot to remove stale protection templates from unprotected pages.
+
+ .. versionchanged:: 7.0
+ CheckerBot is a ConfigParserBot
+ """
update_options = {
'show': False,
diff --git a/scripts/category_redirect.py b/scripts/category_redirect.py
index 96fb733..2897a53 100755
--- a/scripts/category_redirect.py
+++ b/scripts/category_redirect.py
@@ -11,6 +11,9 @@
The following parameters are supported:
+-always If used, the bot won't ask if it should add the specified
+ text
+
-delay:# Set an amount of days. If the category is edited more recenty
than given days, ignore it. Default is 7.
@@ -22,6 +25,9 @@
python pwb.py category_redirect [options]
+.. note:: This script is a
+ :py:obj:`ConfigParserBot <pywikibot.bot.ConfigParserBot>`. All options
+ can be set within a settings file which is scripts.ini by default.
"""
#
# (C) Pywikibot team, 2008-2021
@@ -36,7 +42,7 @@
import pywikibot
from pywikibot import config, i18n, pagegenerators
-from pywikibot.bot import SingleSiteBot
+from pywikibot.bot import ConfigParserBot, SingleSiteBot
from pywikibot.exceptions import (
CircularRedirectError,
Error,
@@ -45,9 +51,13 @@
)
-class CategoryRedirectBot(SingleSiteBot):
+class CategoryRedirectBot(ConfigParserBot, SingleSiteBot):
- """Page category update bot."""
+ """Page category update bot.
+
+ .. versionchanged:: 7.0
+ CategoryRedirectBot is a ConfigParserBot
+ """
update_options = {
'tiny': False, # use Non-empty category redirects only
diff --git a/scripts/change_pagelang.py b/scripts/change_pagelang.py
index a3c7a38..5a3c6e6 100755
--- a/scripts/change_pagelang.py
+++ b/scripts/change_pagelang.py
@@ -15,6 +15,10 @@
-never If a language is already set for a page, never change it to
the one set in -setlang (keep the current language).
+
+.. note:: This script is a
+ :py:obj:`ConfigParserBot <pywikibot.bot.ConfigParserBot>`. All options
+ can be set within a settings file which is scripts.ini by default.
"""
#
# (C) Pywikibot team, 2018-2021
@@ -23,7 +27,7 @@
#
import pywikibot
from pywikibot import pagegenerators
-from pywikibot.bot import SingleSiteBot
+from pywikibot.bot import ConfigParserBot, SingleSiteBot
from pywikibot.tools.formatter import color_format
@@ -32,9 +36,13 @@
}
-class ChangeLangBot(SingleSiteBot):
+class ChangeLangBot(ConfigParserBot, SingleSiteBot):
- """Change page language bot."""
+ """Change page language bot.
+
+ .. versionchanged:: 7.0
+ ChangeLangBot is a ConfigParserBot
+ """
update_options = {
'never': False,
diff --git a/scripts/commonscat.py b/scripts/commonscat.py
index 4cef4a3..8737162 100755
--- a/scripts/commonscat.py
+++ b/scripts/commonscat.py
@@ -9,15 +9,19 @@
The following parameters are supported:
+-checkcurrent Work on all category pages that use the primary commonscat
+ template.
+
+This script is a :py:obj:`ConfigParserBot <pywikibot.bot.ConfigParserBot>`.
+The following options can be set within a settings file which is scripts.ini
+by default::
+
-always Don't prompt you for each replacement. Warning message
has not to be confirmed. ATTENTION: Use this with care!
-summary:XYZ Set the action summary message for the edit to XYZ,
otherwise it uses messages from add_text.py as default.
--checkcurrent Work on all category pages that use the primary commonscat
- template.
-
This bot uses pagegenerators to get a list of pages. The following options are
supported:
@@ -43,7 +47,7 @@
import pywikibot
from pywikibot import i18n, pagegenerators
-from pywikibot.bot import ExistingPageBot, NoRedirectPageBot
+from pywikibot.bot import ConfigParserBot, ExistingPageBot, NoRedirectPageBot
from pywikibot.exceptions import InvalidTitleError
from pywikibot.textlib import add_text
@@ -222,11 +226,15 @@
}
-class CommonscatBot(ExistingPageBot, NoRedirectPageBot):
+class CommonscatBot(ConfigParserBot, ExistingPageBot, NoRedirectPageBot):
- """Commons categorisation bot."""
+ """Commons categorisation bot.
- update_options = {'summary': None}
+ .. versionchanged:: 7.0
+ CommonscatBot is a ConfigParserBot
+ """
+
+ update_options = {'summary': ''}
def skip_page(self, page):
"""Skip category redirects or disambigs."""
diff --git a/scripts/coordinate_import.py b/scripts/coordinate_import.py
index a2f9848..49cb745 100755
--- a/scripts/coordinate_import.py
+++ b/scripts/coordinate_import.py
@@ -31,8 +31,15 @@
The following command line parameters are supported:
+-always If used, the bot won't ask if it should add the specified
+ text
+
-create Create items for pages without one.
+.. note:: This script is a
+ :py:obj:`ConfigParserBot <pywikibot.bot.ConfigParserBot>`. All options
+ can be set within a settings file which is scripts.ini by default.
+
¶ms;
"""
#
@@ -43,16 +50,22 @@
from typing import Optional
import pywikibot
-from pywikibot import WikidataBot, pagegenerators
+
+from pywikibot import pagegenerators
+from pywikibot.bot import ConfigParserBot, WikidataBot
from pywikibot.exceptions import CoordinateGlobeUnknownError
docuReplacements = {'¶ms;': pagegenerators.parameterHelp} # noqa: N816
-class CoordImportRobot(WikidataBot):
+class CoordImportRobot(ConfigParserBot, WikidataBot):
- """A bot to import coordinates to Wikidata."""
+ """A bot to import coordinates to Wikidata.
+
+ .. versionchanged:: 7.0
+ CoordImportRobot is a ConfigParserBot
+ """
use_from_page = None
diff --git a/scripts/djvutext.py b/scripts/djvutext.py
index ac86ec2..5fcf2f1 100755
--- a/scripts/djvutext.py
+++ b/scripts/djvutext.py
@@ -19,6 +19,11 @@
A- -> pages A until number of images
A -> just page A
-B -> pages 1 until B
+
+This script is a :py:obj:`ConfigParserBot <pywikibot.bot.ConfigParserBot>`.
+The following options can be set within a settings file which is scripts.ini
+by default:
+
-summary: custom edit summary.
Use quotes if edit summary contains spaces.
-force overwrites existing text
@@ -48,6 +53,9 @@
A bot that uploads text-layer from djvu files to Page:namespace.
Works only on sites with Proofread Page extension installed.
+
+ .. versionchanged:: 7.0
+ CheckerBot is a ConfigParserBot
"""
update_options = {
diff --git a/scripts/download_dump.py b/scripts/download_dump.py
index 26366c2..6d19b34 100755
--- a/scripts/download_dump.py
+++ b/scripts/download_dump.py
@@ -11,6 +11,9 @@
-dumpdate:# The dumpdate date of the dump (default to `latest`)
formatted as YYYYMMDD.
+.. note:: This script is a
+ :py:obj:`ConfigParserBot <pywikibot.bot.ConfigParserBot>`. All options
+ can be set within a settings file which is scripts.ini by default.
"""
#
# (C) Pywikibot team, 2017-2021
@@ -23,13 +26,17 @@
from os import remove, replace, symlink, urandom
import pywikibot
-from pywikibot import Bot
+from pywikibot.bot import Bot, ConfigParserBot
from pywikibot.comms.http import fetch
-class DownloadDumpBot(Bot):
+class DownloadDumpBot(Bot, ConfigParserBot):
- """Download dump bot."""
+ """Download dump bot.
+
+ .. versionchanged:: 7.0
+ DownloadDumpBot is a ConfigParserBot
+ """
available_options = {
'wikiname': '',
diff --git a/scripts/harvest_template.py b/scripts/harvest_template.py
index 68df846..c740470 100755
--- a/scripts/harvest_template.py
+++ b/scripts/harvest_template.py
@@ -22,6 +22,9 @@
You can also use additional parameters:
+-always If used, the bot won't ask if it should add the specified
+ text
+
-create Create missing items before importing.
The following command line parameters can be used to change the bot's behavior.
@@ -85,6 +88,10 @@
python pwb.py harvest_template -lang:en -family:wikipedia -namespace:0 \
-template:"Infobox musical artist" current_members P527 -exists:p \
-multi
+
+.. note:: This script is a
+ :py:obj:`ConfigParserBot <pywikibot.bot.ConfigParserBot>`. All options
+ can be set within a settings file which is scripts.ini by default.
"""
#
# (C) Pywikibot team, 2013-2021
@@ -99,7 +106,7 @@
from pywikibot import pagegenerators as pg
from pywikibot import textlib
from pywikibot.backports import List
-from pywikibot.bot import OptionHandler, WikidataBot
+from pywikibot.bot import ConfigParserBot, OptionHandler, WikidataBot
from pywikibot.exceptions import InvalidTitleError, NoPageError
@@ -132,9 +139,13 @@
}
-class HarvestRobot(WikidataBot):
+class HarvestRobot(ConfigParserBot, WikidataBot):
- """A bot to add Wikidata claims."""
+ """A bot to add Wikidata claims.
+
+ .. versionchanged:: 7.0
+ HarvestRobot is a ConfigParserBot
+ """
update_options = {
'always': True,
diff --git a/scripts/interwikidata.py b/scripts/interwikidata.py
index 48235de..2b6fc90 100755
--- a/scripts/interwikidata.py
+++ b/scripts/interwikidata.py
@@ -13,6 +13,9 @@
Furthermore, the following command line parameters are supported:
+-always If used, the bot won't ask if it should add the specified
+ text
+
-clean Clean pages.
-create Create items.
@@ -20,6 +23,10 @@
-merge Merge items.
-summary: Use your own edit summary for cleaning the page.
+
+.. note:: This script is a
+ :py:obj:`ConfigParserBot <pywikibot.bot.ConfigParserBot>`. All options
+ can be set within a settings file which is scripts.ini by default.
"""
# (C) Pywikibot team, 2015-2021
@@ -34,7 +41,12 @@
import pywikibot.textlib
from pywikibot import output, pagegenerators, warning
from pywikibot.backports import Set
-from pywikibot.bot import ExistingPageBot, SingleSiteBot, suggest_help
+from pywikibot.bot import (
+ ConfigParserBot,
+ ExistingPageBot,
+ SingleSiteBot,
+ suggest_help,
+)
from pywikibot.exceptions import APIError, NoPageError
@@ -49,9 +61,13 @@
# should cause the bot to skip the page, see T134497
-class IWBot(ExistingPageBot, SingleSiteBot):
+class IWBot(ConfigParserBot, ExistingPageBot, SingleSiteBot):
- """The bot for interwiki."""
+ """The bot for interwiki.
+
+ .. versionchanged:: 7.0
+ IWBot is a ConfigParserBot
+ """
update_options = {
'clean': False,
diff --git a/scripts/nowcommons.py b/scripts/nowcommons.py
index 6c90ded..6bb1c41 100755
--- a/scripts/nowcommons.py
+++ b/scripts/nowcommons.py
@@ -38,12 +38,9 @@
python pwb.py nowcommons -replaceonly -replaceloose -replacealways -replace
-Todo
-----
-Please fix these if you are capable and motivated:
-
-- if a file marked nowcommons is not present on Wikimedia Commons, the bot
- will exit.
+.. note:: This script is a
+ :py:obj:`ConfigParserBot <pywikibot.bot.ConfigParserBot>`. All options
+ can be set within a settings file which is scripts.ini by default.
"""
#
# (C) Pywikibot team, 2006-2021
@@ -54,7 +51,8 @@
from itertools import chain
import pywikibot
-from pywikibot import Bot, i18n
+from pywikibot import i18n
+from pywikibot.bot import Bot, ConfigParserBot
from pywikibot import pagegenerators as pg
from pywikibot.exceptions import IsRedirectPageError, NoPageError
from pywikibot.tools import filter_unique
@@ -175,9 +173,13 @@
]
-class NowCommonsDeleteBot(Bot):
+class NowCommonsDeleteBot(Bot, ConfigParserBot):
- """Bot to delete migrated files."""
+ """Bot to delete migrated files.
+
+ .. versionchanged:: 7.0
+ NowCommonsDeleteBot is a ConfigParserBot
+ """
update_options = {
'replace': False,
diff --git a/scripts/protect.py b/scripts/protect.py
index 20a378e..ce119f6 100755
--- a/scripts/protect.py
+++ b/scripts/protect.py
@@ -9,17 +9,6 @@
Furthermore, the following command line parameters are supported:
--always Don't prompt to protect pages, just do it.
-
--summary: Supply a custom edit summary. Tries to generate summary from
- the page selector. If no summary is supplied or couldn't
- determine one from the selector it'll ask for one.
-
--expiry: Supply a custom protection expiry, which defaults to
- indefinite. Any string understandable by MediaWiki, including
- relative and absolute, is acceptable. See:
- https://www.mediawiki.org/wiki/API:Protect#Parameters
-
-unprotect Acts like "default:all"
-default: Sets the default protection level (default 'sysop'). If no
@@ -35,6 +24,21 @@
parameters -unprotect or -default are used, only the last occurrence
is applied.
+This script is a :py:obj:`ConfigParserBot <pywikibot.bot.ConfigParserBot>`.
+The following options can be set within a settings file which is scripts.ini
+by default::
+
+-always Don't prompt to protect pages, just do it.
+
+-summary: Supply a custom edit summary. Tries to generate summary from
+ the page selector. If no summary is supplied or couldn't
+ determine one from the selector it'll ask for one.
+
+-expiry: Supply a custom protection expiry, which defaults to
+ indefinite. Any string understandable by MediaWiki, including
+ relative and absolute, is acceptable. See:
+ https://www.mediawiki.org/wiki/API:Protect#Parameters
+
Usage:
python pwb.py protect <OPTIONS>
@@ -59,7 +63,7 @@
#
import pywikibot
from pywikibot import i18n, pagegenerators
-from pywikibot.bot import CurrentPageBot, SingleSiteBot
+from pywikibot.bot import ConfigParserBot, CurrentPageBot, SingleSiteBot
# This is required for the text that is shown when you run this script
@@ -67,9 +71,13 @@
docuReplacements = {'¶ms;': pagegenerators.parameterHelp} # noqa: N816
-class ProtectionRobot(SingleSiteBot, CurrentPageBot):
+class ProtectionRobot(SingleSiteBot, ConfigParserBot, CurrentPageBot):
- """This bot allows protection of pages en masse."""
+ """This bot allows protection of pages en masse.
+
+ .. versionchanged:: 7.0
+ CheckerBot is a ConfigParserBot
+ """
update_options = {
'summary': '',
diff --git a/scripts/reflinks.py b/scripts/reflinks.py
index 825eb69..da9a975 100755
--- a/scripts/reflinks.py
+++ b/scripts/reflinks.py
@@ -18,13 +18,20 @@
The following parameters are supported:
--limit:n Stops after n edits
-
-xml:dump.xml Should be used instead of a simple page fetching method
from pagegenerators.py for performance and load issues
-xmlstart Page to start with when using an XML dump
+This script is a :py:obj:`ConfigParserBot <pywikibot.bot.ConfigParserBot>`.
+The following options can be set within a settings file which is scripts.ini
+by default::
+
+-always Doesn't ask every time whether the bot should make the change.
+ Do it always.
+
+-limit:n Stops after n edits
+
-ignorepdf Do not handle PDF files (handy if you use Windows and
can't get pdfinfo)
@@ -57,7 +64,12 @@
import pywikibot
from pywikibot import comms, config, i18n, pagegenerators, textlib
from pywikibot.backports import removeprefix
-from pywikibot.bot import ExistingPageBot, NoRedirectPageBot, SingleSiteBot
+from pywikibot.bot import (
+ ConfigParserBot,
+ ExistingPageBot,
+ NoRedirectPageBot,
+ SingleSiteBot,
+)
from pywikibot.exceptions import (
FatalServerError,
Server414Error,
@@ -412,9 +424,16 @@
return text
-class ReferencesRobot(SingleSiteBot, ExistingPageBot, NoRedirectPageBot):
+class ReferencesRobot(SingleSiteBot,
+ ConfigParserBot,
+ ExistingPageBot,
+ NoRedirectPageBot):
- """References bot."""
+ """References bot.
+
+ .. versionchanged:: 7.0
+ ReferencesRobot is a ConfigParserBot
+ """
update_options = {
'ignorepdf': False,
diff --git a/scripts/unusedfiles.py b/scripts/unusedfiles.py
index 5d05f5c..947ba18 100755
--- a/scripts/unusedfiles.py
+++ b/scripts/unusedfiles.py
@@ -4,13 +4,18 @@
Parameters:
--always Don't be asked every time.
--nouserwarning Do not warn uploader about orphaned file.
--filetemplate: Use a custom template on unused file pages.
--usertemplate: Use a custom template to warn the uploader.
-limit Specify number of pages to work on with "-limit:n" where
n is the maximum number of articles to work on.
If not used, all pages are used.
+-always Don't be asked every time.
+
+This script is a :py:obj:`ConfigParserBot <pywikibot.bot.ConfigParserBot>`.
+The following options can be set within a settings file which is scripts.ini
+by default::
+
+-nouserwarning Do not warn uploader about orphaned file.
+-filetemplate: Use a custom template on unused file pages.
+-usertemplate: Use a custom template to warn the uploader.
"""
#
# (C) Pywikibot team, 2007-2021
@@ -21,7 +26,12 @@
import pywikibot
from pywikibot import i18n, pagegenerators
-from pywikibot.bot import AutomaticTWSummaryBot, ExistingPageBot, SingleSiteBot
+from pywikibot.bot import (
+ AutomaticTWSummaryBot,
+ ConfigParserBot,
+ ExistingPageBot,
+ SingleSiteBot,
+)
from pywikibot.exceptions import Error, NoPageError, TranslationError
from pywikibot.flow import Board
@@ -41,9 +51,16 @@
}
-class UnusedFilesBot(SingleSiteBot, AutomaticTWSummaryBot, ExistingPageBot):
+class UnusedFilesBot(SingleSiteBot,
+ AutomaticTWSummaryBot,
+ ConfigParserBot,
+ ExistingPageBot):
- """Unused files bot."""
+ """Unused files bot.
+
+ .. versionchanged:: 7.0
+ UnusedFilesBot is a ConfigParserBot
+ """
summary_key = 'unusedfiles-comment'
update_options = {
--
To view, visit https://gerrit.wikimedia.org/r/c/pywikibot/core/+/731267
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: I218439e25468957f9aecc389a23cf49f727efcaa
Gerrit-Change-Number: 731267
Gerrit-PatchSet: 2
Gerrit-Owner: Xqt <info(a)gno.de>
Gerrit-Reviewer: D3r1ck01 <xsavitar.wiki(a)aol.com>
Gerrit-Reviewer: Xqt <info(a)gno.de>
Gerrit-Reviewer: jenkins-bot
Gerrit-MessageType: merged
jenkins-bot has submitted this change. ( https://gerrit.wikimedia.org/r/c/pywikibot/core/+/731737 )
Change subject: [doc] fix sphinx doc
......................................................................
[doc] fix sphinx doc
Change-Id: I3dc86f6c57e46935843298457e20e257f01835c9
---
M pywikibot/tools/_deprecate.py
1 file changed, 1 insertion(+), 1 deletion(-)
Approvals:
Xqt: Looks good to me, approved
jenkins-bot: Verified
diff --git a/pywikibot/tools/_deprecate.py b/pywikibot/tools/_deprecate.py
index a043e5d..1c874af 100644
--- a/pywikibot/tools/_deprecate.py
+++ b/pywikibot/tools/_deprecate.py
@@ -15,7 +15,7 @@
only one arg, and that arg be a callable, as it will be detected as
a deprecator without any arguments.
-.. versionchanged 6.4:
+.. versionchanged:: 6.4
deprecation decorators moved to _deprecate module
"""
#
--
To view, visit https://gerrit.wikimedia.org/r/c/pywikibot/core/+/731737
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: I3dc86f6c57e46935843298457e20e257f01835c9
Gerrit-Change-Number: 731737
Gerrit-PatchSet: 1
Gerrit-Owner: Xqt <info(a)gno.de>
Gerrit-Reviewer: Xqt <info(a)gno.de>
Gerrit-Reviewer: jenkins-bot
Gerrit-MessageType: merged
jenkins-bot has submitted this change. ( https://gerrit.wikimedia.org/r/c/pywikibot/core/+/731116 )
Change subject: [bugfix] Raise a generic ServerError if the http status code is unofficial
......................................................................
[bugfix] Raise a generic ServerError if the http status code is unofficial
Bug: T293208
Change-Id: I3caf2d70803e25b73acada64b13281afbda50a90
---
M pywikibot/site_detect.py
1 file changed, 16 insertions(+), 1 deletion(-)
Approvals:
Matěj Suchánek: Looks good to me, but someone else must approve
Xqt: Looks good to me, approved
jenkins-bot: Verified
diff --git a/pywikibot/site_detect.py b/pywikibot/site_detect.py
index 6868b52..0181f65 100644
--- a/pywikibot/site_detect.py
+++ b/pywikibot/site_detect.py
@@ -5,6 +5,8 @@
# Distributed under the terms of the MIT license.
#
import json
+import re
+
from contextlib import suppress
from html.parser import HTMLParser
from http import HTTPStatus
@@ -276,9 +278,22 @@
"""Raise ServerError if the response indicates a server error.
.. versionadded:: 3.0
+ .. versionchanged:: 7.0
+ Raise a generic ServerError if http status code is not
+ IANA-registered but unofficial code
+
+
"""
if response.status_code >= HTTPStatus.INTERNAL_SERVER_ERROR:
- raise ServerError(HTTPStatus(response.status_code).phrase)
+ try:
+ msg = HTTPStatus(response.status_code).phrase
+ except ValueError as err:
+ m = re.search(r'\d{3}', err.args[0], flags=re.ASCII)
+ if not m:
+ raise err
+ msg = 'Generic Server Error ({})'.format(m.group())
+
+ raise ServerError(msg)
if response.status_code == HTTPStatus.OK \
and SERVER_DB_ERROR_MSG in response.text:
--
To view, visit https://gerrit.wikimedia.org/r/c/pywikibot/core/+/731116
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: I3caf2d70803e25b73acada64b13281afbda50a90
Gerrit-Change-Number: 731116
Gerrit-PatchSet: 3
Gerrit-Owner: Xqt <info(a)gno.de>
Gerrit-Reviewer: Matěj Suchánek <matejsuchanek97(a)gmail.com>
Gerrit-Reviewer: Xqt <info(a)gno.de>
Gerrit-Reviewer: jenkins-bot
Gerrit-MessageType: merged