From 1e18c77a228c86e0c4ce3fcbea76178902c9dc8f Mon Sep 17 00:00:00 2001 From: NP-Hardass Date: Tue, 10 Feb 2015 19:32:06 -0500 Subject: [PATCH 1/5] Fix imports --- __init__.py | 6 +++--- plugin.py | 5 ++++- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/__init__.py b/__init__.py index c1106e7..c4e159e 100644 --- a/__init__.py +++ b/__init__.py @@ -49,14 +49,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..8beefb5 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 From f05719ae5fd1726df94f83262a014a523b5768c9 Mon Sep 17 00:00:00 2001 From: NP-Hardass Date: Tue, 10 Feb 2015 19:48:36 -0500 Subject: [PATCH 2/5] Fix list handling --- plugin.py | 16 ++++++++-------- test.py | 2 +- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/plugin.py b/plugin.py index 8beefb5..4ef58f1 100644 --- a/plugin.py +++ b/plugin.py @@ -107,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)) @@ -244,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 == '(': @@ -326,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.shortname == name] if not matches: irc.reply('No configured repository named %s.' % name) return @@ -361,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 @@ -416,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: @@ -492,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: 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))) From b07cca353fe9d080e57687a6c1c1e5f75755ce3f Mon Sep 17 00:00:00 2001 From: NP-Hardass Date: Tue, 10 Feb 2015 20:12:26 -0500 Subject: [PATCH 3/5] Fix exception handling --- plugin.py | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/plugin.py b/plugin.py index 4ef58f1..d65e6f1 100644 --- a/plugin.py +++ b/plugin.py @@ -294,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: @@ -353,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): @@ -451,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: @@ -460,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) @@ -506,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): @@ -557,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 From 14ee6ce829bfacedca754160503213be8bd8a994 Mon Sep 17 00:00:00 2001 From: NP-Hardass Date: Tue, 10 Feb 2015 20:13:14 -0500 Subject: [PATCH 4/5] Fix import of reload --- __init__.py | 1 + 1 file changed, 1 insertion(+) diff --git a/__init__.py b/__init__.py index c4e159e..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. From ac90f9dc3f69b22a585665cc84106779def4f22d Mon Sep 17 00:00:00 2001 From: NP-Hardass Date: Wed, 25 Mar 2015 22:58:24 -0400 Subject: [PATCH 5/5] Fix typo --- plugin.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugin.py b/plugin.py index d65e6f1..722bd77 100644 --- a/plugin.py +++ b/plugin.py @@ -326,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 = [r for r in self.repository_list if r.shortname == name] + 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