diff --git a/__init__.py b/__init__.py index c1106e7..c3ad226 100644 --- a/__init__.py +++ b/__init__.py @@ -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. @@ -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 diff --git a/plugin.py b/plugin.py index 37dcf67..722bd77 100644 --- a/plugin.py +++ b/plugin.py @@ -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 @@ -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)) @@ -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 == '(': @@ -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: @@ -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 @@ -350,7 +353,7 @@ 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): @@ -358,8 +361,8 @@ def repositories(self, irc, msg, args, channel): 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] if not repositories: irc.reply('No repositories configured for this channel.') return @@ -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: @@ -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: @@ -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) @@ -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: @@ -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): @@ -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 diff --git a/test.py b/test.py index 4d949e8..078ecaa 100644 --- a/test.py +++ b/test.py @@ -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)))