jenkins-bot has submitted this change and it was merged.
Change subject: Misc script flakes ......................................................................
Misc script flakes
Remove unused variables, remove globals, and in replace.py avoid re-using old & new.
Change-Id: Idf4ff0f72b9b625f3441754d66272b2315b2fd78 --- M scripts/category.py M scripts/commons_link.py M scripts/flickrripper.py M scripts/nowcommons.py M scripts/reflinks.py M scripts/replace.py M scripts/tests/test_data_ingestion.py M scripts/welcome.py 8 files changed, 31 insertions(+), 41 deletions(-)
Approvals: Ladsgroup: Looks good to me, approved jenkins-bot: Verified
diff --git a/scripts/category.py b/scripts/category.py index f0b0ebf..6f143fe 100755 --- a/scripts/category.py +++ b/scripts/category.py @@ -953,8 +953,6 @@
def main(*args): - global catDB - fromGiven = False toGiven = False batchMode = False @@ -1035,10 +1033,15 @@ depth = int(arg[len('-depth:'):]) else: genFactory.handleArg(arg) + pywikibot.Site().login() + + catDB = None + bot = None
catDB = CategoryDatabase(rebuild=rebuild) gen = genFactory.getCombinedGenerator() + if action == 'add': if not gen: # default for backwards compatibility @@ -1049,7 +1052,6 @@ gen = pagegenerators.PreloadingGenerator(gen) bot = AddCategory(gen, sort_by_last_name, create_pages, editSummary, follow_redirects) - bot.run() elif action == 'remove': if not fromGiven: oldCatTitle = pywikibot.input(u'Please enter the name of the ' @@ -1063,7 +1065,6 @@ history=withHistory, pagesonly=pagesonly, deletion_comment=useSummaryForDeletion) - bot.run() elif action == 'move': if not fromGiven: oldCatTitle = pywikibot.input( @@ -1085,11 +1086,9 @@ history=withHistory, pagesonly=pagesonly, deletion_comment=deletion_comment) - bot.run() elif action == 'tidy': catTitle = pywikibot.input(u'Which category do you want to tidy up?') bot = CategoryTidyRobot(catTitle, catDB) - bot.run() elif action == 'tree': catTitle = pywikibot.input( u'For which category do you want to create a tree view?') @@ -1097,7 +1096,6 @@ u'Please enter the name of the file where the tree should be saved,' u'\nor press enter to simply show the tree:') bot = CategoryTreeRobot(catTitle, catDB, filename, depth) - bot.run() elif action == 'listify': if not fromGiven: oldCatTitle = pywikibot.input( @@ -1108,16 +1106,18 @@ bot = CategoryListifyRobot(oldCatTitle, newCatTitle, editSummary, overwrite, showImages, subCats=True, talkPages=talkPages, recurse=recurse) - bot.run() + + if bot: + try: + bot.run() + except pywikibot.Error: + pywikibot.error("Fatal error:", exc_info=True) + finally: + if catDB: + catDB.dump() else: pywikibot.showHelp()
if __name__ == "__main__": - try: - main() - except pywikibot.Error: - pywikibot.error("Fatal error:", exc_info=True) - finally: - if 'catDB' in globals(): - catDB.dump() + main() diff --git a/scripts/commons_link.py b/scripts/commons_link.py index 34a7721..ec761ce 100644 --- a/scripts/commons_link.py +++ b/scripts/commons_link.py @@ -66,7 +66,7 @@ ('Page', 'Category')[catmode] )(commons, page.title()) try: - getcommons = commonspage.get(get_redirect=True) + commonspage.get(get_redirect=True) pagetitle = commonspage.title(withNamespace=not catmode) if page.title() == pagetitle: oldText = page.get() diff --git a/scripts/flickrripper.py b/scripts/flickrripper.py index e9816b9..7446331 100644 --- a/scripts/flickrripper.py +++ b/scripts/flickrripper.py @@ -43,7 +43,10 @@ import upload
import flickrapi # see: http://stuvel.eu/projects/flickrapi -from Tkinter import * +from Tkinter import ( + Tk, Label, Entry, Scrollbar, Text, Button, + END, VERTICAL, NORMAL, WORD +) from PIL import Image, ImageTk # see: http://www.pythonware.com/products/pil/
flickr_allowed_license = { @@ -66,19 +69,16 @@ TODO: Add exception handling
""" - gotPhoto = False - while not gotPhoto: + while True: try: photoInfo = flickr.photos_getInfo(photo_id=photo_id) #xml.etree.ElementTree.dump(photoInfo) photoSizes = flickr.photos_getSizes(photo_id=photo_id) #xml.etree.ElementTree.dump(photoSizes) - gotPhoto = True + return photoInfo, photoSizes except flickrapi.exceptions.FlickrError: - gotPhotos = False pywikibot.output(u'Flickr api problem, sleeping') time.sleep(30) - return photoInfo, photoSizes
def isAllowedLicense(photoInfo=None): @@ -391,8 +391,6 @@ def getPhotos(flickr=None, user_id=u'', group_id=u'', photoset_id=u'', start_id='', end_id='', tags=u''): """ Loop over a set of Flickr photos. """ - result = [] - retry = False found_start_id = not start_id
# https://www.flickr.com/services/api/flickr.groups.pools.getPhotos.html @@ -504,9 +502,6 @@
def main(): - site = pywikibot.Site(u'commons', u'commons') - #imagerecat.initLists() - #Get the api key if not config.flickr['api_key']: pywikibot.output('Flickr api key not found! Get yourself an api key') diff --git a/scripts/nowcommons.py b/scripts/nowcommons.py index 3f2c60e..19de9ac 100644 --- a/scripts/nowcommons.py +++ b/scripts/nowcommons.py @@ -59,7 +59,7 @@ import sys import re import webbrowser -import urllib + import pywikibot from pywikibot import i18n, Bot from pywikibot import pagegenerators as pg @@ -239,8 +239,8 @@ % image_local) pywikibot.output(u'Local: %s\nCommons: %s\n' % (url_local, url_commons)) - result1 = webbrowser.open(url_local, 0, 1) - result2 = webbrowser.open(url_commons, 0, 1) + webbrowser.open(url_local, 0, 1) + webbrowser.open(url_commons, 0, 1) if image_local.split('Image:')[1] == image_commons: choice = pywikibot.inputChoice( u'The local and the commons images have the same name, continue?', diff --git a/scripts/reflinks.py b/scripts/reflinks.py index b62565a..f1fb419 100644 --- a/scripts/reflinks.py +++ b/scripts/reflinks.py @@ -681,7 +681,7 @@ elif u'.zh' in ref.link: enc.append("gbk")
- if not 'utf-8' in enc: + if 'utf-8' not in enc: enc.append('utf-8') u = linkedpagetext.decode(enc[0]) # Bug 67410
diff --git a/scripts/replace.py b/scripts/replace.py index dbac5f8..3bd916a 100755 --- a/scripts/replace.py +++ b/scripts/replace.py @@ -654,8 +654,8 @@ replacements, exceptions) elif useSql: whereClause = 'WHERE (%s)' % ' OR '.join( - ["old_text RLIKE '%s'" % prepareRegexForMySQL(old.pattern) - for (old, new) in replacements]) + ["old_text RLIKE '%s'" % prepareRegexForMySQL(old_regexp.pattern) + for (old_regexp, new_text) in replacements]) if exceptions: exceptClause = 'AND NOT (%s)' % ' OR '.join( ["old_text RLIKE '%s'" % prepareRegexForMySQL(exc.pattern) diff --git a/scripts/tests/test_data_ingestion.py b/scripts/tests/test_data_ingestion.py index 835f04b..36fa0fb 100644 --- a/scripts/tests/test_data_ingestion.py +++ b/scripts/tests/test_data_ingestion.py @@ -6,7 +6,6 @@
import os import unittest -import test_utils import data_ingestion
diff --git a/scripts/welcome.py b/scripts/welcome.py index d7db434..9ea90ea 100644 --- a/scripts/welcome.py +++ b/scripts/welcome.py @@ -862,8 +862,6 @@ return list_loaded
globalvar = Global() -global bot -global filename
def main(): @@ -959,11 +957,6 @@ pywikibot.output("Put welcomed users before quit...") bot.makelogpage(bot.welcomed_users) pywikibot.output("\nQuitting...") - - -if __name__ == "__main__": - try: - main() finally: # If there is the savedata, the script must save the number_user. if globalvar.randomSign and globalvar.saveSignIndex and \ @@ -972,3 +965,6 @@ f = file(filename, 'w') cPickle.dump(bot.welcomed_users, f) f.close() + +if __name__ == "__main__": + main()
pywikibot-commits@lists.wikimedia.org