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):