Project

General

Profile

Statistics
| Branch: | Revision:

root / env / lib / python2.7 / site-packages / django / utils / version.py @ 1a305335

History | View | Annotate | Download (1.31 KB)

1 1a305335 officers
import django
2
import re
3
4
def get_svn_revision(path=None):
5
    """
6
    Returns the SVN revision in the form SVN-XXXX,
7
    where XXXX is the revision number.
8

9
    Returns SVN-unknown if anything goes wrong, such as an unexpected
10
    format of internal SVN files.
11

12
    If path is provided, it should be a directory whose SVN info you want to
13
    inspect. If it's not provided, this will use the root django/ package
14
    directory.
15
    """
16
    rev = None
17
    if path is None:
18
        path = django.__path__[0]
19
    entries_path = '%s/.svn/entries' % path
20
21
    try:
22
        entries = open(entries_path, 'r').read()
23
    except IOError:
24
        pass
25
    else:
26
        # Versions >= 7 of the entries file are flat text.  The first line is
27
        # the version number. The next set of digits after 'dir' is the revision.
28
        if re.match('(\d+)', entries):
29
            rev_match = re.search('\d+\s+dir\s+(\d+)', entries)
30
            if rev_match:
31
                rev = rev_match.groups()[0]
32
        # Older XML versions of the file specify revision as an attribute of
33
        # the first entries node.
34
        else:
35
            from xml.dom import minidom
36
            dom = minidom.parse(entries_path)
37
            rev = dom.getElementsByTagName('entry')[0].getAttribute('revision')
38
39
    if rev:
40
        return u'SVN-%s' % rev
41
    return u'SVN-unknown'