Fixed #7496 -- It's now possible to pickle SortedDicts with pickle protocol 2
[django.git] / django / utils / version.py
blobcf8085653f9462c7c916843de175dfce3fe0d030
1 import django
2 import os.path
3 import re
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.
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
15 directory.
16 """
17 rev = None
18 if path is None:
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)
28 if rev_match:
29 rev = rev_match.groups()[0]
30 # Older XML versions of the file specify revision as an attribute of
31 # the first entries node.
32 else:
33 from xml.dom import minidom
34 dom = minidom.parse(entries_path)
35 rev = dom.getElementsByTagName('entry')[0].getAttribute('revision')
37 if rev:
38 return u'SVN-%s' % rev
39 return u'SVN-unknown'