Merge "Use flake8 instead pep8."

This commit is contained in:
Jenkins 2013-06-20 16:50:26 +00:00 committed by Gerrit Code Review
commit 07f4eddf7c
3 changed files with 34 additions and 50 deletions

View File

@ -58,7 +58,7 @@ import yaml
try:
import daemon.pidlockfile
pid_file_module = daemon.pidlockfile
except:
except Exception:
# as of python-daemon 1.6 it doesn't bundle pidlockfile anymore
# instead it depends on lockfile-0.9.1
import daemon.pidfile
@ -68,9 +68,8 @@ except:
class GerritBot(irc.bot.SingleServerIRCBot):
def __init__(self, channels, nickname, password, server, port=6667,
server_password=None):
irc.bot.SingleServerIRCBot.__init__(self,
[(server, port, server_password)],
nickname, nickname)
irc.bot.SingleServerIRCBot.__init__(
self, [(server, port, server_password)], nickname, nickname)
self.channel_list = channels
self.nickname = nickname
self.password = password
@ -118,12 +117,12 @@ class Gerrit(threading.Thread):
# Import here because it needs to happen after daemonization
import gerritlib.gerrit
try:
self.gerrit = gerritlib.gerrit.Gerrit(self.server, self.username,
self.port, self.keyfile)
self.gerrit = gerritlib.gerrit.Gerrit(
self.server, self.username, self.port, self.keyfile)
self.gerrit.startWatching()
self.log.info('Start watching Gerrit event stream.')
self.connected = True
except:
except Exception:
self.log.exception('Exception while connecting to gerrit')
self.connected = False
# Delay before attempting again.
@ -147,9 +146,9 @@ class Gerrit(threading.Thread):
self.ircbot.send(channel, msg)
for approval in data.get('approvals', []):
if (approval['type'] == 'VRIF' and approval['value'] == '-2' and
channel in self.channel_config.events.get(
'x-vrif-minus-2', set())):
if (approval['type'] == 'VRIF' and approval['value'] == '-2'
and channel in self.channel_config.events.get(
'x-vrif-minus-2', set())):
msg = 'Verification of a change to %s failed: %s %s' % (
data['change']['project'],
data['change']['subject'],
@ -157,9 +156,9 @@ class Gerrit(threading.Thread):
self.log.info('Compiled Message %s: %s' % (channel, msg))
self.ircbot.send(channel, msg)
if (approval['type'] == 'VRIF' and approval['value'] == '2' and
channel in self.channel_config.events.get(
'x-vrif-plus-2', set())):
if (approval['type'] == 'VRIF' and approval['value'] == '2'
and channel in self.channel_config.events.get(
'x-vrif-plus-2', set())):
msg = 'Verification of a change to %s succeeded: %s %s' % (
data['change']['project'],
data['change']['subject'],
@ -167,9 +166,9 @@ class Gerrit(threading.Thread):
self.log.info('Compiled Message %s: %s' % (channel, msg))
self.ircbot.send(channel, msg)
if (approval['type'] == 'CRVW' and approval['value'] == '-2' and
channel in self.channel_config.events.get(
'x-crvw-minus-2', set())):
if (approval['type'] == 'CRVW' and approval['value'] == '-2'
and channel in self.channel_config.events.get(
'x-crvw-minus-2', set())):
msg = 'A change to %s has been rejected: %s %s' % (
data['change']['project'],
data['change']['subject'],
@ -177,9 +176,9 @@ class Gerrit(threading.Thread):
self.log.info('Compiled Message %s: %s' % (channel, msg))
self.ircbot.send(channel, msg)
if (approval['type'] == 'CRVW' and approval['value'] == '2' and
channel in self.channel_config.events.get(
'x-crvw-plus-2', set())):
if (approval['type'] == 'CRVW' and approval['value'] == '2'
and channel in self.channel_config.events.get(
'x-crvw-plus-2', set())):
msg = 'A change to %s has been approved: %s %s' % (
data['change']['project'],
data['change']['subject'],
@ -198,17 +197,17 @@ class Gerrit(threading.Thread):
def _read(self, data):
try:
channel_set = (self.channel_config.projects.get(
data['change']['project'], set()) &
self.channel_config.events.get(
data['type'], set()) &
self.channel_config.branches.get(
data['change']['branch'], set()))
data['change']['project'], set()) &
self.channel_config.events.get(
data['type'], set()) &
self.channel_config.branches.get(
data['change']['branch'], set()))
except KeyError:
# The data we care about was not present, no channels want
# this event.
channel_set = set()
self.log.info('Potential channels to receive event notification: %s' %
channel_set)
channel_set)
for channel in channel_set:
if data['type'] == 'comment-added':
self.comment_added(channel, data)
@ -225,7 +224,7 @@ class Gerrit(threading.Thread):
event = self.gerrit.getEvent()
self.log.info('Received event: %s' % event)
self._read(event)
except:
except Exception:
self.log.exception('Exception encountered in event loop')
if not self.gerrit.watcher_thread.is_alive():
# Start new gerrit connection. Don't need to restart IRC
@ -296,7 +295,7 @@ def main():
sys.exit(1)
pid = pid_file_module.TimeoutPIDLockFile(
"/var/run/gerritbot/gerritbot.pid", 10)
"/var/run/gerritbot/gerritbot.pid", 10)
with daemon.DaemonContext(pidfile=pid):
_main()

View File

@ -1,10 +1,4 @@
distribute>=0.6.24
mock
nose
nose-exclude
nosexcover
openstack.nose_plugin
pep8==1.1
hacking>=0.5.4,<0.6
sphinx>=1.1.2
unittest2

23
tox.ini
View File

@ -1,28 +1,19 @@
[tox]
envlist = py26,py27,pep8
envlist = pep8
[testenv]
setenv = VIRTUAL_ENV={envdir}
NOSE_WITH_OPENSTACK=1
NOSE_OPENSTACK_COLOR=1
NOSE_OPENSTACK_RED=0.05
NOSE_OPENSTACK_YELLOW=0.025
NOSE_OPENSTACK_SHOW_ELAPSED=1
NOSE_OPENSTACK_STDOUT=1
deps = -r{toxinidir}/tools/pip-requires
-r{toxinidir}/tools/test-requires
commands = nosetests {posargs}
[testenv:pep8]
deps = pep8==1.1
commands = pep8 --repeat --show-source --exclude=.venv,.tox,dist,doc,*.egg .
[testenv:cover]
setenv = NOSE_WITH_COVERAGE=1
commands = flake8
[testenv:pyflakes]
deps = pyflakes
commands = pyflakes gerritbot/bot.py setup.py
commands = flake8
[testenv:venv]
commands = {posargs}
[flake8]
show-source = True
exclude = .venv,.tox,dist,doc,*.egg