# HG changeset patch # User Jeff Hammel # Date 1380256529 25200 # Node ID 4cb3971d9d9d67068e147ecba560567c77a078c9 # Parent 4e24f3c6610c4bd2cd827c773deb16ba2d7377c9 commitwatcher/__init__.py commitwatcher/agent.py commitwatcher/main.py setup.py commitwatcher/commit.py commitwatcher/store.py mozbasewatcher.py diff -r 4e24f3c6610c -r 4cb3971d9d9d commitwatcher/__init__.py --- a/commitwatcher/__init__.py Thu Sep 26 05:11:57 2013 -0700 +++ b/commitwatcher/__init__.py Thu Sep 26 21:35:29 2013 -0700 @@ -1,3 +1,4 @@ # from main import * - +from agent import * +from commit import Commit diff -r 4e24f3c6610c -r 4cb3971d9d9d commitwatcher/agent.py --- a/commitwatcher/agent.py Thu Sep 26 05:11:57 2013 -0700 +++ b/commitwatcher/agent.py Thu Sep 26 21:35:29 2013 -0700 @@ -2,11 +2,39 @@ agents to gather commits """ +import feedparser +from .commit import Commit + class Agent(object): """abstract base class""" + def __init__(self, repository, store): + """ + repository -- repo to monitor + """ + self.repository = repository + self.store = store + + class LocalCheckoutAgent(object): """agent based on local checkouts""" + class FeedAgent(Agent): """gathers changesets by reading RSS/Atom""" + + def feed(self): + """feed URL""" + return '/'.join((self.repository.rstrip('/'), 'atom-log')) + + def update(self): + """update""" + + feed = feedparser.parse(self.feed()) + for entry in feedparser['entries']: + + # get paths from diff + link = entry['link'] + # TODO + + commit = Commit() diff -r 4e24f3c6610c -r 4cb3971d9d9d commitwatcher/commit.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/commitwatcher/commit.py Thu Sep 26 21:35:29 2013 -0700 @@ -0,0 +1,14 @@ +""" +commit object model +""" + +class Commit(object): + + def __init__(self, message, datetime, author, paths, link=None, identity=None): + self.message = message + self.datetime = datetime + self.author= author + self.paths = paths + self.link = link + self.identity = identify + diff -r 4e24f3c6610c -r 4cb3971d9d9d commitwatcher/main.py --- a/commitwatcher/main.py Thu Sep 26 05:11:57 2013 -0700 +++ b/commitwatcher/main.py Thu Sep 26 21:35:29 2013 -0700 @@ -10,13 +10,15 @@ import subprocess import sys +from .agent import FeedAgent + def add_options(parser): """add options to the OptionParser instance""" def main(args=sys.argv[1:]): # parse command line options - usage = '%prog [options] ...' + usage = '%prog [options] url://of.repository/' class PlainDescriptionFormatter(optparse.IndentedHelpFormatter): """description formatter for console script entry point""" def format_description(self, description): @@ -26,6 +28,15 @@ return '' parser = optparse.OptionParser(usage=usage, description=__doc__, formatter=PlainDescriptionFormatter()) options, args = parser.parse_args(args) + if len(args) != 1: + parser.error("Please specify a single repository") + # TODO : multiple repos + + repo = args[0] + + # watch the damn thing + watcher = FeedAgent(repository=repo) + watcher.update() if __name__ == '__main__': main() diff -r 4e24f3c6610c -r 4cb3971d9d9d commitwatcher/store.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/commitwatcher/store.py Thu Sep 26 21:35:29 2013 -0700 @@ -0,0 +1,15 @@ +from abc import abstractmethod + +class CommitStore(object): + """ABC for commits""" + + @abstractmethod + def add(self, commit): + """adds a commit to the store""" + +class MemoryStore(CommitStore): + """store in volatile memory""" + # volatile! + + def add(self, commit): + raise NotImplementedError diff -r 4e24f3c6610c -r 4cb3971d9d9d mozbasewatcher.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mozbasewatcher.py Thu Sep 26 21:35:29 2013 -0700 @@ -0,0 +1,26 @@ +#!/usr/bin/env python + +""" +script for watching mozbase + +https://wiki.mozilla.org/Auto-tools/Projects/Mozbase +""" + +import optparse +import os +import sys +from + +here = os.path.dirname(os.path.realpath(__file__)) + +def main(args=sys.argv[1:]): + + usage = '%prog [options]' + parser = optparse.OptionParser(usage=usage, description=__doc__) + options, args = parser.parse_args(args) + + repo = 'http://hg.mozilla.org/mozilla-central' + + +if __name__ == '__main__': + main() diff -r 4e24f3c6610c -r 4cb3971d9d9d setup.py --- a/setup.py Thu Sep 26 05:11:57 2013 -0700 +++ b/setup.py Thu Sep 26 21:35:29 2013 -0700 @@ -5,7 +5,10 @@ import os version = "0.0" -dependencies = ['webob'] +dependencies = ['feedparser', + 'pypatch', + 'webob', + ] # allow use of setuptools/distribute or distutils kw = {}