From 13d9811a2f5868125a40586a3af1414c9fb2dc31 Mon Sep 17 00:00:00 2001 From: Jon Bergli Heier Date: Sat, 29 Aug 2009 20:47:32 +0200 Subject: Detect removal of repos. Use optparse to get LoopingCall interval. Fixed new_paths iterator. --- gitnoti.py | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/gitnoti.py b/gitnoti.py index ece0d02..28e3ffb 100755 --- a/gitnoti.py +++ b/gitnoti.py @@ -11,6 +11,7 @@ parser.add_option('-s', '--host') parser.add_option('-n', '--nick', default = 'git') parser.add_option('-d', '--dir') parser.add_option('-c', '--channel') +parser.add_option('-i', '--interval', type = 'int', default = 30) (options, args) = parser.parse_args() @@ -44,8 +45,14 @@ def check_repos(bot): else: old_paths = [os.path.basename(x[0].path) for x in repos] new_paths = [x for x in repo_paths if not x in old_paths] - for n in new_paths: - repos.append([git.Repo('%s/%s' % (root, x)), None]) + del_paths = [x for x in old_paths if not x in repo_paths] + del_repos = [x for x in repos if os.path.basename(x[0].path) in del_paths] + if del_repos: + bot.gitmsg('Removed repo%s: %s' % ('' if len(del_paths) == 1 else '', ', '.join([os.path.splitext(x)[0] for x in del_paths]))) + for i in del_repos: + repos.remove(i) + for i in new_paths: + repos.append([git.Repo('%s/%s' % (root, i)), None]) if new_paths: bot.gitmsg('New repo%s: %s' % ('' if len(new_paths) == 1 else 's', ', '.join([os.path.splitext(x)[0] for x in new_paths]))) @@ -70,7 +77,7 @@ class Bot(irc.IRCClient): def signedOn(self): self.join(options.channel) self.repeater = LoopingCall(check_repos, self) - self.repeater.start(5) + self.repeater.start(options.interval) def privmsg(self, user, channel, message): private = channel == self.nickname -- cgit v1.2.3