5 def get_svn_revision(path
=None):
7 Returns the SVN revision in the form SVN-XXXX,
8 where XXXX is the revision number.
10 Returns SVN-unknown if anything goes wrong, such as an unexpected
11 format of internal SVN files.
13 If path is provided, it should be a directory whose SVN info you want to
14 inspect. If it's not provided, this will use the root django/ package
19 path
= django
.__path
__[0]
20 entries_path
= '%s/.svn/entries' % path
22 if os
.path
.exists(entries_path
):
23 entries
= open(entries_path
, 'r').read()
24 # Versions >= 7 of the entries file are flat text. The first line is
25 # the version number. The next set of digits after 'dir' is the revision.
26 if re
.match('(\d+)', entries
):
27 rev_match
= re
.search('\d+\s+dir\s+(\d+)', entries
)
29 rev
= rev_match
.groups()[0]
30 # Older XML versions of the file specify revision as an attribute of
31 # the first entries node.
33 from xml
.dom
import minidom
34 dom
= minidom
.parse(entries_path
)
35 rev
= dom
.getElementsByTagName('entry')[0].getAttribute('revision')
38 return u
'SVN-%s' % rev