Mercurial > hg > CommitWatcher
annotate commitwatcher/store.py @ 40:97dfcdeb9a4e
stub
author | Jeff Hammel <jhammel@mozilla.com> |
---|---|
date | Tue, 05 Nov 2013 02:10:58 -0800 |
parents | b04538e7f9f3 |
children | cd590e1722d6 |
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 """ |
39 | 11 ABC for commit storage |
5 | 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 | 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 | 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 |
5 | 32 @abstractmethod |
33 def paths(self, *commits): | |
34 """return all paths touched for a given commit""" | |
35 | |
20 | 36 def ancestry(self, path): |
37 sep = '/' # unix/url-style separators | |
38 path = path.split('/') | |
39 paths = [] | |
40 while path: | |
41 paths.append(sep.join(path)) | |
42 path.pop() | |
43 return paths | |
44 | |
31 | 45 def paths(self, *commits): |
46 """ | |
47 return paths touched by commits | |
48 """ | |
49 | |
50 paths = set() | |
51 for commit in commits: | |
52 for f in commit.files: | |
53 paths.update(self.ancestry(f)) | |
54 return paths | |
55 | |
5 | 56 |
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
|
57 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
|
58 """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
|
59 # 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
|
60 |
39 | 61 def __init__(self, *args, **kwargs): |
62 CommitStore.__init__(self, *args, **kwargs) | |
20 | 63 self.path_to_commit = {} |
22 | 64 self._commits = [] |
20 | 65 |
31 | 66 def store(self, commit): |
67 paths = self.paths(commit) | |
68 for path in paths: | |
38 | 69 self.path_to_commit.set_default(path, []).append(commit) |
70 raise NotImplementedError | |
5 | 71 |