Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions __init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@

import supybot
import supybot.world as world
from imp import reload

# Use this for the version of this plugin. You may wish to put a CVS keyword
# in here if you're keeping the plugin in CVS or some similar system.
Expand All @@ -49,14 +50,14 @@
# This is a url where the most recent plugin package can be downloaded.
__url__ = 'http://github.com/mmueller/supybot-git'

import config
import plugin
from . import config
from . import plugin
reload(plugin) # In case we're being reloaded.
# Add more reloads here if you add third-party modules and want them to be
# reloaded when this plugin is reloaded. Don't forget to import them as well!

if world.testing:
import test
from . import test

Class = plugin.Class
configure = config.configure
Expand Down
37 changes: 20 additions & 17 deletions plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,10 @@
import supybot.log as log
import supybot.world as world

import ConfigParser
try:
import ConfigParser
except ImportError:
import configparser as ConfigParser
from functools import wraps
import os
import threading
Expand Down Expand Up @@ -104,7 +107,7 @@ def __init__(self, repo_dir, long_name, options):
if name not in options:
raise Exception('Section %s missing required value: %s' %
(long_name, name))
for name, value in options.items():
for name, value in list(options.items()):
if name not in required_values and name not in optional_values:
raise Exception('Section %s contains unrecognized value: %s' %
(long_name, name))
Expand Down Expand Up @@ -241,7 +244,7 @@ def format_message(self, commit, format_str=None):
outline = ''
for c in line:
if mode == MODE_SUBST:
if c in subst.keys():
if c in list(subst.keys()):
outline += subst[c]
mode = MODE_NORMAL
elif c == '(':
Expand Down Expand Up @@ -291,7 +294,7 @@ def __init__(self, irc):
self._stop_polling()
try:
self._read_config()
except Exception, e:
except Exception as e:
if 'reply' in dir(irc):
irc.reply('Warning: %s' % str(e))
else:
Expand Down Expand Up @@ -323,7 +326,7 @@ def _log(self, irc, msg, args, channel, name, count):
Display the last commits on the named repository. [count] defaults to
1 if unspecified.
"""
matches = filter(lambda r: r.short_name == name, self.repository_list)
matches = [r for r in self.repository_list if r.short_name == name]
if not matches:
irc.reply('No configured repository named %s.' % name)
return
Expand All @@ -350,16 +353,16 @@ def rehash(self, irc, msg, args):
n = len(self.repository_list)
irc.reply('Git reinitialized with %d %s.' %
(n, plural(n, 'repository')))
except Exception, e:
except Exception as e:
irc.reply('Warning: %s' % str(e))

def repositories(self, irc, msg, args, channel):
"""(takes no arguments)

Display the names of known repositories configured for this channel.
"""
repositories = filter(lambda r: channel in r.channels,
self.repository_list)
repositories = [r for r in self.repository_list if channel in
r.channels]
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suggest splitting the line before the if aligning the if with the [

if not repositories:
irc.reply('No repositories configured for this channel.')
return
Expand Down Expand Up @@ -413,7 +416,7 @@ def _reply_commits(self, irc, channel, repository, commits):
format_str = repository.commit_reply or repository.commit_message
for commit in commits[-commits_at_once:]:
lines = repository.format_message(commit, format_str)
map(irc.reply, lines)
list(map(irc.reply, lines))

def _poll(self):
# Note that polling happens in two steps:
Expand Down Expand Up @@ -448,7 +451,7 @@ def _poll(self):
for irc, channel in targets:
self._display_commits(irc, channel, repository,
commits)
except Exception, e:
except Exception as e:
log_error('Exception in _poll repository %s: %s' %
(repository.short_name, str(e)))
finally:
Expand All @@ -457,7 +460,7 @@ def _poll(self):
log.info('Postponing repository read: %s: Locked.' %
repository.long_name)
self._schedule_next_event()
except Exception, e:
except Exception as e:
log_error('Exception in _poll(): %s' % str(e))
traceback.print_exc(e)

Expand Down Expand Up @@ -489,8 +492,8 @@ def _snarf(self, irc, msg, match):
if self.registryValue('shaSnarfing'):
sha = match.group('sha')
channel = msg.args[0]
repositories = filter(lambda r: channel in r.channels,
self.repository_list)
repositories = [r for r in self.repository_list if channel in
r.channels]
for repository in repositories:
commit = repository.get_commit(sha)
if commit:
Expand All @@ -503,14 +506,14 @@ def _stop_polling(self):
try:
self.fetcher.stop()
self.fetcher.join() # This might take time, but it's safest.
except Exception, e:
except Exception as e:
log_error('Stopping fetcher: %s' % str(e))
self.fetcher = None
try:
schedule.removeEvent(self.name())
except KeyError:
pass
except Exception, e:
except Exception as e:
log_error('Stopping scheduled task: %s' % str(e))

class GitFetcher(threading.Thread):
Expand Down Expand Up @@ -554,14 +557,14 @@ def run(self):
if repository.lock.acquire(blocking=False):
try:
repository.fetch()
except Exception, e:
except Exception as e:
repository.record_error(e)
finally:
repository.lock.release()
else:
log_info('Postponing repository fetch: %s: Locked.' %
repository.long_name)
except Exception, e:
except Exception as e:
log_error('Exception checking repository %s: %s' %
(repository.short_name, str(e)))
# Wait for the next periodic check
Expand Down
2 changes: 1 addition & 1 deletion test.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ def _feedMsgLoop(self, query, timeout=None, **kwargs):
def assertResponses(self, query, expectedResponses, **kwargs):
"Run a command and assert that it returns the given list of replies."
responses = self._feedMsgLoop(query, **kwargs)
responses = map(lambda m: m.args[1], responses)
responses = [m.args[1] for m in responses]
self.assertEqual(responses, expectedResponses,
'\nActual:\n%s\n\nExpected:\n%s' %
('\n'.join(responses), '\n'.join(expectedResponses)))
Expand Down