Mercurial > hg > CommitWatcher
changeset 2:4cb3971d9d9d
commitwatcher/__init__.py commitwatcher/agent.py commitwatcher/main.py setup.py commitwatcher/commit.py commitwatcher/store.py mozbasewatcher.py
author | Jeff Hammel <jhammel@mozilla.com> |
---|---|
date | Thu, 26 Sep 2013 21:35:29 -0700 |
parents | 4e24f3c6610c |
children | 134cdb6a882c |
files | commitwatcher/__init__.py commitwatcher/agent.py commitwatcher/commit.py commitwatcher/main.py commitwatcher/store.py mozbasewatcher.py setup.py |
diffstat | 7 files changed, 101 insertions(+), 3 deletions(-) [+] |
line wrap: on
line diff
--- 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
--- 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()
--- /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 +
--- 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()
--- /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
--- /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()