Mercurial > hg > CommitWatcher
annotate commitwatcher/store.py @ 38:035368f84847
indent
| author | Jeff Hammel <jhammel@mozilla.com> | 
|---|---|
| date | Mon, 04 Nov 2013 23:20:32 -0800 | 
| parents | 3edb91cfd3c1 | 
| children | b04538e7f9f3 | 
| rev | line source | 
|---|---|
| 38 | 1 """ | 
| 2 storage classes for commits and related data | |
| 3 """ | |
| 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 | 10 """ | 
| 11 ABC for commits | |
| 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 | 
| 
30
 
4c53f4cc6ffe
commitwatcher/commit.py commitwatcher/store.py
 
Jeff Hammel <jhammel@mozilla.com> 
parents: 
24 
diff
changeset
 | 
14 def __init__(self, verbose=True): | 
| 
 
4c53f4cc6ffe
commitwatcher/commit.py commitwatcher/store.py
 
Jeff Hammel <jhammel@mozilla.com> 
parents: 
24 
diff
changeset
 | 
15 self.verbose = verbose | 
| 
 
4c53f4cc6ffe
commitwatcher/commit.py commitwatcher/store.py
 
Jeff Hammel <jhammel@mozilla.com> 
parents: 
24 
diff
changeset
 | 
16 | 
| 
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
 | 
17 @abstractmethod | 
| 
30
 
4c53f4cc6ffe
commitwatcher/commit.py commitwatcher/store.py
 
Jeff Hammel <jhammel@mozilla.com> 
parents: 
24 
diff
changeset
 | 
18 def __contains__(self, revision): | 
| 
 
4c53f4cc6ffe
commitwatcher/commit.py commitwatcher/store.py
 
Jeff Hammel <jhammel@mozilla.com> 
parents: 
24 
diff
changeset
 | 
19 """if a particular revision is already added""" | 
| 
 
4c53f4cc6ffe
commitwatcher/commit.py commitwatcher/store.py
 
Jeff Hammel <jhammel@mozilla.com> 
parents: 
24 
diff
changeset
 | 
20 | 
| 
 
4c53f4cc6ffe
commitwatcher/commit.py commitwatcher/store.py
 
Jeff Hammel <jhammel@mozilla.com> 
parents: 
24 
diff
changeset
 | 
21 @abstractmethod | 
| 
 
4c53f4cc6ffe
commitwatcher/commit.py commitwatcher/store.py
 
Jeff Hammel <jhammel@mozilla.com> 
parents: 
24 
diff
changeset
 | 
22 def store(self, commit): | 
| 
 
4c53f4cc6ffe
commitwatcher/commit.py commitwatcher/store.py
 
Jeff Hammel <jhammel@mozilla.com> 
parents: 
24 
diff
changeset
 | 
23 """store a commit""" | 
| 
 
4c53f4cc6ffe
commitwatcher/commit.py commitwatcher/store.py
 
Jeff Hammel <jhammel@mozilla.com> 
parents: 
24 
diff
changeset
 | 
24 | 
| 
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
 | 
25 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
 | 
26 """adds a commit to the store""" | 
| 
30
 
4c53f4cc6ffe
commitwatcher/commit.py commitwatcher/store.py
 
Jeff Hammel <jhammel@mozilla.com> 
parents: 
24 
diff
changeset
 | 
27 if commit.revision not in self: | 
| 
 
4c53f4cc6ffe
commitwatcher/commit.py commitwatcher/store.py
 
Jeff Hammel <jhammel@mozilla.com> 
parents: 
24 
diff
changeset
 | 
28 return | 
| 
 
4c53f4cc6ffe
commitwatcher/commit.py commitwatcher/store.py
 
Jeff Hammel <jhammel@mozilla.com> 
parents: 
24 
diff
changeset
 | 
29 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
 | 
30 | 
| 5 | 31 @abstractmethod | 
| 32 def paths(self, *commits): | |
| 33 """return all paths touched for a given commit""" | |
| 34 | |
| 20 | 35 def ancestry(self, path): | 
| 36 sep = '/' # unix/url-style separators | |
| 37 path = path.split('/') | |
| 38 paths = [] | |
| 39 while path: | |
| 40 paths.append(sep.join(path)) | |
| 41 path.pop() | |
| 42 return paths | |
| 43 | |
| 31 | 44 def paths(self, *commits): | 
| 45 """ | |
| 46 return paths touched by commits | |
| 47 """ | |
| 48 | |
| 49 paths = set() | |
| 50 for commit in commits: | |
| 51 for f in commit.files: | |
| 52 paths.update(self.ancestry(f)) | |
| 53 return paths | |
| 54 | |
| 5 | 55 | 
| 
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
 | 
56 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
 | 
57 """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
 | 
58 # 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
 | 
59 | 
| 20 | 60 def __init__(self): | 
| 61 self.path_to_commit = {} | |
| 22 | 62 self._commits = [] | 
| 20 | 63 | 
| 31 | 64 def store(self, commit): | 
| 65 paths = self.paths(commit) | |
| 66 for path in paths: | |
| 38 | 67 self.path_to_commit.set_default(path, []).append(commit) | 
| 68 raise NotImplementedError | |
| 5 | 69 | 
