Ticket #5215: version_by_svn.diff

File version_by_svn.diff, 1.7 KB (added by Deryck Hodge <deryck@…>, 17 years ago)

Patch to add SVN revision number to version string

  • __init__.py

     
    44    "Returns the version as a human-format string."
    55    v = '.'.join([str(i) for i in VERSION[:-1]])
    66    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())
    89    return v
  • utils/version.py

     
     1from os import path
     2import re
     3from xml.dom import minidom
     4import django
     5
     6def get_svn_revision():
     7    """
     8    Returns the SVN revision in the form SVN-XXXX
     9    where XXXX is the revision number.
     10
     11    Returns SVN-unknown if anything goes wrong.
     12    """
     13    rev = None
     14    entries_path = '%s/.svn/entries' % django.__path__[0]
     15
     16    if 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            dom = minidom.parse(entries_path)
     28            rev = dom.getElementsByTagName('entry')[0].getAttribute('revision')
     29
     30    if rev:
     31        return u'SVN-%s' % rev
     32    return u'SVN-unknown'
     33
Back to Top