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
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
1 """
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
2 agents to gather commits
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
3 """
Jeff Hammel <jhammel@mozilla.com>
parents:
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: 1
diff changeset
5 import feedparser
15
77118f83b5b7 almost does somethign
Jeff Hammel <jhammel@mozilla.com>
parents: 12
diff changeset
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
Jeff Hammel <jhammel@mozilla.com>
parents: 11
diff changeset
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
77118f83b5b7 almost does somethign
Jeff Hammel <jhammel@mozilla.com>
parents: 12
diff changeset
12
1
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
13 class Agent(object):
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
14 """abstract base class"""
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
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
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
24 class LocalCheckoutAgent(object):
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
25 """agent based on local checkouts"""
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
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
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
28 class FeedAgent(Agent):
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
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
08dd6fbbec3a commitwatcher/agent.py
Jeff Hammel <jhammel@mozilla.com>
parents: 8
diff changeset
35 @abstractmethod
08dd6fbbec3a commitwatcher/agent.py
Jeff Hammel <jhammel@mozilla.com>
parents: 8
diff changeset
36 def files(self, revision):
08dd6fbbec3a commitwatcher/agent.py
Jeff Hammel <jhammel@mozilla.com>
parents: 8
diff changeset
37 """gets the files from the revision link"""
08dd6fbbec3a commitwatcher/agent.py
Jeff Hammel <jhammel@mozilla.com>
parents: 8
diff changeset
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
2061b13f7aad commitwatcher/agent.py
Jeff Hammel <jhammel@mozilla.com>
parents: 7
diff changeset
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
Jeff Hammel <jhammel@mozilla.com>
parents: 19
diff changeset
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
08dd6fbbec3a commitwatcher/agent.py
Jeff Hammel <jhammel@mozilla.com>
parents: 8
diff changeset
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
Jeff Hammel <jhammel@mozilla.com>
parents: 19
diff changeset
49 # make commit object
Jeff Hammel <jhammel@mozilla.com>
parents: 19
diff changeset
50 import pdb; pdb.set_trace()
Jeff Hammel <jhammel@mozilla.com>
parents: 19
diff changeset
51 commit = Commit()
Jeff Hammel <jhammel@mozilla.com>
parents: 19
diff changeset
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
77118f83b5b7 almost does somethign
Jeff Hammel <jhammel@mozilla.com>
parents: 12
diff changeset
59
77118f83b5b7 almost does somethign
Jeff Hammel <jhammel@mozilla.com>
parents: 12
diff changeset
60 if '://' in diff:
77118f83b5b7 almost does somethign
Jeff Hammel <jhammel@mozilla.com>
parents: 12
diff changeset
61 factory = patch.fromurl
77118f83b5b7 almost does somethign
Jeff Hammel <jhammel@mozilla.com>
parents: 12
diff changeset
62 elif os.path.exists(diff):
77118f83b5b7 almost does somethign
Jeff Hammel <jhammel@mozilla.com>
parents: 12
diff changeset
63 factory = patch.fromfile
77118f83b5b7 almost does somethign
Jeff Hammel <jhammel@mozilla.com>
parents: 12
diff changeset
64 else:
77118f83b5b7 almost does somethign
Jeff Hammel <jhammel@mozilla.com>
parents: 12
diff changeset
65 factory = patch.fromstring
77118f83b5b7 almost does somethign
Jeff Hammel <jhammel@mozilla.com>
parents: 12
diff changeset
66 patchset = factory(diff)
77118f83b5b7 almost does somethign
Jeff Hammel <jhammel@mozilla.com>
parents: 12
diff changeset
67
77118f83b5b7 almost does somethign
Jeff Hammel <jhammel@mozilla.com>
parents: 12
diff changeset
68 files = {}
77118f83b5b7 almost does somethign
Jeff Hammel <jhammel@mozilla.com>
parents: 12
diff changeset
69 for p in patchset.items:
77118f83b5b7 almost does somethign
Jeff Hammel <jhammel@mozilla.com>
parents: 12
diff changeset
70
77118f83b5b7 almost does somethign
Jeff Hammel <jhammel@mozilla.com>
parents: 12
diff changeset
71 # before, after
77118f83b5b7 almost does somethign
Jeff Hammel <jhammel@mozilla.com>
parents: 12
diff changeset
72 a_b = {}
77118f83b5b7 almost does somethign
Jeff Hammel <jhammel@mozilla.com>
parents: 12
diff changeset
73 for i in ('source', 'target'):
77118f83b5b7 almost does somethign
Jeff Hammel <jhammel@mozilla.com>
parents: 12
diff changeset
74 a_b[i] = getattr(p, i)
77118f83b5b7 almost does somethign
Jeff Hammel <jhammel@mozilla.com>
parents: 12
diff changeset
75
77118f83b5b7 almost does somethign
Jeff Hammel <jhammel@mozilla.com>
parents: 12
diff changeset
76 # strip 'a/', 'b/' from front, just to make sure
20
Jeff Hammel <jhammel@mozilla.com>
parents: 19
diff changeset
77 # XXX because the current version is b0rken sometimes
15
77118f83b5b7 almost does somethign
Jeff Hammel <jhammel@mozilla.com>
parents: 12
diff changeset
78 for prefix in ('a/', 'b/'):
77118f83b5b7 almost does somethign
Jeff Hammel <jhammel@mozilla.com>
parents: 12
diff changeset
79 if a_b[i].startswith(prefix):
77118f83b5b7 almost does somethign
Jeff Hammel <jhammel@mozilla.com>
parents: 12
diff changeset
80 a_b[i] = a_b[i][len(prefix):]
77118f83b5b7 almost does somethign
Jeff Hammel <jhammel@mozilla.com>
parents: 12
diff changeset
81 break
77118f83b5b7 almost does somethign
Jeff Hammel <jhammel@mozilla.com>
parents: 12
diff changeset
82
18
53533334469f commitwatcher/agent.py
Jeff Hammel <jhammel@mozilla.com>
parents: 17
diff changeset
83 # added, modified, removed, renamed
15
77118f83b5b7 almost does somethign
Jeff Hammel <jhammel@mozilla.com>
parents: 12
diff changeset
84 if a_b['source'] == a_b['target']:
77118f83b5b7 almost does somethign
Jeff Hammel <jhammel@mozilla.com>
parents: 12
diff changeset
85 files.setdefault('modified', set()).add(a_b['source'])
16
59c94aaf311c almost does somethign
Jeff Hammel <jhammel@mozilla.com>
parents: 15
diff changeset
86 elif a_b['source'] in ('/dev/null', 'dev/null'):
59c94aaf311c almost does somethign
Jeff Hammel <jhammel@mozilla.com>
parents: 15
diff changeset
87 files.setdefault('added', set()).add(a_b['target'])
59c94aaf311c almost does somethign
Jeff Hammel <jhammel@mozilla.com>
parents: 15
diff changeset
88 elif a_b['target'] in ('/dev/null', 'dev/null'):
59c94aaf311c almost does somethign
Jeff Hammel <jhammel@mozilla.com>
parents: 15
diff changeset
89 files.setdefault('removed', set()).add(a_b['source'])
15
77118f83b5b7 almost does somethign
Jeff Hammel <jhammel@mozilla.com>
parents: 12
diff changeset
90 else:
16
59c94aaf311c almost does somethign
Jeff Hammel <jhammel@mozilla.com>
parents: 15
diff changeset
91 raise NotImplementedError("source: %s; target: %s" % (a_b['source'], a_b['target']))
59c94aaf311c almost does somethign
Jeff Hammel <jhammel@mozilla.com>
parents: 15
diff changeset
92
59c94aaf311c almost does somethign
Jeff Hammel <jhammel@mozilla.com>
parents: 15
diff changeset
93 # xxx flatten for simplicity for now and hope i don't regret this
59c94aaf311c almost does somethign
Jeff Hammel <jhammel@mozilla.com>
parents: 15
diff changeset
94 files = set(sum([list(item) for item in files.values()], []))
15
77118f83b5b7 almost does somethign
Jeff Hammel <jhammel@mozilla.com>
parents: 12
diff changeset
95
77118f83b5b7 almost does somethign
Jeff Hammel <jhammel@mozilla.com>
parents: 12
diff changeset
96 return files
12
Jeff Hammel <jhammel@mozilla.com>
parents: 11
diff changeset
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
59c94aaf311c almost does somethign
Jeff Hammel <jhammel@mozilla.com>
parents: 15
diff changeset
115 paths = self.lsdiff(raw_rev)
17
9ec036da252e commitwatcher/agent.py
Jeff Hammel <jhammel@mozilla.com>
parents: 16
diff changeset
116 print '%s :\n%s\n' % (revision,
19
091fd9f40b05 commitwatcher/agent.py
Jeff Hammel <jhammel@mozilla.com>
parents: 18
diff changeset
117 '\n'.join([(' %s' % path)
091fd9f40b05 commitwatcher/agent.py
Jeff Hammel <jhammel@mozilla.com>
parents: 18
diff changeset
118 for path in sorted(paths)]))
091fd9f40b05 commitwatcher/agent.py
Jeff Hammel <jhammel@mozilla.com>
parents: 18
diff changeset
119
20
Jeff Hammel <jhammel@mozilla.com>
parents: 19
diff changeset
120
Jeff Hammel <jhammel@mozilla.com>
parents: 19
diff changeset
121 class FeedAgentHTML(FeedAgent):
21
Jeff Hammel <jhammel@mozilla.com>
parents: 20
diff changeset
122 """
Jeff Hammel <jhammel@mozilla.com>
parents: 20
diff changeset
123 http://stackoverflow.com/questions/11709079/parsing-html-python
Jeff Hammel <jhammel@mozilla.com>
parents: 20
diff changeset
124 """
Jeff Hammel <jhammel@mozilla.com>
parents: 20
diff changeset
125