This repository has been archived by the owner on Aug 4, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
svn.py
54 lines (45 loc) · 1.78 KB
/
svn.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
import text
from xml.etree.cElementTree import parse as xmlparse
from cStringIO import StringIO
from subprocess import Popen, PIPE
class SvnPoller(object):
"""
Run "svn info" and "svn log -r REV" to get metadata for the most recent commits.
"""
def __init__(self, root=None, args=None, changeset_url_format=None):
self.pre = ["svn", "--xml"]
if args:
self.pre += args.split()
self.root = root
self.changeset_url_format = changeset_url_format
print "Initializing SVN poller: %s" % (" ".join(self.pre)+" "+root, )
def svn(self, *cmd):
pipe = Popen(self.pre + list(cmd) + [self.root], stdout=PIPE)
try:
data = pipe.communicate()[0]
except IOError:
data = ""
return xmlparse(StringIO(data))
def revision(self):
tree = self.svn("info")
revision = tree.find(".//commit").get("revision")
return int(revision)
def revision_info(self, revision):
revision = str(revision)
tree = self.svn("log", "-r", revision)
author = tree.find(".//author").text
comment = text.strip(tree.find(".//msg").text, truncate=True)
url = self.changeset_url(revision)
return (revision, author, comment, url)
def changeset_url(self, revision):
return self.changeset_url_format % (revision, )
previous_revision = None
def check(self):
try:
latest = self.revision()
if self.previous_revision and latest != self.previous_revision:
for rev in range(self.previous_revision + 1, latest + 1):
yield "r%s by %s: %s -- %s" % self.revision_info(rev)
self.previous_revision = latest
except Exception, e:
print "ERROR: %s" % e