comparison 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
comparison
equal deleted inserted replaced
14:8a02f209992f 15:77118f83b5b7
1 """ 1 """
2 agents to gather commits 2 agents to gather commits
3 """ 3 """
4 4
5 import feedparser 5 import feedparser
6 import os
6 from abc import abstractmethod 7 from abc import abstractmethod
7 from pypatch import patch 8 from pypatch import patch
8 from .commit import Commit 9 from .commit import Commit
9 from .store import MemoryStore 10 from .store import MemoryStore
11
10 12
11 class Agent(object): 13 class Agent(object):
12 """abstract base class""" 14 """abstract base class"""
13 15
14 def __init__(self, repository, store=None): 16 def __init__(self, repository, store=None):
49 class FeedAgentDiff(FeedAgent): 51 class FeedAgentDiff(FeedAgent):
50 """read files from diff""" 52 """read files from diff"""
51 53
52 @staticmethod 54 @staticmethod
53 def lsdiff(diff): 55 def lsdiff(diff):
54 import pdb; pdb.set_trace() 56
57 if '://' in diff:
58 factory = patch.fromurl
59 elif os.path.exists(diff):
60 factory = patch.fromfile
61 else:
62 factory = patch.fromstring
63 patchset = factory(diff)
64
65 files = {}
66 for p in patchset.items:
67
68 # before, after
69 a_b = {}
70 for i in ('source', 'target'):
71 a_b[i] = getattr(p, i)
72
73 # strip 'a/', 'b/' from front, just to make sure
74 # XXX because
75 for prefix in ('a/', 'b/'):
76 if a_b[i].startswith(prefix):
77 a_b[i] = a_b[i][len(prefix):]
78 break
79
80 # TODO: could break this in to added, modified, removed, renamed
81 if a_b['source'] == a_b['target']:
82 files.setdefault('modified', set()).add(a_b['source'])
83 else:
84 raise NotImplementedError("%s %s" % (a_b['source'], a_b['target']))
85
86 return files
55 87
56 def diff_url(self, link): 88 def diff_url(self, link):
57 """ 89 """
58 returns diff_url from revision link: 90 returns diff_url from revision link:
59 91