annotate commitwatcher/agent.py @ 13:fc91a93fcaee

tests/unit.py
author Jeff Hammel <jhammel@mozilla.com>
date Sat, 28 Sep 2013 07:08:32 -0700
parents a0ff003319ec
children 77118f83b5b7
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
10
7ae60d2ff1c2 commitwatcher/agent.py mozbasewatcher.py tests/41701d2c0341.diff
Jeff Hammel <jhammel@mozilla.com>
parents: 9
diff changeset
6 from abc import abstractmethod
12
Jeff Hammel <jhammel@mozilla.com>
parents: 11
diff changeset
7 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
8 from .commit import Commit
6
883c88b13142 commitwatcher/agent.py commitwatcher/store.py mozbasewatcher.py
Jeff Hammel <jhammel@mozilla.com>
parents: 2
diff changeset
9 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
10
1
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
11 class Agent(object):
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
12 """abstract base class"""
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
13
6
883c88b13142 commitwatcher/agent.py commitwatcher/store.py mozbasewatcher.py
Jeff Hammel <jhammel@mozilla.com>
parents: 2
diff changeset
14 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
15 """
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
16 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
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 self.repository = repository
6
883c88b13142 commitwatcher/agent.py commitwatcher/store.py mozbasewatcher.py
Jeff Hammel <jhammel@mozilla.com>
parents: 2
diff changeset
19 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
20
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
21
1
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
22 class LocalCheckoutAgent(object):
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
23 """agent based on local checkouts"""
Jeff Hammel <jhammel@mozilla.com>
parents:
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: 1
diff changeset
25
1
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
26 class FeedAgent(Agent):
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
27 """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
28
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
29 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
30 """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
31 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
32
9
08dd6fbbec3a commitwatcher/agent.py
Jeff Hammel <jhammel@mozilla.com>
parents: 8
diff changeset
33 @abstractmethod
08dd6fbbec3a commitwatcher/agent.py
Jeff Hammel <jhammel@mozilla.com>
parents: 8
diff changeset
34 def files(self, revision):
08dd6fbbec3a commitwatcher/agent.py
Jeff Hammel <jhammel@mozilla.com>
parents: 8
diff changeset
35 """gets the files from the revision link"""
08dd6fbbec3a commitwatcher/agent.py
Jeff Hammel <jhammel@mozilla.com>
parents: 8
diff changeset
36
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
37 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
38 """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
39
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 feed = feedparser.parse(self.feed())
8
2061b13f7aad commitwatcher/agent.py
Jeff Hammel <jhammel@mozilla.com>
parents: 7
diff changeset
41 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
42
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
43 link = entry['link']
9
08dd6fbbec3a commitwatcher/agent.py
Jeff Hammel <jhammel@mozilla.com>
parents: 8
diff changeset
44 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
45 # 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
46
7
296af1d32b6a commitwatcher/agent.py
Jeff Hammel <jhammel@mozilla.com>
parents: 6
diff changeset
47 # TODO commit = Commit()
10
7ae60d2ff1c2 commitwatcher/agent.py mozbasewatcher.py tests/41701d2c0341.diff
Jeff Hammel <jhammel@mozilla.com>
parents: 9
diff changeset
48
7ae60d2ff1c2 commitwatcher/agent.py mozbasewatcher.py tests/41701d2c0341.diff
Jeff Hammel <jhammel@mozilla.com>
parents: 9
diff changeset
49 class FeedAgentDiff(FeedAgent):
7ae60d2ff1c2 commitwatcher/agent.py mozbasewatcher.py tests/41701d2c0341.diff
Jeff Hammel <jhammel@mozilla.com>
parents: 9
diff changeset
50 """read files from diff"""
7ae60d2ff1c2 commitwatcher/agent.py mozbasewatcher.py tests/41701d2c0341.diff
Jeff Hammel <jhammel@mozilla.com>
parents: 9
diff changeset
51
11
546695da018c commitwatcher/agent.py tests/unit.py
Jeff Hammel <jhammel@mozilla.com>
parents: 10
diff changeset
52 @staticmethod
546695da018c commitwatcher/agent.py tests/unit.py
Jeff Hammel <jhammel@mozilla.com>
parents: 10
diff changeset
53 def lsdiff(diff):
12
Jeff Hammel <jhammel@mozilla.com>
parents: 11
diff changeset
54 import pdb; pdb.set_trace()
Jeff Hammel <jhammel@mozilla.com>
parents: 11
diff changeset
55
10
7ae60d2ff1c2 commitwatcher/agent.py mozbasewatcher.py tests/41701d2c0341.diff
Jeff Hammel <jhammel@mozilla.com>
parents: 9
diff changeset
56 def diff_url(self, link):
7ae60d2ff1c2 commitwatcher/agent.py mozbasewatcher.py tests/41701d2c0341.diff
Jeff Hammel <jhammel@mozilla.com>
parents: 9
diff changeset
57 """
7ae60d2ff1c2 commitwatcher/agent.py mozbasewatcher.py tests/41701d2c0341.diff
Jeff Hammel <jhammel@mozilla.com>
parents: 9
diff changeset
58 returns diff_url from revision link:
7ae60d2ff1c2 commitwatcher/agent.py mozbasewatcher.py tests/41701d2c0341.diff
Jeff Hammel <jhammel@mozilla.com>
parents: 9
diff changeset
59
7ae60d2ff1c2 commitwatcher/agent.py mozbasewatcher.py tests/41701d2c0341.diff
Jeff Hammel <jhammel@mozilla.com>
parents: 9
diff changeset
60 >>> 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
61 '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
62 """
7ae60d2ff1c2 commitwatcher/agent.py mozbasewatcher.py tests/41701d2c0341.diff
Jeff Hammel <jhammel@mozilla.com>
parents: 9
diff changeset
63 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
64
7ae60d2ff1c2 commitwatcher/agent.py mozbasewatcher.py tests/41701d2c0341.diff
Jeff Hammel <jhammel@mozilla.com>
parents: 9
diff changeset
65 def files(self, revision):
7ae60d2ff1c2 commitwatcher/agent.py mozbasewatcher.py tests/41701d2c0341.diff
Jeff Hammel <jhammel@mozilla.com>
parents: 9
diff changeset
66 """
7ae60d2ff1c2 commitwatcher/agent.py mozbasewatcher.py tests/41701d2c0341.diff
Jeff Hammel <jhammel@mozilla.com>
parents: 9
diff changeset
67 revision -- revision link
7ae60d2ff1c2 commitwatcher/agent.py mozbasewatcher.py tests/41701d2c0341.diff
Jeff Hammel <jhammel@mozilla.com>
parents: 9
diff changeset
68 """
7ae60d2ff1c2 commitwatcher/agent.py mozbasewatcher.py tests/41701d2c0341.diff
Jeff Hammel <jhammel@mozilla.com>
parents: 9
diff changeset
69
7ae60d2ff1c2 commitwatcher/agent.py mozbasewatcher.py tests/41701d2c0341.diff
Jeff Hammel <jhammel@mozilla.com>
parents: 9
diff changeset
70 raw_rev = self.diff_url(revision)
7ae60d2ff1c2 commitwatcher/agent.py mozbasewatcher.py tests/41701d2c0341.diff
Jeff Hammel <jhammel@mozilla.com>
parents: 9
diff changeset
71 print raw_rev
7ae60d2ff1c2 commitwatcher/agent.py mozbasewatcher.py tests/41701d2c0341.diff
Jeff Hammel <jhammel@mozilla.com>
parents: 9
diff changeset
72
7ae60d2ff1c2 commitwatcher/agent.py mozbasewatcher.py tests/41701d2c0341.diff
Jeff Hammel <jhammel@mozilla.com>
parents: 9
diff changeset
73 # get paths from diff