jenkins-bot has submitted this change and it was merged.
Change subject: Add ignore templates for 'pt' lang to commonscat.py
......................................................................
Add ignore templates for 'pt' lang to commonscat.py
Also:
- fixed pep257 docstrings
- refactored findCommonscatLink
Bug: 68941
Change-Id: I0c7d4956897d57a527a27fca90b9d456ada8c3c8
---
M scripts/commonscat.py
1 file changed, 30 insertions(+), 18 deletions(-)
Approvals:
John Vandenberg: Looks good to me, approved
jenkins-bot: Verified
diff --git a/scripts/commonscat.py b/scripts/commonscat.py
index 1d89b7c..ad004f6 100755
--- a/scripts/commonscat.py
+++ b/scripts/commonscat.py
@@ -204,7 +204,11 @@
'nl': [u'Commons', u'Commonsklein', u'Commonscatklein', u'Catbeg',
u'Catsjab', u'Catwiki'],
'om': [u'Commons'],
- 'pt': [u'Correlatos'],
+ 'pt': [u'Correlatos',
+ u'Commons',
+ u'Commons cat multi',
+ u'Commons1',
+ u'Commons2'],
'simple': [u'Sisterlinks'],
'ru': [u'Навигация', u'Навигация для категорий', u'КПР', u'КБР',
u'Годы в России', u'commonscat-inline'],
@@ -240,6 +244,7 @@
"""Commons categorisation bot."""
def __init__(self, generator, always, summary=None):
+ """Constructor."""
super(CommonscatBot, self).__init__(always=always)
self.generator = generator
self.summary = summary
@@ -400,25 +405,32 @@
% (page.title(), error.url))
def findCommonscatLink(self, page=None):
- # In Pywikibot 2.0, page.interwiki() now returns Link objects, not
Page objects
+ """Find CommonsCat template on interwiki pages.
+
+ In Pywikibot 2.0, page.interwiki() now returns Link objects,
+ not Page objects
+
+ @rtype: unicode, name of a valid commons category
+ """
for ipageLink in page.langlinks():
ipage = pywikibot.page.Page(ipageLink)
pywikibot.log("Looking for template on %s" % (ipage.title()))
try:
- if(ipage.exists() and not ipage.isRedirectPage()
- and not ipage.isDisambig()):
- commonscatLink = self.getCommonscatLink(ipage)
- if commonscatLink:
- (currentTemplate,
- possibleCommonscat, linkText, Note) = commonscatLink
- checkedCommonscat = self.checkCommonscatLink(
- possibleCommonscat)
- if (checkedCommonscat != u''):
- pywikibot.output(
- u"Found link for %s at [[%s:%s]] to %s."
- % (page.title(), ipage.site.code,
- ipage.title(), checkedCommonscat))
- return checkedCommonscat
+ if(not ipage.exists() or ipage.isRedirectPage()
+ or ipage.isDisambig()):
+ continue
+ commonscatLink = self.getCommonscatLink(ipage)
+ if not commonscatLink:
+ continue
+ (currentTemplate,
+ possibleCommonscat, linkText, Note) = commonscatLink
+ checkedCommonscat =
self.checkCommonscatLink(possibleCommonscat)
+ if (checkedCommonscat != u''):
+ pywikibot.output(
+ u"Found link for %s at [[%s:%s]] to %s."
+ % (page.title(), ipage.site.code,
+ ipage.title(), checkedCommonscat))
+ return checkedCommonscat
except pywikibot.BadTitle:
#The interwiki was incorrect
return u''
@@ -427,7 +439,7 @@
def getCommonscatLink(self, wikipediaPage=None):
"""Find CommonsCat template on page.
- @rtype: tuple of (<templatename>, <target>)
+ @rtype: tuple of (<templatename>, <target>, <linktext>, <note>)
"""
primaryCommonscat, commonscatAlternatives = self.getCommonscatTemplate(
wikipediaPage.site.code)
@@ -457,7 +469,7 @@
""" Return the name of a valid commons category.
If the page is a redirect this function tries to follow it.
- If the page doesnt exists the function will return an empty string
+ If the page doesn't exists the function will return an empty string
"""
pywikibot.log("getCommonscat: " + name)
--
To view, visit https://gerrit.wikimedia.org/r/173498
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I0c7d4956897d57a527a27fca90b9d456ada8c3c8
Gerrit-PatchSet: 1
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: jenkins-bot <>
_______________________________________________
Pywikibot-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/pywikibot-commits