jenkins-bot has submitted this change. (
https://gerrit.wikimedia.org/r/c/pywikibot/core/+/654412 )
Change subject: [IMPR] use pagegenerators namespace filter for redirect.py
......................................................................
[IMPR] use pagegenerators namespace filter for redirect.py
New behaviour may be like
pwb redirect do -ns:6
(process redirects of namespace 6 only)
pwb redirect do -ns:not:1,2
process redirects excluding namespaces 1 and 2
Bug: T234133
Bug: T271116
Change-Id: Ic6ddd7db06863bd6d918266b38bc1e6bd5744c2e
---
M scripts/redirect.py
1 file changed, 22 insertions(+), 31 deletions(-)
Approvals:
Xqt: Looks good to me, approved
jenkins-bot: Verified
diff --git a/scripts/redirect.py b/scripts/redirect.py
index 9b07caf..ef04b64 100755
--- a/scripts/redirect.py
+++ b/scripts/redirect.py
@@ -1,5 +1,4 @@
#!/usr/bin/python
-# -*- coding: utf-8 -*-
"""
Script to resolve double redirects, and to delete broken redirects.
@@ -42,10 +41,6 @@
-page:title Work on a single page
--namespace:n Namespace to process. Can be given multiple times, for several
- namespaces. If omitted, only the main (article) namespace is
- treated.
-
-offset:n With -moves, the number of hours ago to start scanning moved
pages. With -xml, the number of the redirect to restart with
(see progress). Otherwise, ignored.
@@ -68,9 +63,12 @@
-always Don't prompt you for each replacement.
+Furthermore the following options are provided:
+
+¶ms;
"""
#
-# (C) Pywikibot team, 2004-2020
+# (C) Pywikibot team, 2004-2021
#
# Distributed under the terms of the MIT license.
#
@@ -85,8 +83,11 @@
from pywikibot.backports import Dict, List, Set, Tuple
from pywikibot.bot import (ExistingPageBot, MultipleSitesBot, OptionHandler,
RedirectPageBot)
+from pywikibot import pagegenerators
from pywikibot.textlib import extract_templates_and_params_regex_simple
+docuReplacements = {'¶ms;': pagegenerators.parameterHelp} # noqa: N816
+
def space_to_underscore(link) -> str:
"""Convert spaces to underscore."""
@@ -663,11 +664,12 @@
# what the bot should do (either resolve double redirs, or process broken
# redirs)
action = None
- namespaces = set()
source = set()
+ gen_factory = pagegenerators.GeneratorFactory()
- for arg in pywikibot.handle_args(args):
- arg, sep, value = arg.partition(':')
+ local_args = pywikibot.handle_args(args)
+ for argument in local_args:
+ arg, sep, value = argument.partition(':')
option = arg.partition('-')[2]
# bot options
if arg == 'do':
@@ -689,45 +691,34 @@
gen_options[option] = value or i18n.input(
'pywikibot-enter-xml-filename')
source.add(arg)
- elif option == 'namespace':
- # "-namespace:" does NOT yield -namespace:0 further down the road!
- ns = value or i18n.input('pywikibot-enter-namespace-number')
- # TODO: at least for some generators enter a namespace by its name
- # or number
- if ns == '':
- ns = '0'
- try:
- ns = int(ns)
- except ValueError:
- # -namespace:all Process all namespaces.
- # Only works with the API read interface.
- pass
- else:
- namespaces.add(ns)
elif option == 'offset':
gen_options[option] = int(value)
elif option in ('page', 'start', 'until'):
gen_options[option] = value
elif option == 'limit':
options['limit'] = gen_options['limit'] = int(value)
+ elif gen_factory.handleArg(argument):
+ pass
else:
pywikibot.output('Unknown argument: ' + arg)
- if namespaces:
- gen_options['namespaces'] = namespaces
-
if len(source) > 1:
problem = 'You can only use one of {0} options.'.format(
' or '.join(source))
pywikibot.bot.suggest_help(additional_text=problem,
missing_action=not action)
return
+
if not action:
pywikibot.bot.suggest_help(missing_action=True)
- else:
- options['generator'] = RedirectGenerator(action, **gen_options)
- bot = RedirectRobot(action, **options)
- bot.run()
+ return
+
+ if gen_factory.namespaces:
+ gen_options['namespaces'] = gen_factory.namespaces
+ gen = RedirectGenerator(action, **gen_options)
+ options['generator'] = gen_factory.getCombinedGenerator(gen)
+ bot = RedirectRobot(action, **options)
+ bot.run()
if __name__ == '__main__':
--
To view, visit https://gerrit.wikimedia.org/r/c/pywikibot/core/+/654412
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: Ic6ddd7db06863bd6d918266b38bc1e6bd5744c2e
Gerrit-Change-Number: 654412
Gerrit-PatchSet: 1
Gerrit-Owner: Xqt <[email protected]>
Gerrit-Reviewer: D3r1ck01 <[email protected]>
Gerrit-Reviewer: MarcoAurelio <[email protected]>
Gerrit-Reviewer: Xqt <[email protected]>
Gerrit-Reviewer: jenkins-bot
Gerrit-MessageType: merged
_______________________________________________
Pywikibot-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/pywikibot-commits