annotate commitwatcher/agent.py @ 15:77118f83b5b7

almost does somethign
author Jeff Hammel <jhammel@mozilla.com>
date Sat, 28 Sep 2013 09:20:14 -0700
parents a0ff003319ec
children 59c94aaf311c
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
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
45 link = entry['link']
9
08dd6fbbec3a commitwatcher/agent.py
Jeff Hammel <jhammel@mozilla.com>
parents: 8
diff changeset
46 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
47 # TODO
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
7
296af1d32b6a commitwatcher/agent.py
Jeff Hammel <jhammel@mozilla.com>
parents: 6
diff changeset
49 # TODO commit = Commit()
10
7ae60d2ff1c2 commitwatcher/agent.py mozbasewatcher.py tests/41701d2c0341.diff
Jeff Hammel <jhammel@mozilla.com>
parents: 9
diff changeset
50
7ae60d2ff1c2 commitwatcher/agent.py mozbasewatcher.py tests/41701d2c0341.diff
Jeff Hammel <jhammel@mozilla.com>
parents: 9
diff changeset
51 class FeedAgentDiff(FeedAgent):
7ae60d2ff1c2 commitwatcher/agent.py mozbasewatcher.py tests/41701d2c0341.diff
Jeff Hammel <jhammel@mozilla.com>
parents: 9
diff changeset
52 """read files from diff"""
7ae60d2ff1c2 commitwatcher/agent.py mozbasewatcher.py tests/41701d2c0341.diff
Jeff Hammel <jhammel@mozilla.com>
parents: 9
diff changeset
53
11
546695da018c commitwatcher/agent.py tests/unit.py
Jeff Hammel <jhammel@mozilla.com>
parents: 10
diff changeset
54 @staticmethod
546695da018c commitwatcher/agent.py tests/unit.py
Jeff Hammel <jhammel@mozilla.com>
parents: 10
diff changeset
55 def lsdiff(diff):
15
77118f83b5b7 almost does somethign
Jeff Hammel <jhammel@mozilla.com>
parents: 12
diff changeset
56
77118f83b5b7 almost does somethign
Jeff Hammel <jhammel@mozilla.com>
parents: 12
diff changeset
57 if '://' in diff:
77118f83b5b7 almost does somethign
Jeff Hammel <jhammel@mozilla.com>
parents: 12
diff changeset
58 factory = patch.fromurl
77118f83b5b7 almost does somethign
Jeff Hammel <jhammel@mozilla.com>
parents: 12
diff changeset
59 elif os.path.exists(diff):
77118f83b5b7 almost does somethign
Jeff Hammel <jhammel@mozilla.com>
parents: 12
diff changeset
60 factory = patch.fromfile
77118f83b5b7 almost does somethign
Jeff Hammel <jhammel@mozilla.com>
parents: 12
diff changeset
61 else:
77118f83b5b7 almost does somethign
Jeff Hammel <jhammel@mozilla.com>
parents: 12
diff changeset
62 factory = patch.fromstring
77118f83b5b7 almost does somethign
Jeff Hammel <jhammel@mozilla.com>
parents: 12
diff changeset
63 patchset = factory(diff)
77118f83b5b7 almost does somethign
Jeff Hammel <jhammel@mozilla.com>
parents: 12
diff changeset
64
77118f83b5b7 almost does somethign
Jeff Hammel <jhammel@mozilla.com>
parents: 12
diff changeset
65 files = {}
77118f83b5b7 almost does somethign
Jeff Hammel <jhammel@mozilla.com>
parents: 12
diff changeset
66 for p in patchset.items:
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 # before, after
77118f83b5b7 almost does somethign
Jeff Hammel <jhammel@mozilla.com>
parents: 12
diff changeset
69 a_b = {}
77118f83b5b7 almost does somethign
Jeff Hammel <jhammel@mozilla.com>
parents: 12
diff changeset
70 for i in ('source', 'target'):
77118f83b5b7 almost does somethign
Jeff Hammel <jhammel@mozilla.com>
parents: 12
diff changeset
71 a_b[i] = getattr(p, i)
77118f83b5b7 almost does somethign
Jeff Hammel <jhammel@mozilla.com>
parents: 12
diff changeset
72
77118f83b5b7 almost does somethign
Jeff Hammel <jhammel@mozilla.com>
parents: 12
diff changeset
73 # strip 'a/', 'b/' from front, just to make sure
77118f83b5b7 almost does somethign
Jeff Hammel <jhammel@mozilla.com>
parents: 12
diff changeset
74 # XXX because
77118f83b5b7 almost does somethign
Jeff Hammel <jhammel@mozilla.com>
parents: 12
diff changeset
75 for prefix in ('a/', 'b/'):
77118f83b5b7 almost does somethign
Jeff Hammel <jhammel@mozilla.com>
parents: 12
diff changeset
76 if a_b[i].startswith(prefix):
77118f83b5b7 almost does somethign
Jeff Hammel <jhammel@mozilla.com>
parents: 12
diff changeset
77 a_b[i] = a_b[i][len(prefix):]
77118f83b5b7 almost does somethign
Jeff Hammel <jhammel@mozilla.com>
parents: 12
diff changeset
78 break
77118f83b5b7 almost does somethign
Jeff Hammel <jhammel@mozilla.com>
parents: 12
diff changeset
79
77118f83b5b7 almost does somethign
Jeff Hammel <jhammel@mozilla.com>
parents: 12
diff changeset
80 # TODO: could break this in to added, modified, removed, renamed
77118f83b5b7 almost does somethign
Jeff Hammel <jhammel@mozilla.com>
parents: 12
diff changeset
81 if a_b['source'] == a_b['target']:
77118f83b5b7 almost does somethign
Jeff Hammel <jhammel@mozilla.com>
parents: 12
diff changeset
82 files.setdefault('modified', set()).add(a_b['source'])
77118f83b5b7 almost does somethign
Jeff Hammel <jhammel@mozilla.com>
parents: 12
diff changeset
83 else:
77118f83b5b7 almost does somethign
Jeff Hammel <jhammel@mozilla.com>
parents: 12
diff changeset
84 raise NotImplementedError("%s %s" % (a_b['source'], a_b['target']))
77118f83b5b7 almost does somethign
Jeff Hammel <jhammel@mozilla.com>
parents: 12
diff changeset
85
77118f83b5b7 almost does somethign
Jeff Hammel <jhammel@mozilla.com>
parents: 12
diff changeset
86 return files
12
Jeff Hammel <jhammel@mozilla.com>
parents: 11
diff changeset
87
10
7ae60d2ff1c2 commitwatcher/agent.py mozbasewatcher.py tests/41701d2c0341.diff
Jeff Hammel <jhammel@mozilla.com>
parents: 9
diff changeset
88 def diff_url(self, link):
7ae60d2ff1c2 commitwatcher/agent.py mozbasewatcher.py tests/41701d2c0341.diff
Jeff Hammel <jhammel@mozilla.com>
parents: 9
diff changeset
89 """
7ae60d2ff1c2 commitwatcher/agent.py mozbasewatcher.py tests/41701d2c0341.diff
Jeff Hammel <jhammel@mozilla.com>
parents: 9
diff changeset
90 returns diff_url from revision link:
7ae60d2ff1c2 commitwatcher/agent.py mozbasewatcher.py tests/41701d2c0341.diff
Jeff Hammel <jhammel@mozilla.com>
parents: 9
diff changeset
91
7ae60d2ff1c2 commitwatcher/agent.py mozbasewatcher.py tests/41701d2c0341.diff
Jeff Hammel <jhammel@mozilla.com>
parents: 9
diff changeset
92 >>> 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
93 '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
94 """
7ae60d2ff1c2 commitwatcher/agent.py mozbasewatcher.py tests/41701d2c0341.diff
Jeff Hammel <jhammel@mozilla.com>
parents: 9
diff changeset
95 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
96
7ae60d2ff1c2 commitwatcher/agent.py mozbasewatcher.py tests/41701d2c0341.diff
Jeff Hammel <jhammel@mozilla.com>
parents: 9
diff changeset
97 def files(self, revision):
7ae60d2ff1c2 commitwatcher/agent.py mozbasewatcher.py tests/41701d2c0341.diff
Jeff Hammel <jhammel@mozilla.com>
parents: 9
diff changeset
98 """
7ae60d2ff1c2 commitwatcher/agent.py mozbasewatcher.py tests/41701d2c0341.diff
Jeff Hammel <jhammel@mozilla.com>
parents: 9
diff changeset
99 revision -- revision link
7ae60d2ff1c2 commitwatcher/agent.py mozbasewatcher.py tests/41701d2c0341.diff
Jeff Hammel <jhammel@mozilla.com>
parents: 9
diff changeset
100 """
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 raw_rev = self.diff_url(revision)
7ae60d2ff1c2 commitwatcher/agent.py mozbasewatcher.py tests/41701d2c0341.diff
Jeff Hammel <jhammel@mozilla.com>
parents: 9
diff changeset
103 print raw_rev
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 # get paths from diff