jenkins-bot has submitted this change and it was merged. ( https://gerrit.wikimedia.org/r/434277 )
Change subject: [bugfix] Fix class handling for category add and tidy ......................................................................
[bugfix] Fix class handling for category add and tidy
Since 765965cb1223e46fee42fc11835b5082105af707 category add and tidy failed completely due to wrong superclass handling
Also: - update error message when editing template which could possibly be categorized using its documentation subpage - handle Nonetype return value
Bug: T195062 Change-Id: I89d962a210b7774d3354c3a8c0c036e2ebce81f0 --- M pywikibot/page.py M scripts/category.py M tests/category_bot_tests.py 3 files changed, 33 insertions(+), 32 deletions(-)
Approvals: Xqt: Looks good to me, approved jenkins-bot: Verified
diff --git a/pywikibot/page.py b/pywikibot/page.py index a132194..c78f629 100644 --- a/pywikibot/page.py +++ b/pywikibot/page.py @@ -2130,8 +2130,12 @@ return False
if oldCat not in cats: - pywikibot.error(u'%s is not in category %s!' - % (self.title(asLink=True), oldCat.title())) + if self.namespace() != 10: + pywikibot.error('%s is not in category %s!' + % (self.title(asLink=True), oldCat.title())) + else: + pywikibot.output('%s is not in category %s, skipping...' + % (self.title(asLink=True), oldCat.title())) return False
# This prevents the bot from adding newCat if it is already present. diff --git a/scripts/category.py b/scripts/category.py index b4fe075..10eca56 100755 --- a/scripts/category.py +++ b/scripts/category.py @@ -172,11 +172,10 @@
"""A class to prepare a list of pages for robots."""
- def __init__(self, page, follow_redirects=False, edit_redirects=False, - create=False): + def __init__(self, follow_redirects=False, edit_redirects=False, + create=False, **kwargs): """Initializer.""" - super(CategoryPreprocess, self).__init__() - page = page + super(CategoryPreprocess, self).__init__(**kwargs) self.follow_redirects = follow_redirects self.edit_redirects = edit_redirects self.create = create @@ -188,7 +187,7 @@ @param page: Existing, missing or redirect page to be processed @type page: pywikibot.Page @return: Page to be categorized - @rtype: pywikibot.Page + @rtype: pywikibot.Page or None """ if page.exists(): if page.isRedirectPage(): @@ -197,37 +196,33 @@ if self.follow_redirects: if redir_target.exists(): return redir_target - elif self.create: + if self.create: redir_target.text = '' pywikibot.output('Redirect target %s does not exist ' 'yet; creating.' % redir_target.title(asLink=True)) return redir_target - elif self.edit_redirects: + if self.edit_redirects: return page - else: - pywikibot.warning('Redirect target %s can not ' - 'be modified; skipping.' - % redir_target.title(asLink=True)) - return - elif self.edit_redirects: + pywikibot.warning('Redirect target %s can not ' + 'be modified; skipping.' + % redir_target.title(asLink=True)) + return None + if self.edit_redirects: return page - else: - pywikibot.warning('Page %s is a redirect to %s; skipping.' - % (page.title(asLink=True), - redir_target.title(asLink=True))) - return - else: - return page - elif self.create: + pywikibot.warning('Page %s is a redirect to %s; skipping.' + % (page.title(asLink=True), + redir_target.title(asLink=True))) + return None + return page + if self.create: page.text = '' pywikibot.output('Page %s does not exist yet; creating.' % page.title(asLink=True)) return page - else: - pywikibot.warning('Page %s does not exist; skipping.' - % page.title(asLink=True)) - return + pywikibot.warning('Page %s does not exist; skipping.' + % page.title(asLink=True)) + return None
def determine_template_target(self, page): """ @@ -451,6 +446,8 @@ """Process one page.""" # find correct categorization target page = self.determine_type_target(page) + if not page: + return self.current_page = self.determine_template_target(page) # load the page text = self.current_page.text diff --git a/tests/category_bot_tests.py b/tests/category_bot_tests.py index 829fb5f..680e4e7 100644 --- a/tests/category_bot_tests.py +++ b/tests/category_bot_tests.py @@ -75,20 +75,20 @@ def test_determine_type_target(self): """Test determining type target.""" page = pywikibot.Page(self.site, 'Template:Doc') - bot = CategoryPreprocess(page, follow_redirects=True) + bot = CategoryPreprocess(follow_redirects=True) bot.site = self.site new_page = bot.determine_type_target(page) expected = pywikibot.Page(self.site, 'Template:Documentation') self.assertEqual(new_page, expected)
page = pywikibot.Page(self.site, 'Template:Doc') - bot = CategoryPreprocess(page) + bot = CategoryPreprocess() bot.site = self.site new_page = bot.determine_type_target(page) self.assertEqual(new_page, None)
page = pywikibot.Page(self.site, 'Template:Baz') - bot = CategoryPreprocess(page) + bot = CategoryPreprocess() bot.site = self.site new_page = bot.determine_type_target(page) self.assertEqual(new_page, None) @@ -96,7 +96,7 @@ def test_determine_template_target(self): """Test determining template target.""" page = pywikibot.Page(self.site, 'Template:Documentation') - bot = CategoryPreprocess(page) + bot = CategoryPreprocess() bot.site = self.site new_page = bot.determine_template_target(page) expected = pywikibot.Page(self.site, 'Template:Documentation/doc') @@ -104,7 +104,7 @@ self.assertEqual(bot.includeonly, ['includeonly'])
page = pywikibot.Page(self.site, 'Template:Branches of chemistry') - bot = CategoryPreprocess(page) + bot = CategoryPreprocess() bot.site = self.site new_page = bot.determine_template_target(page) expected = pywikibot.Page(self.site, 'Template:Branches of chemistry')
pywikibot-commits@lists.wikimedia.org