view commitwatcher/store.py @ 21:be7090ee7738

wip
author Jeff Hammel <jhammel@mozilla.com>
date Sun, 29 Sep 2013 20:32:42 -0700
parents a8e21cfda5fe
children f82d43bcb24e
line wrap: on
line source

from abc import abstractmethod

__all__ = ['CommitStore', 'MemoryStore']

class CommitStore(object):
    """
    ABC for commits
    """

    @abstractmethod
    def add(self, commit):
        """adds a commit to the store"""

    @abstractmethod
    def paths(self, *commits):
        """return all paths touched for a given commit"""

    def ancestry(self, path):
        sep = '/' # unix/url-style separators
        path = path.split('/')
        paths = []
        while path:
            paths.append(sep.join(path))
            path.pop()
        return paths


class MemoryStore(CommitStore):
    """store in volatile memory"""
    # volatile!

    def __init__(self):
        self.path_to_commit = {}

    def add(self, commit):
        raise NotImplementedError()

    def paths(self, *commits):
        """
        return paths touched by commits
        """

        paths = set()
        for commit in commits:
            for f in commit.files:

                raise NotImplementedError