Merge "Use flake8 instead pep8."
This commit is contained in:
commit
07f4eddf7c
|
@ -58,7 +58,7 @@ import yaml
|
||||||
try:
|
try:
|
||||||
import daemon.pidlockfile
|
import daemon.pidlockfile
|
||||||
pid_file_module = daemon.pidlockfile
|
pid_file_module = daemon.pidlockfile
|
||||||
except:
|
except Exception:
|
||||||
# as of python-daemon 1.6 it doesn't bundle pidlockfile anymore
|
# as of python-daemon 1.6 it doesn't bundle pidlockfile anymore
|
||||||
# instead it depends on lockfile-0.9.1
|
# instead it depends on lockfile-0.9.1
|
||||||
import daemon.pidfile
|
import daemon.pidfile
|
||||||
|
@ -68,9 +68,8 @@ except:
|
||||||
class GerritBot(irc.bot.SingleServerIRCBot):
|
class GerritBot(irc.bot.SingleServerIRCBot):
|
||||||
def __init__(self, channels, nickname, password, server, port=6667,
|
def __init__(self, channels, nickname, password, server, port=6667,
|
||||||
server_password=None):
|
server_password=None):
|
||||||
irc.bot.SingleServerIRCBot.__init__(self,
|
irc.bot.SingleServerIRCBot.__init__(
|
||||||
[(server, port, server_password)],
|
self, [(server, port, server_password)], nickname, nickname)
|
||||||
nickname, nickname)
|
|
||||||
self.channel_list = channels
|
self.channel_list = channels
|
||||||
self.nickname = nickname
|
self.nickname = nickname
|
||||||
self.password = password
|
self.password = password
|
||||||
|
@ -118,12 +117,12 @@ class Gerrit(threading.Thread):
|
||||||
# Import here because it needs to happen after daemonization
|
# Import here because it needs to happen after daemonization
|
||||||
import gerritlib.gerrit
|
import gerritlib.gerrit
|
||||||
try:
|
try:
|
||||||
self.gerrit = gerritlib.gerrit.Gerrit(self.server, self.username,
|
self.gerrit = gerritlib.gerrit.Gerrit(
|
||||||
self.port, self.keyfile)
|
self.server, self.username, self.port, self.keyfile)
|
||||||
self.gerrit.startWatching()
|
self.gerrit.startWatching()
|
||||||
self.log.info('Start watching Gerrit event stream.')
|
self.log.info('Start watching Gerrit event stream.')
|
||||||
self.connected = True
|
self.connected = True
|
||||||
except:
|
except Exception:
|
||||||
self.log.exception('Exception while connecting to gerrit')
|
self.log.exception('Exception while connecting to gerrit')
|
||||||
self.connected = False
|
self.connected = False
|
||||||
# Delay before attempting again.
|
# Delay before attempting again.
|
||||||
|
@ -147,9 +146,9 @@ class Gerrit(threading.Thread):
|
||||||
self.ircbot.send(channel, msg)
|
self.ircbot.send(channel, msg)
|
||||||
|
|
||||||
for approval in data.get('approvals', []):
|
for approval in data.get('approvals', []):
|
||||||
if (approval['type'] == 'VRIF' and approval['value'] == '-2' and
|
if (approval['type'] == 'VRIF' and approval['value'] == '-2'
|
||||||
channel in self.channel_config.events.get(
|
and channel in self.channel_config.events.get(
|
||||||
'x-vrif-minus-2', set())):
|
'x-vrif-minus-2', set())):
|
||||||
msg = 'Verification of a change to %s failed: %s %s' % (
|
msg = 'Verification of a change to %s failed: %s %s' % (
|
||||||
data['change']['project'],
|
data['change']['project'],
|
||||||
data['change']['subject'],
|
data['change']['subject'],
|
||||||
|
@ -157,9 +156,9 @@ class Gerrit(threading.Thread):
|
||||||
self.log.info('Compiled Message %s: %s' % (channel, msg))
|
self.log.info('Compiled Message %s: %s' % (channel, msg))
|
||||||
self.ircbot.send(channel, msg)
|
self.ircbot.send(channel, msg)
|
||||||
|
|
||||||
if (approval['type'] == 'VRIF' and approval['value'] == '2' and
|
if (approval['type'] == 'VRIF' and approval['value'] == '2'
|
||||||
channel in self.channel_config.events.get(
|
and channel in self.channel_config.events.get(
|
||||||
'x-vrif-plus-2', set())):
|
'x-vrif-plus-2', set())):
|
||||||
msg = 'Verification of a change to %s succeeded: %s %s' % (
|
msg = 'Verification of a change to %s succeeded: %s %s' % (
|
||||||
data['change']['project'],
|
data['change']['project'],
|
||||||
data['change']['subject'],
|
data['change']['subject'],
|
||||||
|
@ -167,9 +166,9 @@ class Gerrit(threading.Thread):
|
||||||
self.log.info('Compiled Message %s: %s' % (channel, msg))
|
self.log.info('Compiled Message %s: %s' % (channel, msg))
|
||||||
self.ircbot.send(channel, msg)
|
self.ircbot.send(channel, msg)
|
||||||
|
|
||||||
if (approval['type'] == 'CRVW' and approval['value'] == '-2' and
|
if (approval['type'] == 'CRVW' and approval['value'] == '-2'
|
||||||
channel in self.channel_config.events.get(
|
and channel in self.channel_config.events.get(
|
||||||
'x-crvw-minus-2', set())):
|
'x-crvw-minus-2', set())):
|
||||||
msg = 'A change to %s has been rejected: %s %s' % (
|
msg = 'A change to %s has been rejected: %s %s' % (
|
||||||
data['change']['project'],
|
data['change']['project'],
|
||||||
data['change']['subject'],
|
data['change']['subject'],
|
||||||
|
@ -177,9 +176,9 @@ class Gerrit(threading.Thread):
|
||||||
self.log.info('Compiled Message %s: %s' % (channel, msg))
|
self.log.info('Compiled Message %s: %s' % (channel, msg))
|
||||||
self.ircbot.send(channel, msg)
|
self.ircbot.send(channel, msg)
|
||||||
|
|
||||||
if (approval['type'] == 'CRVW' and approval['value'] == '2' and
|
if (approval['type'] == 'CRVW' and approval['value'] == '2'
|
||||||
channel in self.channel_config.events.get(
|
and channel in self.channel_config.events.get(
|
||||||
'x-crvw-plus-2', set())):
|
'x-crvw-plus-2', set())):
|
||||||
msg = 'A change to %s has been approved: %s %s' % (
|
msg = 'A change to %s has been approved: %s %s' % (
|
||||||
data['change']['project'],
|
data['change']['project'],
|
||||||
data['change']['subject'],
|
data['change']['subject'],
|
||||||
|
@ -198,17 +197,17 @@ class Gerrit(threading.Thread):
|
||||||
def _read(self, data):
|
def _read(self, data):
|
||||||
try:
|
try:
|
||||||
channel_set = (self.channel_config.projects.get(
|
channel_set = (self.channel_config.projects.get(
|
||||||
data['change']['project'], set()) &
|
data['change']['project'], set()) &
|
||||||
self.channel_config.events.get(
|
self.channel_config.events.get(
|
||||||
data['type'], set()) &
|
data['type'], set()) &
|
||||||
self.channel_config.branches.get(
|
self.channel_config.branches.get(
|
||||||
data['change']['branch'], set()))
|
data['change']['branch'], set()))
|
||||||
except KeyError:
|
except KeyError:
|
||||||
# The data we care about was not present, no channels want
|
# The data we care about was not present, no channels want
|
||||||
# this event.
|
# this event.
|
||||||
channel_set = set()
|
channel_set = set()
|
||||||
self.log.info('Potential channels to receive event notification: %s' %
|
self.log.info('Potential channels to receive event notification: %s' %
|
||||||
channel_set)
|
channel_set)
|
||||||
for channel in channel_set:
|
for channel in channel_set:
|
||||||
if data['type'] == 'comment-added':
|
if data['type'] == 'comment-added':
|
||||||
self.comment_added(channel, data)
|
self.comment_added(channel, data)
|
||||||
|
@ -225,7 +224,7 @@ class Gerrit(threading.Thread):
|
||||||
event = self.gerrit.getEvent()
|
event = self.gerrit.getEvent()
|
||||||
self.log.info('Received event: %s' % event)
|
self.log.info('Received event: %s' % event)
|
||||||
self._read(event)
|
self._read(event)
|
||||||
except:
|
except Exception:
|
||||||
self.log.exception('Exception encountered in event loop')
|
self.log.exception('Exception encountered in event loop')
|
||||||
if not self.gerrit.watcher_thread.is_alive():
|
if not self.gerrit.watcher_thread.is_alive():
|
||||||
# Start new gerrit connection. Don't need to restart IRC
|
# Start new gerrit connection. Don't need to restart IRC
|
||||||
|
@ -296,7 +295,7 @@ def main():
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
pid = pid_file_module.TimeoutPIDLockFile(
|
pid = pid_file_module.TimeoutPIDLockFile(
|
||||||
"/var/run/gerritbot/gerritbot.pid", 10)
|
"/var/run/gerritbot/gerritbot.pid", 10)
|
||||||
with daemon.DaemonContext(pidfile=pid):
|
with daemon.DaemonContext(pidfile=pid):
|
||||||
_main()
|
_main()
|
||||||
|
|
||||||
|
|
|
@ -1,10 +1,4 @@
|
||||||
distribute>=0.6.24
|
distribute>=0.6.24
|
||||||
|
|
||||||
mock
|
hacking>=0.5.4,<0.6
|
||||||
nose
|
|
||||||
nose-exclude
|
|
||||||
nosexcover
|
|
||||||
openstack.nose_plugin
|
|
||||||
pep8==1.1
|
|
||||||
sphinx>=1.1.2
|
sphinx>=1.1.2
|
||||||
unittest2
|
|
||||||
|
|
23
tox.ini
23
tox.ini
|
@ -1,28 +1,19 @@
|
||||||
[tox]
|
[tox]
|
||||||
envlist = py26,py27,pep8
|
envlist = pep8
|
||||||
|
|
||||||
[testenv]
|
[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
|
deps = -r{toxinidir}/tools/pip-requires
|
||||||
-r{toxinidir}/tools/test-requires
|
-r{toxinidir}/tools/test-requires
|
||||||
commands = nosetests {posargs}
|
|
||||||
|
|
||||||
[testenv:pep8]
|
[testenv:pep8]
|
||||||
deps = pep8==1.1
|
commands = flake8
|
||||||
commands = pep8 --repeat --show-source --exclude=.venv,.tox,dist,doc,*.egg .
|
|
||||||
|
|
||||||
[testenv:cover]
|
|
||||||
setenv = NOSE_WITH_COVERAGE=1
|
|
||||||
|
|
||||||
[testenv:pyflakes]
|
[testenv:pyflakes]
|
||||||
deps = pyflakes
|
commands = flake8
|
||||||
commands = pyflakes gerritbot/bot.py setup.py
|
|
||||||
|
|
||||||
[testenv:venv]
|
[testenv:venv]
|
||||||
commands = {posargs}
|
commands = {posargs}
|
||||||
|
|
||||||
|
[flake8]
|
||||||
|
show-source = True
|
||||||
|
exclude = .venv,.tox,dist,doc,*.egg
|
||||||
|
|
Loading…
Reference in New Issue