|
0
|
1 |
import django |
|
|
2 |
import os.path |
|
|
3 |
import re |
|
|
4 |
|
|
|
5 |
def get_svn_revision(path=None): |
|
|
6 |
""" |
|
|
7 |
Returns the SVN revision in the form SVN-XXXX, |
|
|
8 |
where XXXX is the revision number. |
|
|
9 |
|
|
|
10 |
Returns SVN-unknown if anything goes wrong, such as an unexpected |
|
|
11 |
format of internal SVN files. |
|
|
12 |
|
|
|
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 |
|
|
15 |
directory. |
|
|
16 |
""" |
|
|
17 |
rev = None |
|
|
18 |
if path is None: |
|
|
19 |
path = django.__path__[0] |
|
|
20 |
entries_path = '%s/.svn/entries' % path |
|
|
21 |
|
|
|
22 |
try: |
|
|
23 |
entries = open(entries_path, 'r').read() |
|
|
24 |
except IOError: |
|
|
25 |
pass |
|
|
26 |
else: |
|
|
27 |
# Versions >= 7 of the entries file are flat text. The first line is |
|
|
28 |
# the version number. The next set of digits after 'dir' is the revision. |
|
|
29 |
if re.match('(\d+)', entries): |
|
|
30 |
rev_match = re.search('\d+\s+dir\s+(\d+)', entries) |
|
|
31 |
if rev_match: |
|
|
32 |
rev = rev_match.groups()[0] |
|
|
33 |
# Older XML versions of the file specify revision as an attribute of |
|
|
34 |
# the first entries node. |
|
|
35 |
else: |
|
|
36 |
from xml.dom import minidom |
|
|
37 |
dom = minidom.parse(entries_path) |
|
|
38 |
rev = dom.getElementsByTagName('entry')[0].getAttribute('revision') |
|
|
39 |
|
|
|
40 |
if rev: |
|
|
41 |
return u'SVN-%s' % rev |
|
|
42 |
return u'SVN-unknown' |