jenkins-bot has submitted this change. ( https://gerrit.wikimedia.org/r/c/pywikibot/core/+/758084 )
Change subject: refactor input
......................................................................
refactor input
move 'pywikibot.input' from main
into CategoryAddBot, CategoryListifyRobot, CategoryTidyRobot, CategoryTreeRobot
Change-Id: Ib6fc1fcfc27f5a6e777bec96ab8c790251ea88d2
---
M scripts/category.py
1 file changed, 25 insertions(+), 24 deletions(-)
Approvals:
Xqt: Looks good to me, approved
jenkins-bot: Verified
diff --git a/scripts/category.py b/scripts/category.py
index c396b09..6fa4c2b 100755
--- a/scripts/category.py
+++ b/scripts/category.py
@@ -427,7 +427,8 @@
"""Initializer."""
super().__init__()
self.generator = generator
- self.newcat = newcat
+ self.newcat = newcat or pywikibot.input(
+ 'Category to add (do not give namespace):')
self.sort = sort_by_last_name
self.create = create
self.follow_redirects = follow_redirects
@@ -911,7 +912,8 @@
"""Create a list containing all of the members in a category."""
- def __init__(self, cat_title: str, list_title: str, edit_summary: str,
+ def __init__(self, cat_title: Optional[str], list_title: Optional[str],
+ edit_summary: str,
append: bool = False,
overwrite: bool = False,
show_images: bool = False, *,
@@ -925,7 +927,13 @@
self.overwrite = overwrite
self.show_images = show_images
self.site = pywikibot.Site()
+ if not cat_title:
+ cat_title = pywikibot.input(
+ 'Please enter the name of the category to listify:')
self.cat = pywikibot.Category(self.site, cat_title)
+ if not list_title:
+ list_title = pywikibot.input(
+ 'Please enter the name of the list to create:')
self.list = pywikibot.Page(self.site, list_title)
self.talk_pages = talk_pages
self.recurse = recurse
@@ -998,17 +1006,18 @@
:param comment: a custom summary for edits.
"""
- def __init__(self, cat_title: str, cat_db, namespaces=None,
+ def __init__(self, cat_title: Optional[str], cat_db, namespaces=None,
comment: Optional[str] = None) -> None:
"""Initializer."""
- self.cat_title = cat_title
+ self.cat_title = cat_title or \
+ pywikibot.input('Which category do you want to tidy up?')
self.cat_db = cat_db
self.edit_summary = comment
if not comment:
- self.template_vars = {'oldcat': cat_title}
+ self.template_vars = {'oldcat': self.cat_title}
site = pywikibot.Site()
- self.cat = pywikibot.Category(site, cat_title)
+ self.cat = pywikibot.Category(site, self.cat_title)
super().__init__(generator=pagegenerators.PreloadingGenerator(
self.cat.articles(namespaces=namespaces)))
@@ -1254,8 +1263,15 @@
def __init__(self, cat_title, cat_db, filename=None, max_depth=10) -> None:
"""Initializer."""
- self.cat_title = cat_title
+ self.cat_title = cat_title or \
+ pywikibot.input(
+ 'For which category do you want to create a tree view?')
self.cat_db = cat_db
+ if filename is None:
+ filename = pywikibot.input(
+ 'Please enter the name of the file '
+ 'where the tree should be saved,\n'
+ 'or press enter to simply show the tree:')
if filename and not os.path.isabs(filename):
filename = config.datafilepath(filename)
self.filename = filename
@@ -1514,9 +1530,6 @@
cat_db = CategoryDatabase(rebuild=rebuild)
if action == 'add':
- if not new_cat_title:
- new_cat_title = pywikibot.input(
- 'Category to add (do not give namespace):')
gen = gen_factory.getCombinedGenerator()
if not gen:
# default for backwards compatibility
@@ -1571,23 +1584,11 @@
move_together=move_together,
keep_sortkey=keep_sortkey)
elif action == 'tidy':
- cat_title = pywikibot.input('Which category do you want to tidy up?')
- bot = CategoryTidyRobot(cat_title, cat_db, gen_factory.namespaces,
+ bot = CategoryTidyRobot(old_cat_title, cat_db, gen_factory.namespaces,
summary)
elif action == 'tree':
- cat_title = pywikibot.input(
- 'For which category do you want to create a tree view?')
- filename = pywikibot.input(
- 'Please enter the name of the file where the tree should be saved,'
- '\nor press enter to simply show the tree:')
- bot = CategoryTreeRobot(cat_title, cat_db, filename, depth)
+ bot = CategoryTreeRobot(old_cat_title, cat_db, new_cat_title, depth)
elif action == 'listify':
- if not old_cat_title:
- old_cat_title = pywikibot.input(
- 'Please enter the name of the category to listify:')
- if not new_cat_title:
- new_cat_title = pywikibot.input(
- 'Please enter the name of the list to create:')
bot = CategoryListifyRobot(old_cat_title, new_cat_title, summary,
append, overwrite, showimages,
talk_pages=talkpages,
--
To view, visit https://gerrit.wikimedia.org/r/c/pywikibot/core/+/758084
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: Ib6fc1fcfc27f5a6e777bec96ab8c790251ea88d2
Gerrit-Change-Number: 758084
Gerrit-PatchSet: 3
Gerrit-Owner: Costa Shul <constantine.shulyupin(a)gmail.com>
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/i18n/+/758088 )
Change subject: [i18n] Add CleanBot summary to the i18n system
......................................................................
[i18n] Add CleanBot summary to the i18n system
Change-Id: Iaa2a2db895466659d806b72038f50351d04e4b1d
---
M category/en.json
M category/qqq.json
2 files changed, 2 insertions(+), 1 deletion(-)
Approvals:
Costa Shul: Looks good to me, but someone else must approve
Xqt: Looks good to me, approved
jenkins-bot: Verified
diff --git a/category/en.json b/category/en.json
index 700628b..207314a 100644
--- a/category/en.json
+++ b/category/en.json
@@ -8,7 +8,7 @@
},
"category-adding": "Bot: Adding category [[:Category:%(newcat)s|%(newcat)s]]",
"category-also-in": "(also in %(alsocat)s)",
-
+ "category-clean": "Bot: Removing category %(category)s which is already in %(child)s",
"category-listifying": "Bot: Listifying from %(fromcat)s ({{PLURAL:%(num)d|1 entry|%(num)d entries}})",
"category-removing": "Bot: Removing from %(oldcat)s",
"category-renamed": "Bot: Moved from %(oldcat)s. Authors: %(authors)s",
diff --git a/category/qqq.json b/category/qqq.json
index d14f2b2..1ec2e93 100644
--- a/category/qqq.json
+++ b/category/qqq.json
@@ -14,6 +14,7 @@
},
"category-adding": "{{doc-important|Do not change \":Category:%(newcat)s\" so this message will work in any language.}}",
"category-also-in": "Translations to say that the current category is in more categories than the one we are coming from",
+ "category-clean": "Edit summary when a category is removed because the page is already in child category. Parameters:\n* %(category)s - category name to be removed\n* %(child)s - child category",
"category-listifying": "Definition of [[mw:Manual:Pywikibot/category.py#Syntax|listify]] - make a list of all of the articles that are in a category.\n\n*Variable \"%(fromcat)s\" = the category to make a list of in the listify option.\n*Variable \"%(num)d\" is probably a number.\n*You may use PLURAL tag like (<code><nowiki>{{PLURAL:%(num)d|1 entry|%(num)d entries}}</nowiki></code>)\nDo not translate the variables.",
"category-removing": "Edit summary. Parameters:\n* %(oldcat)s - old category name",
"category-renamed": "Edit summary when a category was renamed.",
--
To view, visit https://gerrit.wikimedia.org/r/c/pywikibot/i18n/+/758088
To unsubscribe, or for help writing mail filters, visit https://gerrit.wikimedia.org/r/settings
Gerrit-Project: pywikibot/i18n
Gerrit-Branch: master
Gerrit-Change-Id: Iaa2a2db895466659d806b72038f50351d04e4b1d
Gerrit-Change-Number: 758088
Gerrit-PatchSet: 1
Gerrit-Owner: Xqt <info(a)gno.de>
Gerrit-Reviewer: Costa Shul <constantine.shulyupin(a)gmail.com>
Gerrit-Reviewer: Xqt <info(a)gno.de>
Gerrit-Reviewer: Zoranzoki21 <zorandori4444(a)gmail.com>
Gerrit-Reviewer: jenkins-bot
Gerrit-MessageType: merged
Xqt has submitted this change. ( https://gerrit.wikimedia.org/r/c/pywikibot/core/+/758083 )
Change subject: [doc] Update logging doc
......................................................................
[doc] Update logging doc
Move comments to docstring
Change-Id: I23dee23fea0bf7986e5fb8effe56ed946c06d4e6
---
M docs/api_ref/pywikibot.rst
M pywikibot/logging.py
2 files changed, 26 insertions(+), 26 deletions(-)
Approvals:
Xqt: Looks good to me, approved
jenkins-bot: Verified
diff --git a/docs/api_ref/pywikibot.rst b/docs/api_ref/pywikibot.rst
index 58aa3b6..4721eeb 100644
--- a/docs/api_ref/pywikibot.rst
+++ b/docs/api_ref/pywikibot.rst
@@ -106,6 +106,7 @@
------------------------
.. automodule:: pywikibot.logging
+ :member-order: bysource
pywikibot.login module
----------------------
diff --git a/pywikibot/logging.py b/pywikibot/logging.py
index 7c2edab..ae4f433 100644
--- a/pywikibot/logging.py
+++ b/pywikibot/logging.py
@@ -1,6 +1,26 @@
-"""Logging functions."""
+"""User output/logging functions.
+
+Six output functions are defined. Each requires a string argument
+All of these functions generate a message to the log file if
+logging is enabled (`-log` or `-debug` command line arguments).
+
+The functions :func:`output()`, :func:`stdout()`, :func:`warning()` and
+:func:`error()` all display a message to the user through the logger
+object; the only difference is the priority level, which can be used by
+the application layer to alter the display. The :func:`stdout()`
+function should be used only for data that is the "result" of a script,
+as opposed to information messages to the user.
+
+The function :func:`log()` by default does not display a message to the
+user, but this can be altered by using the `-verbose` command line
+option.
+
+The function :func:`debug()` only logs its messages, they are never
+displayed on the user console. :func:`debug()` takes a required second
+argument, which is a string indicating the debugging layer.
+"""
#
-# (C) Pywikibot team, 2010-2021
+# (C) Pywikibot team, 2010-2022
#
# Distributed under the terms of the MIT license.
#
@@ -16,9 +36,9 @@
from pywikibot.backports import Callable, List
-STDOUT = 16
-VERBOSE = 18
-INPUT = 25
+STDOUT = 16 #:
+VERBOSE = 18 #:
+INPUT = 25 #:
_init_routines = [] # type: List[Callable[[], Any]]
_inited_routines = set()
@@ -41,27 +61,6 @@
_init_routines[:] = [] # the global variable is used with slice operator
-# User output/logging functions
-
-# Six output functions are defined. Each requires a string argument
-# All of these functions generate a message to the log file if
-# logging is enabled ("-log" or "-debug" command line arguments).
-
-# The functions output(), stdout(), warning(), and error() all display a
-# message to the user through the logger object; the only difference is the
-# priority level, which can be used by the application layer to alter the
-# display. The stdout() function should be used only for data that is
-# the "result" of a script, as opposed to information messages to the
-# user.
-
-# The function log() by default does not display a message to the user, but
-# this can be altered by using the "-verbose" command line option.
-
-# The function debug() only logs its messages, they are never displayed on
-# the user console. debug() takes a required second argument, which is a
-# string indicating the debugging layer.
-
-
def logoutput(text: object, decoder: Optional[str] = None,
newline: bool = True, _level: int = INFO, _logger: str = '',
**kwargs: Any) -> None:
--
To view, visit https://gerrit.wikimedia.org/r/c/pywikibot/core/+/758083
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: I23dee23fea0bf7986e5fb8effe56ed946c06d4e6
Gerrit-Change-Number: 758083
Gerrit-PatchSet: 2
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/+/758079 )
Change subject: refactor old_cat_title, new_cat_title
......................................................................
refactor old_cat_title, new_cat_title
remove from_given, to_given
Change-Id: I655cad2a64609015ce9449ef6f5e942f28924086
---
M scripts/category.py
1 file changed, 7 insertions(+), 10 deletions(-)
Approvals:
Xqt: Looks good to me, approved
jenkins-bot: Verified
diff --git a/scripts/category.py b/scripts/category.py
index 09198b1..c396b09 100755
--- a/scripts/category.py
+++ b/scripts/category.py
@@ -1402,9 +1402,8 @@
:param args: command line arguments.
"""
options = {}
- from_given = False
old_cat_title = None
- to_given = False
+ new_cat_title = None
batch = False
summary = ''
inplace = False
@@ -1456,10 +1455,8 @@
rebuild = True
elif option == 'from':
old_cat_title = value.replace('_', ' ')
- from_given = True
elif option == 'to':
new_cat_title = value.replace('_', ' ')
- to_given = True
elif option == 'batch':
batch = True
elif option == 'inplace':
@@ -1517,7 +1514,7 @@
cat_db = CategoryDatabase(rebuild=rebuild)
if action == 'add':
- if not to_given:
+ if not new_cat_title:
new_cat_title = pywikibot.input(
'Category to add (do not give namespace):')
gen = gen_factory.getCombinedGenerator()
@@ -1535,7 +1532,7 @@
comment=summary,
follow_redirects=follow_redirects)
elif action == 'remove':
- if not from_given:
+ if not old_cat_title:
old_cat_title = pywikibot.input('Please enter the name of the '
'category that should be removed:')
bot = CategoryMoveRobot(oldcat=old_cat_title,
@@ -1548,10 +1545,10 @@
pagesonly=pagesonly,
deletion_comment=use_deletion_summary)
elif action == 'move':
- if not from_given:
+ if not old_cat_title:
old_cat_title = pywikibot.input(
'Please enter the old name of the category:')
- if not to_given:
+ if not new_cat_title:
new_cat_title = pywikibot.input(
'Please enter the new name of the category:')
if use_deletion_summary:
@@ -1585,10 +1582,10 @@
'\nor press enter to simply show the tree:')
bot = CategoryTreeRobot(cat_title, cat_db, filename, depth)
elif action == 'listify':
- if not from_given:
+ if not old_cat_title:
old_cat_title = pywikibot.input(
'Please enter the name of the category to listify:')
- if not to_given:
+ if not new_cat_title:
new_cat_title = pywikibot.input(
'Please enter the name of the list to create:')
bot = CategoryListifyRobot(old_cat_title, new_cat_title, summary,
--
To view, visit https://gerrit.wikimedia.org/r/c/pywikibot/core/+/758079
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: I655cad2a64609015ce9449ef6f5e942f28924086
Gerrit-Change-Number: 758079
Gerrit-PatchSet: 2
Gerrit-Owner: Costa Shul <constantine.shulyupin(a)gmail.com>
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/+/748697 )
Change subject: [IMPR] category clean
......................................................................
[IMPR] category clean
automatically clean specified category
Change-Id: Ibcc96c2c878cc1862e9c0f0e0b7bb94beea1b219
---
M CREDITS.rst
M scripts/category.py
2 files changed, 81 insertions(+), 1 deletion(-)
Approvals:
Xqt: Looks good to me, approved
jenkins-bot: Verified
diff --git a/CREDITS.rst b/CREDITS.rst
index f2e412b..78e0164 100644
--- a/CREDITS.rst
+++ b/CREDITS.rst
@@ -55,6 +55,7 @@
::
CodeCat
+ Costa Shulyupin
Christian List
D
diff --git a/scripts/category.py b/scripts/category.py
index 5e5c3bd..09198b1 100755
--- a/scripts/category.py
+++ b/scripts/category.py
@@ -14,6 +14,7 @@
* tidy - tidy up a category by moving its pages into subcategories.
* tree - show a tree of subcategories of a given category.
* listify - make a list of all of the articles that are in a category.
+ * clean - automatically clean specified category.
and option can be one of these
@@ -66,6 +67,10 @@
-ns -ns:0,2,4
-ns:Help,MediaWiki
+Options for "clean" action:
+
+ -always
+
Options for several actions:
-rebuild - Reset the database.
@@ -1320,6 +1325,74 @@
pywikibot.stdout(tree)
+class CleanBot(Bot):
+
+ """Automatically cleans up specified category.
+
+ Removes redundant grandchildren from specified category by
+ removing direct link to grandparent.
+
+ In another words a grandchildren should not be also a children.
+
+ Stubs categories are exception.
+
+ For details please read:
+ https://en.wikipedia.org/wiki/WP:SUBCAT
+ https://en.wikipedia.org/wiki/WP:DIFFUSE
+
+ """
+
+ update_options = {
+ 'recurse': False
+ }
+
+ def __init__(self, cat: Optional[str], **kwargs) -> None:
+ """Initializer."""
+ site = pywikibot.Site()
+ if not cat:
+ cat = pywikibot.input(
+ 'Please enter the name of the category to clean:')
+ self.cat = pywikibot.Category(site, cat)
+ self.subcats = set(self.cat.subcategories())
+ self.children = self.subcats | set(self.cat.articles())
+ # Using sorted for reproducible data sequence
+ super().__init__(generator=pagegenerators.PreloadingGenerator(
+ sorted(self.subcats)), **kwargs)
+
+ def skip_page(self, cat) -> bool:
+ """Check whether the category should be processed."""
+ return cat.title().endswith('stubs')
+
+ def treat(self, child) -> None:
+ """Process the category."""
+ grandchildren = set(child.articles(self.opt.recurse))
+ # For advanced usage uncomment the next line to
+ # check not only grandchildren articles but
+ # grandchildren categories too:
+ # grandchildren |= set(child.subcategories(self.opt.recurse))
+ overcategorized = sorted(grandchildren & self.children)
+ if not overcategorized:
+ return
+ if config.verbose_output:
+ pywikibot.output('Subcategory "{}" is parent for:'.format(
+ format(child.title(with_ns=False))))
+ for grandchild in overcategorized:
+ pywikibot.output('\t{}'. format(grandchild.title()))
+ for grandchild in overcategorized:
+ pywikibot.output(color_format(
+ 'Remove "{lightpurple}{}{default}" from "{}" '
+ 'because it is already under '
+ 'subcategory "{green}{}{default}"?',
+ grandchild.title(with_ns=False),
+ self.cat.title(with_ns=False), child.title(with_ns=False)))
+ if not self.user_confirm('') or config.simulate:
+ # Treat 'simulate' here to be keep output quiet and nice
+ continue
+ summary = ('Already in [[:{}]]'
+ .format(child.title()))
+ grandchild.change_category(self.cat, None, summary)
+
+
def main(*args: str) -> None:
"""
Process command line arguments and invoke bot.
@@ -1330,6 +1403,7 @@
"""
options = {}
from_given = False
+ old_cat_title = None
to_given = False
batch = False
summary = ''
@@ -1364,7 +1438,8 @@
unknown = []
pg_options = []
for arg in local_args:
- if arg in ('add', 'remove', 'move', 'tidy', 'tree', 'listify'):
+ if arg in ('add', 'remove', 'move', 'tidy', 'tree', 'listify',
+ 'clean'):
action = arg
continue
@@ -1426,6 +1501,8 @@
keep_sortkey = True
elif option == 'prefix':
prefix = value
+ elif option == 'always':
+ options[option] = True
else:
pg_options.append(arg)
@@ -1520,6 +1597,8 @@
recurse=options.get('recurse', False),
prefix=prefix,
namespaces=gen_factory.namespaces)
+ elif action == 'clean':
+ bot = CleanBot(old_cat_title, **options)
if not suggest_help(missing_action=not action):
pywikibot.Site().login()
--
To view, visit https://gerrit.wikimedia.org/r/c/pywikibot/core/+/748697
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: Ibcc96c2c878cc1862e9c0f0e0b7bb94beea1b219
Gerrit-Change-Number: 748697
Gerrit-PatchSet: 35
Gerrit-Owner: Costa Shul <constantine.shulyupin(a)gmail.com>
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/+/758021 )
Change subject: [doc] Update documentation
......................................................................
[doc] Update documentation
* fix typo:
** even -> even if
Change-Id: I6b487284b935c9719edeb1ab6722dff1532aa82f
---
M pwb.py
1 file changed, 1 insertion(+), 1 deletion(-)
Approvals:
Xqt: Looks good to me, approved
jenkins-bot: Verified
diff --git a/pwb.py b/pwb.py
index b5e54e5..ae160c1 100755
--- a/pwb.py
+++ b/pwb.py
@@ -12,7 +12,7 @@
4. Maintenance scripts residing in `scripts/maintenance` (directory mode only).
5. Framework scripts residing in `pywikibot/scripts`.
-This wrapper script is able to invoke scripts even the script name is
+This wrapper script is able to invoke scripts even if the script name is
misspelled. In directory mode it also checks package dependencies.
Run scripts with pywikibot in directory mode using::
--
To view, visit https://gerrit.wikimedia.org/r/c/pywikibot/core/+/758021
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: I6b487284b935c9719edeb1ab6722dff1532aa82f
Gerrit-Change-Number: 758021
Gerrit-PatchSet: 2
Gerrit-Owner: Meno25 <meno25mail(a)gmail.com>
Gerrit-Reviewer: Xqt <info(a)gno.de>
Gerrit-Reviewer: jenkins-bot
Gerrit-MessageType: merged