diff options
| author | Adrian Holovaty <adrian@holovaty.com> | 2007-08-21 03:08:02 +0000 |
|---|---|---|
| committer | Adrian Holovaty <adrian@holovaty.com> | 2007-08-21 03:08:02 +0000 |
| commit | a1e26b0105a7f6afc5d950556caf7f44ff35c9cf (patch) | |
| tree | 8734e5589b3df249dbc9aa501585c798d2117358 /django/utils/version.py | |
| parent | a3a07af91060363e21cad1621820cae5f2bf9524 (diff) | |
Fixed #5215 -- Added Subversion revision number to Django version string. Thanks for the patch, Deryck Hodge
git-svn-id: http://code.djangoproject.com/svn/django/trunk@5990 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'django/utils/version.py')
| -rw-r--r-- | django/utils/version.py | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/django/utils/version.py b/django/utils/version.py new file mode 100644 index 0000000000..dd8345d8d2 --- /dev/null +++ b/django/utils/version.py @@ -0,0 +1,33 @@ +import django +import os.path +import re + +def get_svn_revision(): + """ + Returns the SVN revision in the form SVN-XXXX, + where XXXX is the revision number. + + Returns SVN-unknown if anything goes wrong, such as an unexpected + format of internal SVN files. + """ + rev = None + entries_path = '%s/.svn/entries' % django.__path__[0] + + if os.path.exists(entries_path): + entries = open(entries_path, 'r').read() + # Versions >= 7 of the entries file are flat text. The first line is + # the version number. The next set of digits after 'dir' is the revision. + if re.match('(\d+)', entries): + rev_match = re.search('\d+\s+dir\s+(\d+)', entries) + if rev_match: + rev = rev_match.groups()[0] + # Older XML versions of the file specify revision as an attribute of + # the first entries node. + else: + from xml.dom import minidom + dom = minidom.parse(entries_path) + rev = dom.getElementsByTagName('entry')[0].getAttribute('revision') + + if rev: + return u'SVN-%s' % rev + return u'SVN-unknown' |
