jenkins-bot has submitted this change. (
https://gerrit.wikimedia.org/r/c/pywikibot/core/+/660025 )
Change subject: [FEAT] add 'namespaces' option to category 'listify'
......................................................................
[FEAT] add 'namespaces' option to category 'listify'
- Sort the result alphabetically in category listify
- Only include sub-categories when ns is undefined or includes category
- deprecate subCats argument
Change-Id: Ic4f628bf2571f3041de4b97ed07517fbfaf775be
---
M scripts/category.py
1 file changed, 12 insertions(+), 8 deletions(-)
Approvals:
Xqt: Looks good to me, approved
jenkins-bot: Verified
diff --git a/scripts/category.py b/scripts/category.py
index d59fd5a..cc868a0 100755
--- a/scripts/category.py
+++ b/scripts/category.py
@@ -62,7 +62,7 @@
An alternative method to keep sortKey is to use -inplace
option.
-Options for "tidy" action:
+Options for "listify" and "tidy" actions:
-namespaces Filter the arcitles in the specified namespaces. Separate
-namespace multiple namespace numbers or names with commas. Examples:
@@ -894,9 +894,10 @@
"""Create a list containing all of the members in a
category."""
+ @deprecated_args(subCats=True)
def __init__(self, catTitle, listTitle, editSummary, append=False,
- overwrite=False, showImages=False, subCats=False,
- talkPages=False, recurse=False, prefix='*') -> None:
+ overwrite=False, showImages=False, *, talkPages=False,
+ recurse=False, prefix='*', namespaces=None) -> None:
"""Initializer."""
self.editSummary = editSummary
self.append = append
@@ -905,10 +906,11 @@
self.site = pywikibot.Site()
self.cat = pywikibot.Category(self.site, catTitle)
self.list = pywikibot.Page(self.site, listTitle)
- self.subCats = subCats
self.talkPages = talkPages
self.recurse = recurse
self.prefix = prefix
+ self.namespaces = self.site.namespaces.resolve(namespaces or [])
+ self.subCats = not self.namespaces or 'Category' in self.namespaces
def run(self) -> None:
"""Start bot."""
@@ -920,12 +922,13 @@
'-overwrite option to overwrite the output page.'))
return
- set_of_articles = set(self.cat.articles(recurse=self.recurse))
+ set_of_articles = set(self.cat.articles(recurse=self.recurse,
+ namespaces=self.namespaces))
if self.subCats:
set_of_articles |= set(self.cat.subcategories())
list_string = ''
- for article in set_of_articles:
+ for article in sorted(set_of_articles):
textlink = not (article.is_filepage() and self.showImages)
list_string += '{} {}'.format(
self.prefix, article.title(as_link=True, textlink=textlink))
@@ -1498,9 +1501,10 @@
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, subCats=True,
+ append, overwrite, showimages,
talkPages=talkpages, recurse=recurse,
- prefix=prefix)
+ prefix=prefix,
+ namespaces=gen_factory.namespaces)
if bot:
pywikibot.Site().login()
--
To view, visit
https://gerrit.wikimedia.org/r/c/pywikibot/core/+/660025
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: Ic4f628bf2571f3041de4b97ed07517fbfaf775be
Gerrit-Change-Number: 660025
Gerrit-PatchSet: 5
Gerrit-Owner: YFdyh000 <yfdyh000(a)gmail.com>
Gerrit-Reviewer: Xqt <info(a)gno.de>
Gerrit-Reviewer: jenkins-bot
Gerrit-CC: Welcome, new contributor! <ssethi(a)wikimedia.org>
Gerrit-MessageType: merged