Mercurial > hg > CommitWatcher
annotate commitwatcher/agent.py @ 42:cd590e1722d6
dup
author | Jeff Hammel <jhammel@mozilla.com> |
---|---|
date | Tue, 05 Nov 2013 03:03:06 -0800 |
parents | be7090ee7738 |
children |
rev | line source |
---|---|
1 | 1 """ |
2 agents to gather commits | |
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:
1
diff
changeset
|
5 import feedparser |
15 | 6 import os |
10
7ae60d2ff1c2
commitwatcher/agent.py mozbasewatcher.py tests/41701d2c0341.diff
Jeff Hammel <jhammel@mozilla.com>
parents:
9
diff
changeset
|
7 from abc import abstractmethod |
12 | 8 from pypatch import patch |
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:
1
diff
changeset
|
9 from .commit import Commit |
6
883c88b13142
commitwatcher/agent.py commitwatcher/store.py mozbasewatcher.py
Jeff Hammel <jhammel@mozilla.com>
parents:
2
diff
changeset
|
10 from .store import MemoryStore |
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:
1
diff
changeset
|
11 |
15 | 12 |
1 | 13 class Agent(object): |
14 """abstract base class""" | |
15 | |
6
883c88b13142
commitwatcher/agent.py commitwatcher/store.py mozbasewatcher.py
Jeff Hammel <jhammel@mozilla.com>
parents:
2
diff
changeset
|
16 def __init__(self, repository, store=None): |
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:
1
diff
changeset
|
17 """ |
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:
1
diff
changeset
|
18 repository -- repo to monitor |
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:
1
diff
changeset
|
19 """ |
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:
1
diff
changeset
|
20 self.repository = repository |
6
883c88b13142
commitwatcher/agent.py commitwatcher/store.py mozbasewatcher.py
Jeff Hammel <jhammel@mozilla.com>
parents:
2
diff
changeset
|
21 self.store = MemoryStore() if store is None else store |
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:
1
diff
changeset
|
22 |
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:
1
diff
changeset
|
23 |
1 | 24 class LocalCheckoutAgent(object): |
25 """agent based on local checkouts""" | |
26 | |
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:
1
diff
changeset
|
27 |
1 | 28 class FeedAgent(Agent): |
29 """gathers changesets by reading RSS/Atom""" | |
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:
1
diff
changeset
|
30 |
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:
1
diff
changeset
|
31 def feed(self): |
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:
1
diff
changeset
|
32 """feed URL""" |
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:
1
diff
changeset
|
33 return '/'.join((self.repository.rstrip('/'), 'atom-log')) |
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:
1
diff
changeset
|
34 |
9 | 35 @abstractmethod |
36 def files(self, revision): | |
37 """gets the files from the revision link""" | |
38 | |
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:
1
diff
changeset
|
39 def update(self): |
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:
1
diff
changeset
|
40 """update""" |
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:
1
diff
changeset
|
41 |
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:
1
diff
changeset
|
42 feed = feedparser.parse(self.feed()) |
8 | 43 for entry in feed['entries']: |
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:
1
diff
changeset
|
44 |
20 | 45 # get files from the changeset diff |
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:
1
diff
changeset
|
46 link = entry['link'] |
9 | 47 files = self.files(link) |
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:
1
diff
changeset
|
48 |
20 | 49 # make commit object |
50 import pdb; pdb.set_trace() | |
51 commit = Commit() | |
52 | |
10
7ae60d2ff1c2
commitwatcher/agent.py mozbasewatcher.py tests/41701d2c0341.diff
Jeff Hammel <jhammel@mozilla.com>
parents:
9
diff
changeset
|
53 |
7ae60d2ff1c2
commitwatcher/agent.py mozbasewatcher.py tests/41701d2c0341.diff
Jeff Hammel <jhammel@mozilla.com>
parents:
9
diff
changeset
|
54 class FeedAgentDiff(FeedAgent): |
7ae60d2ff1c2
commitwatcher/agent.py mozbasewatcher.py tests/41701d2c0341.diff
Jeff Hammel <jhammel@mozilla.com>
parents:
9
diff
changeset
|
55 """read files from diff""" |
7ae60d2ff1c2
commitwatcher/agent.py mozbasewatcher.py tests/41701d2c0341.diff
Jeff Hammel <jhammel@mozilla.com>
parents:
9
diff
changeset
|
56 |
11
546695da018c
commitwatcher/agent.py tests/unit.py
Jeff Hammel <jhammel@mozilla.com>
parents:
10
diff
changeset
|
57 @staticmethod |
546695da018c
commitwatcher/agent.py tests/unit.py
Jeff Hammel <jhammel@mozilla.com>
parents:
10
diff
changeset
|
58 def lsdiff(diff): |
15 | 59 |
60 if '://' in diff: | |
61 factory = patch.fromurl | |
62 elif os.path.exists(diff): | |
63 factory = patch.fromfile | |
64 else: | |
65 factory = patch.fromstring | |
66 patchset = factory(diff) | |
67 | |
68 files = {} | |
69 for p in patchset.items: | |
70 | |
71 # before, after | |
72 a_b = {} | |
73 for i in ('source', 'target'): | |
74 a_b[i] = getattr(p, i) | |
75 | |
76 # strip 'a/', 'b/' from front, just to make sure | |
20 | 77 # XXX because the current version is b0rken sometimes |
15 | 78 for prefix in ('a/', 'b/'): |
79 if a_b[i].startswith(prefix): | |
80 a_b[i] = a_b[i][len(prefix):] | |
81 break | |
82 | |
18 | 83 # added, modified, removed, renamed |
15 | 84 if a_b['source'] == a_b['target']: |
85 files.setdefault('modified', set()).add(a_b['source']) | |
16 | 86 elif a_b['source'] in ('/dev/null', 'dev/null'): |
87 files.setdefault('added', set()).add(a_b['target']) | |
88 elif a_b['target'] in ('/dev/null', 'dev/null'): | |
89 files.setdefault('removed', set()).add(a_b['source']) | |
15 | 90 else: |
16 | 91 raise NotImplementedError("source: %s; target: %s" % (a_b['source'], a_b['target'])) |
92 | |
93 # xxx flatten for simplicity for now and hope i don't regret this | |
94 files = set(sum([list(item) for item in files.values()], [])) | |
15 | 95 |
96 return files | |
12 | 97 |
10
7ae60d2ff1c2
commitwatcher/agent.py mozbasewatcher.py tests/41701d2c0341.diff
Jeff Hammel <jhammel@mozilla.com>
parents:
9
diff
changeset
|
98 def diff_url(self, link): |
7ae60d2ff1c2
commitwatcher/agent.py mozbasewatcher.py tests/41701d2c0341.diff
Jeff Hammel <jhammel@mozilla.com>
parents:
9
diff
changeset
|
99 """ |
7ae60d2ff1c2
commitwatcher/agent.py mozbasewatcher.py tests/41701d2c0341.diff
Jeff Hammel <jhammel@mozilla.com>
parents:
9
diff
changeset
|
100 returns diff_url from revision link: |
7ae60d2ff1c2
commitwatcher/agent.py mozbasewatcher.py tests/41701d2c0341.diff
Jeff Hammel <jhammel@mozilla.com>
parents:
9
diff
changeset
|
101 |
7ae60d2ff1c2
commitwatcher/agent.py mozbasewatcher.py tests/41701d2c0341.diff
Jeff Hammel <jhammel@mozilla.com>
parents:
9
diff
changeset
|
102 >>> diff_url('http://hg.mozilla.org/mozilla-central/rev/4e1a3919e741') |
7ae60d2ff1c2
commitwatcher/agent.py mozbasewatcher.py tests/41701d2c0341.diff
Jeff Hammel <jhammel@mozilla.com>
parents:
9
diff
changeset
|
103 'http://hg.mozilla.org/mozilla-central/raw-rev/4e1a3919e741' |
7ae60d2ff1c2
commitwatcher/agent.py mozbasewatcher.py tests/41701d2c0341.diff
Jeff Hammel <jhammel@mozilla.com>
parents:
9
diff
changeset
|
104 """ |
7ae60d2ff1c2
commitwatcher/agent.py mozbasewatcher.py tests/41701d2c0341.diff
Jeff Hammel <jhammel@mozilla.com>
parents:
9
diff
changeset
|
105 return '/raw-rev/'.join(link.rsplit('/rev/', 1)) |
7ae60d2ff1c2
commitwatcher/agent.py mozbasewatcher.py tests/41701d2c0341.diff
Jeff Hammel <jhammel@mozilla.com>
parents:
9
diff
changeset
|
106 |
7ae60d2ff1c2
commitwatcher/agent.py mozbasewatcher.py tests/41701d2c0341.diff
Jeff Hammel <jhammel@mozilla.com>
parents:
9
diff
changeset
|
107 def files(self, revision): |
7ae60d2ff1c2
commitwatcher/agent.py mozbasewatcher.py tests/41701d2c0341.diff
Jeff Hammel <jhammel@mozilla.com>
parents:
9
diff
changeset
|
108 """ |
7ae60d2ff1c2
commitwatcher/agent.py mozbasewatcher.py tests/41701d2c0341.diff
Jeff Hammel <jhammel@mozilla.com>
parents:
9
diff
changeset
|
109 revision -- revision link |
7ae60d2ff1c2
commitwatcher/agent.py mozbasewatcher.py tests/41701d2c0341.diff
Jeff Hammel <jhammel@mozilla.com>
parents:
9
diff
changeset
|
110 """ |
7ae60d2ff1c2
commitwatcher/agent.py mozbasewatcher.py tests/41701d2c0341.diff
Jeff Hammel <jhammel@mozilla.com>
parents:
9
diff
changeset
|
111 |
7ae60d2ff1c2
commitwatcher/agent.py mozbasewatcher.py tests/41701d2c0341.diff
Jeff Hammel <jhammel@mozilla.com>
parents:
9
diff
changeset
|
112 raw_rev = self.diff_url(revision) |
7ae60d2ff1c2
commitwatcher/agent.py mozbasewatcher.py tests/41701d2c0341.diff
Jeff Hammel <jhammel@mozilla.com>
parents:
9
diff
changeset
|
113 |
7ae60d2ff1c2
commitwatcher/agent.py mozbasewatcher.py tests/41701d2c0341.diff
Jeff Hammel <jhammel@mozilla.com>
parents:
9
diff
changeset
|
114 # get paths from diff |
16 | 115 paths = self.lsdiff(raw_rev) |
17 | 116 print '%s :\n%s\n' % (revision, |
19 | 117 '\n'.join([(' %s' % path) |
118 for path in sorted(paths)])) | |
119 | |
20 | 120 |
121 class FeedAgentHTML(FeedAgent): | |
21 | 122 """ |
123 http://stackoverflow.com/questions/11709079/parsing-html-python | |
124 """ | |
125 |