Xqt submitted this change.

View Change

Approvals: jenkins-bot: Verified Xqt: Looks good to me, approved
Removed the BadTitle Exception from certain files

Removed the BadTitle Exception from commonscat.py
and redirect.py

Bug: T267768
Change-Id: I2e72637c1c04e373ab94de2d624ec56aeba0928a
---
M scripts/commonscat.py
M scripts/redirect.py
2 files changed, 23 insertions(+), 50 deletions(-)

diff --git a/scripts/commonscat.py b/scripts/commonscat.py
index 50cb0af..1ef48f1 100755
--- a/scripts/commonscat.py
+++ b/scripts/commonscat.py
@@ -372,28 +372,21 @@
for ipageLink in page.langlinks():
ipage = pywikibot.page.Page(ipageLink)
pywikibot.log('Looking for template on ' + ipage.title())
- try:
- if (not ipage.exists() or ipage.isRedirectPage()
- or ipage.isDisambig()):
- continue
+ if (not ipage.exists() or ipage.isRedirectPage()
+ or ipage.isDisambig()):
+ continue

- commonscatLink = self.getCommonscatLink(ipage)
- if not commonscatLink:
- continue
+ commonscatLink = self.getCommonscatLink(ipage)
+ if not commonscatLink:
+ continue

- checkedCommonscat = self.checkCommonscatLink(
- commonscatLink[1])
-
- if checkedCommonscat:
- pywikibot.output(
- 'Found link for {} at [[{}:{}]] to {}.'
- .format(page.title(), ipage.site.code, ipage.title(),
- checkedCommonscat))
- return checkedCommonscat
-
- except pywikibot.BadTitle:
- # The interwiki was incorrect
- break
+ checkedCommonscat = self.checkCommonscatLink(commonscatLink[1])
+ if checkedCommonscat:
+ pywikibot.output(
+ 'Found link for {} at [[{}:{}]] to {}.'
+ .format(page.title(), ipage.site.code, ipage.title(),
+ checkedCommonscat))
+ return checkedCommonscat
return ''

def find_commons_category(self, page) -> str:
@@ -453,13 +446,7 @@
"""
pywikibot.log('getCommonscat: ' + name)
commonsSite = self.site.image_repository()
-
- try:
- # This can throw a pywikibot.BadTitle
- commonsPage = pywikibot.Page(commonsSite, 'Category:' + name)
- except pywikibot.BadTitle:
- # Funky title so not correct
- return ''
+ commonsPage = pywikibot.Page(commonsSite, 'Category:' + name)

if not commonsPage.exists():
pywikibot.output('Commons category does not exist. '
@@ -488,19 +475,19 @@
.format(commonsPage, loguser, logcomment))
return ''
return ''
- elif commonsPage.isRedirectPage():
+
+ if commonsPage.isRedirectPage():
pywikibot.log('getCommonscat: The category is a redirect')
return self.checkCommonscatLink(
commonsPage.getRedirectTarget().title(with_ns=False))
- elif (pywikibot.Page(commonsPage.site,
- 'Template:Category redirect') in commonsPage.templates()):
+
+ if (pywikibot.Page(commonsPage.site, 'Template:Category redirect')
+ in commonsPage.templates()):
pywikibot.log(
'getCommonscat: The category is a category redirect')
for template in commonsPage.templatesWithParams():
- if (
- template[0].title(with_ns=False) == 'Category redirect'
- and len(template[1]) > 0
- ):
+ if (template[0].title(with_ns=False) == 'Category redirect'
+ and len(template[1]) > 0):
return self.checkCommonscatLink(template[1][0])
elif commonsPage.isDisambig():
pywikibot.log('getCommonscat: The category is disambiguation')
diff --git a/scripts/redirect.py b/scripts/redirect.py
index b72fac5..3628b4f 100755
--- a/scripts/redirect.py
+++ b/scripts/redirect.py
@@ -369,7 +369,7 @@
try:
if not moved_page.isRedirectPage():
continue
- except (pywikibot.BadTitle, pywikibot.ServerError):
+ except pywikibot.ServerError:
continue
# moved_page is now a redirect, so any redirects pointing
# to it need to be changed
@@ -492,10 +492,6 @@
else:
try:
targetPage.get()
- except pywikibot.BadTitle as e:
- pywikibot.warning(
- 'Redirect target {0} is not a valid page title.'
- .format(str(e)[10:]))
except pywikibot.InvalidTitle:
pywikibot.exception()
except pywikibot.NoPage:
@@ -576,12 +572,6 @@
pywikibot.exception()
pywikibot.output('Skipping {0}.'.format(newRedir))
break
- except pywikibot.BadTitle as e:
- # str(e) is in the format 'BadTitle: [[Foo]]'
- pywikibot.warning(
- 'Redirect target {0} is not a valid page title.'
- .format(str(e)[10:]))
- break
except pywikibot.NoPage:
if self.opt.always:
pywikibot.output(
@@ -634,11 +624,7 @@
else:
newRedir = targetPage
continue
- try:
- oldText = redir.get(get_redirect=True)
- except pywikibot.BadTitle:
- pywikibot.output('Bad Title Error')
- break
+ oldText = redir.get(get_redirect=True)
if self.is_repo and redir.namespace() == self.repo.item_namespace:
redir = pywikibot.ItemPage(self.repo, redir.title())
targetPage = pywikibot.ItemPage(self.repo, targetPage.title())

To view, visit change 642031. To unsubscribe, or for help writing mail filters, visit settings.

Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Change-Id: I2e72637c1c04e373ab94de2d624ec56aeba0928a
Gerrit-Change-Number: 642031
Gerrit-PatchSet: 7
Gerrit-Owner: Homeboy 445 <akshitsan13@gmail.com>
Gerrit-Reviewer: D3r1ck01 <xsavitar.wiki@aol.com>
Gerrit-Reviewer: Xqt <info@gno.de>
Gerrit-Reviewer: jenkins-bot
Gerrit-MessageType: merged