]> code.delx.au - pymsnt/blob - src/svninfo.py
Added SVN version number to result from jabber:iq:version requests.
[pymsnt] / src / svninfo.py
1 #!/usr/bin/env python
2
3 from tlib.xmlw import parseFile
4
5 import os, os.path
6
7 class SVNVersion:
8 def __init__(self):
9 self.version = 0
10
11 def calcRevision(self, svndir):
12 entriesFile = os.path.join(svndir, "entries")
13 doc = parseFile(entriesFile)
14 for child in doc.elements():
15 try:
16 num = int(child.getAttribute("committed-rev"))
17 self.version = max(num, self.version)
18 except TypeError:
19 pass
20
21 def traverseDir(self, dirname):
22 for file in os.listdir(dirname):
23 if os.path.islink(file):
24 continue
25 if os.path.isdir(file):
26 path = os.path.join(dirname, file)
27 if file == ".svn":
28 self.calcRevision(path)
29 else:
30 self.traverseDir(path)
31
32 def getSVNVersion(dirname="."):
33 x = SVNVersion()
34 x.traverseDir(dirname)
35 return x.version
36
37 if __name__ == "__main__":
38 print getSVNVersion()
39