view commitwatcher/agent.py @ 11:546695da018c

commitwatcher/agent.py tests/unit.py
author Jeff Hammel <jhammel@mozilla.com>
date Sat, 28 Sep 2013 05:15:59 -0700
parents 7ae60d2ff1c2
children a0ff003319ec
line wrap: on
line source

"""
agents to gather commits
"""

import feedparser
import pypatch
from abc import abstractmethod
from .commit import Commit
from .store import MemoryStore

class Agent(object):
    """abstract base class"""

    def __init__(self, repository, store=None):
        """
        repository -- repo to monitor
        """
        self.repository = repository
        self.store = MemoryStore() if store is None else 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'))

    @abstractmethod
    def files(self, revision):
        """gets the files from the revision link"""

    def update(self):
        """update"""

        feed = feedparser.parse(self.feed())
        for entry in feed['entries']:

            link = entry['link']
            files = self.files(link)
            # TODO

            # TODO            commit = Commit()

class FeedAgentDiff(FeedAgent):
    """read files from diff"""

    @staticmethod
    def lsdiff(diff):
        
        
    def diff_url(self, link):
        """
        returns diff_url from revision link:

        >>> diff_url('http://hg.mozilla.org/mozilla-central/rev/4e1a3919e741')
        'http://hg.mozilla.org/mozilla-central/raw-rev/4e1a3919e741'
        """
        return '/raw-rev/'.join(link.rsplit('/rev/', 1))

    def files(self, revision):
        """
        revision -- revision link
        """

        raw_rev = self.diff_url(revision)
        print raw_rev

        # get paths from diff