]> code.delx.au - pymsnt/blob - src/svninfo.py
* Python 2.5 doesn't always return longs from struct.unpack, so we have to be clever...
[pymsnt] / src / svninfo.py
1 #!/usr/bin/env python
2 # Copyright 2006 James Bunton <james@delx.cjb.net>
3 # Licensed for distribution under the GPL version 2, check COPYING for details
4
5 from twisted.words.xish.domish import parseFile
6
7 import os, os.path
8
9 class SVNVersion:
10 def __init__(self):
11 self.version = 0
12
13 def calcRevision(self, svndir):
14 entriesFile = os.path.join(svndir, "entries")
15 doc = parseFile(entriesFile)
16 for child in doc.elements():
17 try:
18 num = int(child.getAttribute("committed-rev"))
19 self.version = max(num, self.version)
20 except TypeError:
21 pass
22
23 def traverseDir(self, dirname):
24 for file in os.listdir(dirname):
25 if os.path.islink(file):
26 continue
27 if os.path.isdir(file):
28 path = os.path.join(dirname, file)
29 if file == ".svn":
30 self.calcRevision(path)
31 else:
32 self.traverseDir(path)
33
34 def getSVNVersion(dirname="."):
35 x = SVNVersion()
36 x.traverseDir(dirname)
37 return x.version
38
39 if __name__ == "__main__":
40 print getSVNVersion()
41