annotate commitwatcher/store.py @ 45:32cf3d3469c3 default tip

assert
author Jeff Hammel <jhammel@mozilla.com>
date Thu, 07 Nov 2013 14:19:06 -0800
parents ef90a853afd1
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
38
Jeff Hammel <jhammel@mozilla.com>
parents: 31
diff changeset
1 """
Jeff Hammel <jhammel@mozilla.com>
parents: 31
diff changeset
2 storage classes for commits and related data
Jeff Hammel <jhammel@mozilla.com>
parents: 31
diff changeset
3 """
Jeff Hammel <jhammel@mozilla.com>
parents: 31
diff changeset
4
2
4cb3971d9d9d commitwatcher/__init__.py commitwatcher/agent.py commitwatcher/main.py setup.py commitwatcher/commit.py commitwatcher/store.py mozbasewatcher.py
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
5 from abc import abstractmethod
4cb3971d9d9d commitwatcher/__init__.py commitwatcher/agent.py commitwatcher/main.py setup.py commitwatcher/commit.py commitwatcher/store.py mozbasewatcher.py
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
6
6
883c88b13142 commitwatcher/agent.py commitwatcher/store.py mozbasewatcher.py
Jeff Hammel <jhammel@mozilla.com>
parents: 5
diff changeset
7 __all__ = ['CommitStore', 'MemoryStore']
883c88b13142 commitwatcher/agent.py commitwatcher/store.py mozbasewatcher.py
Jeff Hammel <jhammel@mozilla.com>
parents: 5
diff changeset
8
2
4cb3971d9d9d commitwatcher/__init__.py commitwatcher/agent.py commitwatcher/main.py setup.py commitwatcher/commit.py commitwatcher/store.py mozbasewatcher.py
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
9 class CommitStore(object):
5
d85093ba9f45 commitwatcher/store.py
Jeff Hammel <jhammel@mozilla.com>
parents: 2
diff changeset
10 """
39
Jeff Hammel <jhammel@mozilla.com>
parents: 38
diff changeset
11 ABC for commit storage
5
d85093ba9f45 commitwatcher/store.py
Jeff Hammel <jhammel@mozilla.com>
parents: 2
diff changeset
12 """
2
4cb3971d9d9d commitwatcher/__init__.py commitwatcher/agent.py commitwatcher/main.py setup.py commitwatcher/commit.py commitwatcher/store.py mozbasewatcher.py
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
13
39
Jeff Hammel <jhammel@mozilla.com>
parents: 38
diff changeset
14 def __init__(self, verbose=True, events=None):
30
4c53f4cc6ffe commitwatcher/commit.py commitwatcher/store.py
Jeff Hammel <jhammel@mozilla.com>
parents: 24
diff changeset
15 self.verbose = verbose
39
Jeff Hammel <jhammel@mozilla.com>
parents: 38
diff changeset
16 self.events = events
30
4c53f4cc6ffe commitwatcher/commit.py commitwatcher/store.py
Jeff Hammel <jhammel@mozilla.com>
parents: 24
diff changeset
17
2
4cb3971d9d9d commitwatcher/__init__.py commitwatcher/agent.py commitwatcher/main.py setup.py commitwatcher/commit.py commitwatcher/store.py mozbasewatcher.py
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
18 @abstractmethod
30
4c53f4cc6ffe commitwatcher/commit.py commitwatcher/store.py
Jeff Hammel <jhammel@mozilla.com>
parents: 24
diff changeset
19 def __contains__(self, revision):
4c53f4cc6ffe commitwatcher/commit.py commitwatcher/store.py
Jeff Hammel <jhammel@mozilla.com>
parents: 24
diff changeset
20 """if a particular revision is already added"""
4c53f4cc6ffe commitwatcher/commit.py commitwatcher/store.py
Jeff Hammel <jhammel@mozilla.com>
parents: 24
diff changeset
21
4c53f4cc6ffe commitwatcher/commit.py commitwatcher/store.py
Jeff Hammel <jhammel@mozilla.com>
parents: 24
diff changeset
22 @abstractmethod
4c53f4cc6ffe commitwatcher/commit.py commitwatcher/store.py
Jeff Hammel <jhammel@mozilla.com>
parents: 24
diff changeset
23 def store(self, commit):
4c53f4cc6ffe commitwatcher/commit.py commitwatcher/store.py
Jeff Hammel <jhammel@mozilla.com>
parents: 24
diff changeset
24 """store a commit"""
4c53f4cc6ffe commitwatcher/commit.py commitwatcher/store.py
Jeff Hammel <jhammel@mozilla.com>
parents: 24
diff changeset
25
2
4cb3971d9d9d commitwatcher/__init__.py commitwatcher/agent.py commitwatcher/main.py setup.py commitwatcher/commit.py commitwatcher/store.py mozbasewatcher.py
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
26 def add(self, commit):
4cb3971d9d9d commitwatcher/__init__.py commitwatcher/agent.py commitwatcher/main.py setup.py commitwatcher/commit.py commitwatcher/store.py mozbasewatcher.py
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
27 """adds a commit to the store"""
30
4c53f4cc6ffe commitwatcher/commit.py commitwatcher/store.py
Jeff Hammel <jhammel@mozilla.com>
parents: 24
diff changeset
28 if commit.revision not in self:
4c53f4cc6ffe commitwatcher/commit.py commitwatcher/store.py
Jeff Hammel <jhammel@mozilla.com>
parents: 24
diff changeset
29 return
4c53f4cc6ffe commitwatcher/commit.py commitwatcher/store.py
Jeff Hammel <jhammel@mozilla.com>
parents: 24
diff changeset
30 self.store(commit)
2
4cb3971d9d9d commitwatcher/__init__.py commitwatcher/agent.py commitwatcher/main.py setup.py commitwatcher/commit.py commitwatcher/store.py mozbasewatcher.py
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
31
43
ef90a853afd1 stubbing
Jeff Hammel <jhammel@mozilla.com>
parents: 42
diff changeset
32 def paths(self):
31
3edb91cfd3c1 move to ABC
Jeff Hammel <jhammel@mozilla.com>
parents: 30
diff changeset
33 """
3edb91cfd3c1 move to ABC
Jeff Hammel <jhammel@mozilla.com>
parents: 30
diff changeset
34 return paths touched by commits
3edb91cfd3c1 move to ABC
Jeff Hammel <jhammel@mozilla.com>
parents: 30
diff changeset
35 """
3edb91cfd3c1 move to ABC
Jeff Hammel <jhammel@mozilla.com>
parents: 30
diff changeset
36
3edb91cfd3c1 move to ABC
Jeff Hammel <jhammel@mozilla.com>
parents: 30
diff changeset
37 paths = set()
3edb91cfd3c1 move to ABC
Jeff Hammel <jhammel@mozilla.com>
parents: 30
diff changeset
38 for commit in commits:
3edb91cfd3c1 move to ABC
Jeff Hammel <jhammel@mozilla.com>
parents: 30
diff changeset
39 for f in commit.files:
3edb91cfd3c1 move to ABC
Jeff Hammel <jhammel@mozilla.com>
parents: 30
diff changeset
40 paths.update(self.ancestry(f))
3edb91cfd3c1 move to ABC
Jeff Hammel <jhammel@mozilla.com>
parents: 30
diff changeset
41 return paths
3edb91cfd3c1 move to ABC
Jeff Hammel <jhammel@mozilla.com>
parents: 30
diff changeset
42
5
d85093ba9f45 commitwatcher/store.py
Jeff Hammel <jhammel@mozilla.com>
parents: 2
diff changeset
43
2
4cb3971d9d9d commitwatcher/__init__.py commitwatcher/agent.py commitwatcher/main.py setup.py commitwatcher/commit.py commitwatcher/store.py mozbasewatcher.py
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
44 class MemoryStore(CommitStore):
4cb3971d9d9d commitwatcher/__init__.py commitwatcher/agent.py commitwatcher/main.py setup.py commitwatcher/commit.py commitwatcher/store.py mozbasewatcher.py
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
45 """store in volatile memory"""
4cb3971d9d9d commitwatcher/__init__.py commitwatcher/agent.py commitwatcher/main.py setup.py commitwatcher/commit.py commitwatcher/store.py mozbasewatcher.py
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
46 # volatile!
4cb3971d9d9d commitwatcher/__init__.py commitwatcher/agent.py commitwatcher/main.py setup.py commitwatcher/commit.py commitwatcher/store.py mozbasewatcher.py
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
47
39
Jeff Hammel <jhammel@mozilla.com>
parents: 38
diff changeset
48 def __init__(self, *args, **kwargs):
Jeff Hammel <jhammel@mozilla.com>
parents: 38
diff changeset
49 CommitStore.__init__(self, *args, **kwargs)
20
Jeff Hammel <jhammel@mozilla.com>
parents: 6
diff changeset
50 self.path_to_commit = {}
22
f82d43bcb24e commitwatcher/store.py
Jeff Hammel <jhammel@mozilla.com>
parents: 21
diff changeset
51 self._commits = []
20
Jeff Hammel <jhammel@mozilla.com>
parents: 6
diff changeset
52
31
3edb91cfd3c1 move to ABC
Jeff Hammel <jhammel@mozilla.com>
parents: 30
diff changeset
53 def store(self, commit):
3edb91cfd3c1 move to ABC
Jeff Hammel <jhammel@mozilla.com>
parents: 30
diff changeset
54 paths = self.paths(commit)
3edb91cfd3c1 move to ABC
Jeff Hammel <jhammel@mozilla.com>
parents: 30
diff changeset
55 for path in paths:
38
Jeff Hammel <jhammel@mozilla.com>
parents: 31
diff changeset
56 self.path_to_commit.set_default(path, []).append(commit)
Jeff Hammel <jhammel@mozilla.com>
parents: 31
diff changeset
57 raise NotImplementedError
5
d85093ba9f45 commitwatcher/store.py
Jeff Hammel <jhammel@mozilla.com>
parents: 2
diff changeset
58