jenkins-bot has submitted this change and it was merged.
Change subject: [PEP8] changes
......................................................................
[PEP8] changes
Change-Id: Ib49a06dc3cef0a95eb7c462249b36963f6684119
---
M maintainer.py
M maintcont.py
M match_images.py
M movepages.py
M mysql_autoconnection.py
5 files changed, 121 insertions(+), 82 deletions(-)
Approvals:
Ladsgroup: Looks good to me, approved
jenkins-bot: Verified
diff --git a/maintainer.py b/maintainer.py
index 55d29d9..c55f0c1 100644
--- a/maintainer.py
+++ b/maintainer.py
@@ -7,10 +7,14 @@
Warning: experimental software, use at your own risk
"""
-__version__ = '$Id$'
-
# Author: Balasyum
#
http://hu.wikipedia.org/wiki/User:Balasyum
+# (C) Balasyum, 2008
+# (C) Pywikibot team, 2008-2013
+#
+# Distributed under the terms of the MIT license.
+__version__ = '$Id$'
+#
import random
import thread
@@ -31,6 +35,7 @@
class rcFeeder(SingleServerIRCBot):
+
def __init__(self, channel, nickname, server, port=6667):
SingleServerIRCBot.__init__(self, [(server, port)], nickname, nickname)
self.channel = channel
@@ -48,10 +53,10 @@
def on_pubmsg(self, c, e):
try:
- msg = unicode(e.arguments()[0],'utf-8')
+ msg = unicode(e.arguments()[0], 'utf-8')
except UnicodeDecodeError:
return
- name = msg[8:msg.find(u'14',9)]
+ name = msg[8:msg.find(u'14', 9)]
if 'rciw' in self.tasks:
self.rcbot.addQueue(name)
if 'censure' in self.tasks:
@@ -95,7 +100,7 @@
do = cmd.split()
if do[0] == "accepted":
print "Joined the network"
- thread.start_new_thread(self.activator,())
+ thread.start_new_thread(self.activator, ())
elif do[0] == "tasklist" and len(do) > 1:
self.feed.tasks = do[1].split('|')
diff --git a/maintcont.py b/maintcont.py
index f6562e1..d42299c 100644
--- a/maintcont.py
+++ b/maintcont.py
@@ -8,10 +8,14 @@
Warning: experimental software, use at your own risk
"""
-__version__ = '$Id$'
-
# Author: Balasyum
#
http://hu.wikipedia.org/wiki/User:Balasyum
+# (C) Balasyum, 2008
+# (C) Pywikibot team, 2009-2013
+#
+# Distributed under the terms of the MIT license.
+__version__ = '$Id$'
+#
import externals
externals.check_setup('irclib')
@@ -25,6 +29,7 @@
projtasks = {}
mainters = []
activity = {}
+
class MaintcontBot(SingleServerIRCBot):
def __init__(self, nickname, server, port=6667):
@@ -72,9 +77,9 @@
print "mainter name:", mainter[0], "job:",
mainter[1]
print "--------------------"
print
- time.sleep(1*60)
+ time.sleep(1 * 60)
- def retasker(self, group, optask = ''):
+ def retasker(self, group, optask=''):
ingroup = 0
for mainter in mainters:
if mainter[1] == group:
@@ -92,10 +97,11 @@
if mainter[1] != group:
continue
tts = '|'.join(tpc[int(round(i * tpcn)):int(round((i + 1) * tpcn))])
- if tts != False:
+ if tts:
self.connection.privmsg(mainter[0], "tasklist " + tts)
i += 1
+
def main():
bot = MaintcontBot("maintcont", "irc.freenode.net")
bot.start()
diff --git a/match_images.py b/match_images.py
index c621a4e..56ac171 100644
--- a/match_images.py
+++ b/match_images.py
@@ -1,6 +1,6 @@
#!/usr/bin/python
# -*- coding: utf-8 -*-
-'''
+"""
Program to match two images based on histograms.
Usage:
@@ -9,23 +9,29 @@
This is just a first version so that other people can play around with it.
Expect the code to change a lot!
-'''
+"""
#
-# (C) Multichill, 2009
+# (c) Multichill, 2009
+# (c) pywikibot team, 2009-2013
#
# Distributed under the terms of the MIT license.
#
__version__ = '$Id$'
+#
-import sys, math, StringIO
-import wikipedia, config
+import StringIO
+import wikipedia
+import config
from PIL import Image
+
def matchImagePages(imagePageA, imagePageB):
- '''
+ """
This functions expects two image page objects.
- It will return True if the image are the same and False if the images are not the
same
- '''
+ It will return True if the image are the same and False if the images are
+ not the same
+
+ """
imageA = getImageFromImagePage(imagePageA)
imageB = getImageFromImagePage(imagePageB)
@@ -35,17 +41,23 @@
imageB = imageB.resize((imA_width, imA_height))
- imageA_topleft = imageA.crop((0,0, int(imA_width/2), int(imA_height/2)))
- imageB_topleft = imageB.crop((0,0, int(imA_width/2), int(imA_height/2)))
+ imageA_topleft = imageA.crop((0, 0, int(imA_width / 2), int(imA_height / 2)))
+ imageB_topleft = imageB.crop((0, 0, int(imA_width / 2), int(imA_height / 2)))
- imageA_topright = imageA.crop((int(imA_width/2),0, imA_width, int(imA_height/2)))
- imageB_topright = imageB.crop((int(imA_width/2),0, imA_width, int(imA_height/2)))
+ imageA_topright = imageA.crop((int(imA_width / 2), 0, imA_width,
+ int(imA_height / 2)))
+ imageB_topright = imageB.crop((int(imA_width / 2), 0, imA_width,
+ int(imA_height / 2)))
- imageA_bottomleft = imageA.crop((0, int(imA_height/2), int(imA_width/2),
imA_height))
- imageB_bottomleft = imageB.crop((0, int(imA_height/2), int(imA_width/2),
imA_height))
+ imageA_bottomleft = imageA.crop((0, int(imA_height / 2), int(imA_width / 2),
+ imA_height))
+ imageB_bottomleft = imageB.crop((0, int(imA_height / 2), int(imA_width / 2),
+ imA_height))
- imageA_bottomright = imageA.crop((int(imA_width/2),int(imA_height/2), imA_width,
imA_height))
- imageB_bottomright = imageB.crop((int(imA_width/2),int(imA_height/2), imA_width,
imA_height))
+ imageA_bottomright = imageA.crop((int(imA_width / 2), int(imA_height / 2),
+ imA_width, imA_height))
+ imageB_bottomright = imageB.crop((int(imA_width / 2), int(imA_height / 2),
+ mA_width, imA_height))
imageA_center = imageA.crop((int(imA_width * 0.25), int(imA_height * 0.25),
int(imA_width * 0.75), int(imA_height * 0.75)))
imageB_center = imageB.crop((int(imA_width * 0.25), int(imA_height * 0.25),
int(imA_width * 0.75), int(imA_height * 0.75)))
@@ -56,7 +68,8 @@
bottomleftScore = matchImages(imageA_bottomleft, imageB_bottomleft)
bottomrightScore = matchImages(imageA_bottomright, imageB_bottomright)
centerScore = matchImages(imageA_center, imageB_center)
- averageScore = (wholeScore + topleftScore + toprightScore + bottomleftScore +
bottomrightScore + centerScore)/6
+ averageScore = (wholeScore + topleftScore + toprightScore +
+ bottomleftScore + bottomrightScore + centerScore) / 6
print u'Whole image ' + str(wholeScore)
print u'Top left of image ' + str(topleftScore)
@@ -75,40 +88,37 @@
print u'Not the same.'
return False
+
def getImageFromImagePage(imagePage):
- '''
- Get the image object to work based on an imagePage object
- '''
- imageURL=imagePage.fileUrl()
- imageURLopener= wikipedia.MyURLopener
+ """ Get the image object to work based on an imagePage object
"""
+ imageURL = imagePage.fileUrl()
+ imageURLopener = wikipedia.MyURLopener
imageWebFile = imageURLopener.open(imageURL)
imageBuffer = StringIO.StringIO(imageWebFile.read())
image = Image.open(imageBuffer)
return image
+
def matchImages(imageA, imageB):
- '''
- Match two image objects. Return the ratio of pixels that match
- '''
+ """ Match two image objects. Return the ratio of pixels that match
"""
histogramA = imageA.histogram()
histogramB = imageB.histogram()
totalMatch = 0
totalPixels = 0
- if not (len(histogramA)==len(histogramB)):
+ if not (len(histogramA) == len(histogramB)):
return 0
for i in range(0, len(histogramA)):
totalMatch = totalMatch + min(histogramA[i], histogramB[i])
totalPixels = totalPixels + max(histogramA[i], histogramB[i])
- if (totalPixels==0):
- return 0;
+ if totalPixels == 0:
+ return 0
return float(totalMatch)/float(totalPixels)*100
-
def main():
@@ -149,31 +159,41 @@
else:
images.append(arg)
- if not (len(images)==2):
+ if not (len(images) == 2):
raise wikipedia.Error, 'require two images to work on.'
else:
- imageTitleA=images[0]
- imageTitleB=images[1]
+ imageTitleA = images[0]
+ imageTitleB = images[1]
if not (imageTitleA == u''):
if not (langA == u''):
if not (familyA == u''):
- imagePageA = wikipedia.ImagePage(wikipedia.getSite(langA, familyA),
imageTitleA)
+ imagePageA = wikipedia.ImagePage(wikipedia.getSite(langA,
+ familyA),
+ imageTitleA)
else:
- imagePageA = wikipedia.ImagePage(wikipedia.getSite(langA,
u'wikipedia'), imageTitleA)
+ imagePageA = wikipedia.ImagePage(wikipedia.getSite(langA,
+ u'wikipedia'),
imageTitleA)
else:
- imagePageA = wikipedia.ImagePage(wikipedia.getSite(u'commons',
u'commons'), imageTitleA)
+ imagePageA = wikipedia.ImagePage(wikipedia.getSite(u'commons',
+ u'commons'),
+ imageTitleA)
if not (imageTitleB == u''):
if not (langB == u''):
if not (familyB == u''):
- imagePageB = wikipedia.ImagePage(wikipedia.getSite(langB, familyB),
imageTitleB)
+ imagePageB = wikipedia.ImagePage(wikipedia.getSite(langB,
+ familyB),
+ imageTitleB)
else:
- imagePageB = wikipedia.ImagePage(wikipedia.getSite(langB,
u'wikipedia'), imageTitleB)
+ imagePageB = wikipedia.ImagePage(wikipedia.getSite(langB,
+ u'wikipedia'),
imageTitleB)
else:
- imagePageB = wikipedia.ImagePage(wikipedia.getSite(u'commons',
u'commons'), imageTitleB)
+ imagePageB = wikipedia.ImagePage(wikipedia.getSite(u'commons',
+ u'commons'),
+ imageTitleB)
- if (imagePageA and imagePageB):
+ if imagePageA and imagePageB:
matchImagePages(imagePageA, imagePageB)
diff --git a/movepages.py b/movepages.py
index af29f7b..1f2edf9 100644
--- a/movepages.py
+++ b/movepages.py
@@ -32,15 +32,16 @@
#
# (C) Leonardo Gregianin, 2006
# (C) Andreas J. Schwab, 2007
-# (C) Pywikipedia bot team, 2006-2013
+# (C) Pywikibot team, 2006-2013
#
# Distributed under the terms of the MIT license.
#
+__version__ = '$Id$'
+#
-__version__='$Id$'
-
-import sys, re
-import wikipedia as pywikibot
+import sys
+import re
+import pywikibot
from pywikibot import i18n
import pagegenerators
@@ -147,7 +148,7 @@
u'Change the page title to "%s"?'
% newPageTitle, ['yes', 'no', 'all',
'quit'],
['y', 'n', 'a', 'q'])
- if choice2 == 'y':
+ if choice2 == 'y':
self.moveOne(page, newPageTitle)
elif choice2 == 'a':
self.appendAll = True
@@ -162,7 +163,7 @@
searchPattern = pywikibot.input(u'Enter the search pattern:')
self.replacePattern = pywikibot.input(
u'Enter the replace pattern:')
- self.regex=re.compile(searchPattern)
+ self.regex = re.compile(searchPattern)
if page.title() == page.title(withNamespace=False):
newPageTitle = self.regex.sub(self.replacePattern,
page.title())
diff --git a/mysql_autoconnection.py b/mysql_autoconnection.py
index 23d13ff..7116dd9 100644
--- a/mysql_autoconnection.py
+++ b/mysql_autoconnection.py
@@ -5,14 +5,18 @@
reconnect them.
"""
#
-# (C) Bryan Tong Minh, 2007
+# (c) Bryan Tong Minh, 2007
+# (c) pywikibot team, 2008-2013
#
# Distributed under the terms of the MIT license.
#
__version__ = '$Id$'
+#
-import MySQLdb, MySQLdb.cursors
+import MySQLdb
+import MySQLdb.cursors
import time
+
class Connection(object):
"""A wrapper to the MySQLdb database and cursor object.
@@ -20,17 +24,17 @@
into one object.
"""
RECOVERABLE_ERRORS = (
- 1040, # Too many connections
- 1152, # Aborted connection
- 2002, # Connection error
- 2003, # Can't connect
- 2006, # Server gone
- 2013, # Server lost
- 2014, # Commands out of sync
- )
+ 1040, # Too many connections
+ 1152, # Aborted connection
+ 2002, # Connection error
+ 2003, # Can't connect
+ 2006, # Server gone
+ 2013, # Server lost
+ 2014, # Commands out of sync
+ )
- def __init__(self, retry_timeout = 60, max_retries = -1,
- callback = lambda *args: None, *conn_args, **conn_kwargs):
+ def __init__(self, retry_timeout=60, max_retries=-1,
+ callback=lambda *args: None, *conn_args, **conn_kwargs):
self.retry_timeout = retry_timeout
self.max_retries = max_retries
@@ -51,6 +55,7 @@
self.callback(self)
time.sleep(self.current_retry * self.retry_timeout)
self.current_retry += 1
+
def __call(self, (object, function_name), *args, **kwargs):
try:
return getattr(object, function_name)(*args, **kwargs)
@@ -89,7 +94,7 @@
except:
pass
- def cursor(self, cursorclass = MySQLdb.cursors.Cursor):
+ def cursor(self, cursorclass=MySQLdb.cursors.Cursor):
if type(cursorclass) is not type(self.__cursor):
self.__cursor = self.database.cursor(cursorclass)
return self
@@ -97,6 +102,7 @@
# Mimic cursor object
def __iter__(self):
return self.__cursor.__iter__()
+
def __getattr__(self, name, *args, **kwargs):
if hasattr(self.database, name):
obj = self.database
@@ -109,22 +115,26 @@
class CallWrapper(object):
+
def __init__(self, executor, function):
self.__executor = executor
self.__function = function
+
def __call__(self, *args, **kwargs):
- return self.__executor(self.__function,
- *args, **kwargs)
+ return self.__executor(self.__function, *args, **kwargs)
+
def __getattr__(self, name):
getattr(self.__function, name)
-def connect(retry_timeout = 60, max_retries = -1,
- callback = lambda *args: None, *conn_args, **conn_kwargs):
- return Connection(retry_timeout = retry_timeout,
- max_retries = max_retries,
- callback = callback,
- *conn_args, **conn_kwargs)
+def connect(retry_timeout=60, max_retries=-1,
+ callback=lambda *args: None, *conn_args, **conn_kwargs):
+
+ return Connection(retry_timeout=retry_timeout,
+ max_retries=max_retries,
+ callback=callback,
+ *conn_args, **conn_kwargs)
+
if __name__ == '__main__':
def callback(conn):
@@ -134,8 +144,8 @@
username = raw_input('Username: ')
password = raw_input('Password: ')
- conn = connect(retry_timeout = 5, max_retries = 4, callback = callback,
- host = host, user = username, passwd = password, charset = 'utf8')
+ conn = connect(retry_timeout=5, max_retries=4, callback=callback,
+ host=host, user=username, passwd=password, charset='utf8')
cur = conn.cursor()
print 'Connected!'
conn.execute('SELECT 1')
@@ -159,6 +169,3 @@
print conn.fetchall()
print 'Query ok!'
raw_input()
-
-
-
--
To view, visit
https://gerrit.wikimedia.org/r/103245
To unsubscribe, visit
https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: Ib49a06dc3cef0a95eb7c462249b36963f6684119
Gerrit-PatchSet: 1
Gerrit-Project: pywikibot/compat
Gerrit-Branch: master
Gerrit-Owner: Xqt <info(a)gno.de>
Gerrit-Reviewer: Ladsgroup <ladsgroup(a)gmail.com>
Gerrit-Reviewer: jenkins-bot