Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Fixed #5215 -- Added Subversion revision number to Django version str…

…ing. Thanks for the patch, Deryck Hodge

git-svn-id: http://code.djangoproject.com/svn/django/trunk@5990 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit a1e26b0105a7f6afc5d950556caf7f44ff35c9cf 1 parent a3a07af
Adrian Holovaty authored August 21, 2007
1  AUTHORS
@@ -136,6 +136,7 @@ answer newbie questions, and generally made Django that much better:
136 136
     Joe Heck <http://www.rhonabwy.com/wp/>
137 137
     Joel Heenan <joelh-django@planetjoel.com>
138 138
     hipertracker@gmail.com
  139
+    Deryck Hodge <http://www.devurandom.org/>
139 140
     Brett Hoerner <bretthoerner@bretthoerner.com>
140 141
     Ian Holsman <http://feh.holsman.net/>
141 142
     Kieran Holland <http://www.kieranholland.com>
3  django/__init__.py
@@ -4,5 +4,6 @@ def get_version():
4 4
     "Returns the version as a human-format string."
5 5
     v = '.'.join([str(i) for i in VERSION[:-1]])
6 6
     if VERSION[-1]:
7  
-        v += '-' + VERSION[-1]
  7
+        from django.utils.version import get_svn_revision
  8
+        v = '%s-%s-%s' % (v, VERSION[-1], get_svn_revision())
8 9
     return v
33  django/utils/version.py
... ...
@@ -0,0 +1,33 @@
  1
+import django
  2
+import os.path
  3
+import re
  4
+
  5
+def get_svn_revision():
  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
+    rev = None
  14
+    entries_path = '%s/.svn/entries' % django.__path__[0]
  15
+
  16
+    if os.path.exists(entries_path):
  17
+        entries = open(entries_path, 'r').read()
  18
+        # Versions >= 7 of the entries file are flat text.  The first line is
  19
+        # the version number. The next set of digits after 'dir' is the revision.
  20
+        if re.match('(\d+)', entries):
  21
+            rev_match = re.search('\d+\s+dir\s+(\d+)', entries)
  22
+            if rev_match:
  23
+                rev = rev_match.groups()[0]
  24
+        # Older XML versions of the file specify revision as an attribute of
  25
+        # the first entries node.
  26
+        else:
  27
+            from xml.dom import minidom
  28
+            dom = minidom.parse(entries_path)
  29
+            rev = dom.getElementsByTagName('entry')[0].getAttribute('revision')
  30
+
  31
+    if rev:
  32
+        return u'SVN-%s' % rev
  33
+    return u'SVN-unknown'

0 notes on commit a1e26b0

Please sign in to comment.
Something went wrong with that request. Please try again.