jenkins-bot has submitted this change and it was merged.
Change subject: Bug 55055: category.py add -to: option
......................................................................
Bug 55055: category.py add -to: option
Feature request: -to: option is now possible not only for "move"
but also for "add".
Some clean-up and naming alignement done as well.
Change-Id: I85d022f3721601583ff3b3535bc81e6df2a0571d
---
M scripts/category.py
1 file changed, 23 insertions(+), 16 deletions(-)
Approvals:
John Vandenberg: Looks good to me, approved
jenkins-bot: Verified
diff --git a/scripts/category.py b/scripts/category.py
index 08588d4..82edeb6 100755
--- a/scripts/category.py
+++ b/scripts/category.py
@@ -242,16 +242,18 @@
"""A robot to mass-add a category to a list of pages."""
- def __init__(self, generator, sort_by_last_name=False, create=False,
- editSummary='', follow_redirects=False, dry=False):
+ @deprecate_arg('editSummary', 'comment')
+ def __init__(self, generator, newcat=None, sort_by_last_name=False,
+ create=False, comment='', follow_redirects=False,
+ dry=False):
self.generator = generator
+ self.newcat = newcat
self.sort = sort_by_last_name
self.create = create
self.follow_redirects = follow_redirects
self.always = False
self.dry = dry
- self.newcatTitle = None
- self.editSummary = editSummary
+ self.comment = comment
def sorted_by_last_name(self, catlink, pagelink):
"""Return a Category with key that sorts persons by their last name.
@@ -285,8 +287,6 @@
return pywikibot.Page(site, catlink.title())
def run(self):
- self.newcatTitle = pywikibot.input(
- u'Category to add (do not give namespace):')
counter = 0
for page in self.generator:
self.treat(page)
@@ -300,7 +300,7 @@
"""
try:
# Load the page
- text = page.get()
+ text = page.text
except pywikibot.NoPage:
if self.create:
pywikibot.output(u"Page %s doesn't exist yet; creating."
@@ -312,17 +312,17 @@
else:
return text
- def save(self, text, page, newcatTitle, minorEdit=True, botflag=True,
old_text=None):
+ def save(self, text, page, newcat, minorEdit=True, botflag=True,
old_text=None):
if old_text is None:
old_text = self.load(page)
# only save if something was changed
if text != old_text:
# show what was changed
pywikibot.showDiff(old_text, text)
- comment = self.editSummary
+ comment = self.comment
if not comment:
comment = i18n.twtranslate(page.site, 'category-adding',
- {'newcat': newcatTitle})
+ {'newcat': newcat})
pywikibot.output(u'Comment: %s' % comment)
if not self.dry:
if not self.always:
@@ -386,10 +386,10 @@
pywikibot.output(u"Current categories:")
for cat in cats:
pywikibot.output(u"* %s" % cat.title())
- newcatTitle = self.newcatTitle
+ newcat = self.newcat
if not page.site.nocapitalize:
- newcatTitle = newcatTitle[:1].upper() + newcatTitle[1:]
- catpl = pywikibot.Page(page.site, newcatTitle, ns=14)
+ newcat = newcat[:1].upper() + newcat[1:]
+ catpl = pywikibot.Page(page.site, newcat, ns=14)
if catpl in cats:
pywikibot.output(u"%s is already in %s."
% (page.title(), catpl.title()))
@@ -399,7 +399,7 @@
pywikibot.output(u'Adding %s' % catpl.title(asLink=True))
cats.append(catpl)
text = textlib.replaceCategoryLinks(text, cats, site=page.site)
- if not self.save(text, page, newcatTitle, old_text=old_text):
+ if not self.save(text, page, newcat, old_text=old_text):
pywikibot.output(u'Page %s not saved.'
% page.title(asLink=True))
@@ -1083,6 +1083,9 @@
gen = genFactory.getCombinedGenerator()
if action == 'add':
+ if not toGiven:
+ newCatTitle = pywikibot.input(
+ u'Category to add (do not give namespace):')
if not gen:
# default for backwards compatibility
genFactory.handleArg('-links')
@@ -1090,8 +1093,12 @@
# The preloading generator is responsible for downloading multiple
# pages from the wiki simultaneously.
gen = pagegenerators.PreloadingGenerator(gen)
- bot = AddCategory(gen, sort_by_last_name, create_pages, editSummary,
- follow_redirects)
+ bot = AddCategory(gen,
+ newcat=newCatTitle,
+ sort_by_last_name=sort_by_last_name,
+ create=create_pages,
+ comment=editSummary,
+ follow_redirects=follow_redirects)
elif action == 'remove':
if not fromGiven:
oldCatTitle = pywikibot.input(u'Please enter the name of the '
--
To view, visit https://gerrit.wikimedia.org/r/155101
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I85d022f3721601583ff3b3535bc81e6df2a0571d
Gerrit-PatchSet: 6
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Owner: Mpaa <[email protected]>
Gerrit-Reviewer: John Vandenberg <[email protected]>
Gerrit-Reviewer: Ladsgroup <[email protected]>
Gerrit-Reviewer: Merlijn van Deen <[email protected]>
Gerrit-Reviewer: Mpaa <[email protected]>
Gerrit-Reviewer: jenkins-bot <>
_______________________________________________
Pywikibot-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/pywikibot-commits