jenkins-bot has submitted this change and it was merged. (
https://gerrit.wikimedia.org/r/512124 )
Change subject: [cleanup] Avoid deeply nested control flow in imagerecat.py
......................................................................
[cleanup] Avoid deeply nested control flow in imagerecat.py
Problem reported by
codeclimate.com
Change-Id: I1dc2b28f83309f89d747666144ec53b4b40bef54
---
M scripts/imagerecat.py
1 file changed, 24 insertions(+), 23 deletions(-)
Approvals:
Dalba: Looks good to me, approved
jenkins-bot: Verified
diff --git a/scripts/imagerecat.py b/scripts/imagerecat.py
index 2edf9d6..6e66b08 100755
--- a/scripts/imagerecat.py
+++ b/scripts/imagerecat.py
@@ -80,31 +80,32 @@
"""
for page in generator:
- if page.exists() and (page.namespace() == 6) and \
- (not page.isRedirectPage()):
- imagepage = pywikibot.FilePage(page.site, page.title())
- pywikibot.output('Working on ' + imagepage.title())
+ if not page.exists() or page.namespace() != 6 or page.isRedirectPage():
+ continue
- if (onlyUncat and not pywikibot.Page(
- imagepage.site, 'Template:Uncategorized')
- in imagepage.templates()):
- pywikibot.output('No Uncategorized template found')
- else:
- currentCats = getCurrentCats(imagepage)
- if onlyFilter:
- commonshelperCats = []
- usage = []
- galleries = []
- else:
- (commonshelperCats, usage,
- galleries) = getCommonshelperCats(imagepage)
- newcats = applyAllFilters(commonshelperCats + currentCats)
+ imagepage = pywikibot.FilePage(page.site, page.title())
+ pywikibot.output('Working on ' + imagepage.title())
- if len(newcats) > 0 and not(set(currentCats) == set(newcats)):
- for cat in newcats:
- pywikibot.output(' Found new cat: ' + cat)
- saveImagePage(imagepage, newcats, usage, galleries,
- onlyFilter)
+ if (onlyUncat and not pywikibot.Page(
+ imagepage.site, 'Template:Uncategorized')
+ in imagepage.templates()):
+ pywikibot.output('No Uncategorized template found')
+ continue
+
+ currentCats = getCurrentCats(imagepage)
+ if onlyFilter:
+ commonshelperCats = []
+ usage = []
+ galleries = []
+ else:
+ (commonshelperCats, usage,
+ galleries) = getCommonshelperCats(imagepage)
+ newcats = applyAllFilters(commonshelperCats + currentCats)
+
+ if newcats and set(currentCats) != set(newcats):
+ for cat in newcats:
+ pywikibot.output(' Found new cat: ' + cat)
+ saveImagePage(imagepage, newcats, usage, galleries, onlyFilter)
def getCurrentCats(imagepage):
--
To view, visit
https://gerrit.wikimedia.org/r/512124
To unsubscribe, or for help writing mail filters, visit
https://gerrit.wikimedia.org/r/settings
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-MessageType: merged
Gerrit-Change-Id: I1dc2b28f83309f89d747666144ec53b4b40bef54
Gerrit-Change-Number: 512124
Gerrit-PatchSet: 1
Gerrit-Owner: Xqt <info(a)gno.de>
Gerrit-Reviewer: D3r1ck01 <xsavitar.wiki(a)aol.com>
Gerrit-Reviewer: Dalba <dalba.wiki(a)gmail.com>
Gerrit-Reviewer: John Vandenberg <jayvdb(a)gmail.com>
Gerrit-Reviewer: jenkins-bot (75)