-
Notifications
You must be signed in to change notification settings - Fork 3
/
SvnSandbox.py
executable file
·67 lines (55 loc) · 2.25 KB
/
SvnSandbox.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
55
56
57
58
59
60
61
62
63
64
65
#!/usr/bin/python
import xml.etree.cElementTree as ET
#import xml.etree.ElementTree as ET # Python 2.5
import utils
class SvnSandbox(object) :
def __init__(self, sandbox ) :
self.sandbox = sandbox
self.conflictResolution = 'postpone'
def state(self) :
xml = utils.output("svn --xml info %(sandbox)s"%self.__dict__)
info = ET.fromstring(xml)
return info.find("entry").get('revision')
# text based implementation (needs LANG and risky)
return utils.output("LANG=C svn info %(sandbox)s | grep ^Revision: "%self.__dict__).split()[-1]
def remoteState(self) :
xml = utils.output("svn --xml info -rHEAD %(sandbox)s"%self.__dict__)
info = ET.fromstring(xml)
return info.find("entry").get('revision')
# text based implementation (needs LANG and risky)
return utils.output("LANG=C svn info %(sandbox)s | grep ^Revision: "%self.__dict__).split()[-1]
def update(self, revision=None) :
utils.run("svn up --accept %(conflictResolution)s %(sandbox)s"%self.__dict__)
def pendingUpdates(self) :
xml = utils.output("svn --xml log %(sandbox)s -rBASE:HEAD"%self.__dict__)
log = ET.fromstring(xml)
return [logentry.get('revision') for logentry in log.findall("logentry") ][1:]
def guilty(self) :
xml = utils.output("svn --xml log %(sandbox)s -rBASE:HEAD"%self.__dict__)
log = ET.fromstring(xml)
return [(
logentry.get('revision'),
logentry.find('author').text,
logentry.find('msg').text,
) for logentry in log.findall("logentry") ][1:]
def _pendingChanges(self) :
xml = utils.output("svn status --xml -u %(sandbox)s "%self.__dict__)
log = ET.fromstring(xml)
result = []
def get(elementOrNot, xmlProperty) :
return 'none' if elementOrNot is None else elementOrNot.get(xmlProperty, 'none')
for entry in log.getiterator("entry") :
lstatus = entry.find("wc-status")
rstatus = entry.find("repos-status")
litem = get(lstatus,'item')
lprop = get(lstatus,'prop')
ritem = get(rstatus,'item')
rprop = get(rstatus,'prop')
result.append( ( entry.get('path'), ( litem, lprop, ritem, rprop)))
return result
def hasPendingChanges(self) :
for path, (litem, lprop, ritem, rprop) in self._pendingChanges() :
if litem == 'missing' : return True
if ritem != 'none' : return True
if rprop != 'none' : return True
return False