app/django/utils/version.py
author Pawel Solyga <Pawel.Solyga@gmail.com>
Thu, 12 Feb 2009 12:58:26 +0000
changeset 1279 f85ac8856dca
parent 54 03e267d67478
permissions -rw-r--r--
App Engine 1.1.9 update breaks django 1.0. Monkey patch django to only check for SVN revision number when not running using dev_appserver. On deployed version this doesn't apply since we use django from zipped file. This issue was discussed here: http://groups.google.com/group/codereview-discuss/browse_thread/thread/a7ab6ceb39c09ce6 http://groups.google.com/group/google-appengine/browse_thread/thread/bbdebf8617b57512 Patch by: Pawel Solyga Review by: to-be-reviewed
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
54
03e267d67478 Major reorganization of the soc svn repo, to merge into a single App Engine
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
     1
import django
03e267d67478 Major reorganization of the soc svn repo, to merge into a single App Engine
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
     2
import os.path
03e267d67478 Major reorganization of the soc svn repo, to merge into a single App Engine
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
     3
import re
03e267d67478 Major reorganization of the soc svn repo, to merge into a single App Engine
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
     4
03e267d67478 Major reorganization of the soc svn repo, to merge into a single App Engine
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
     5
def get_svn_revision(path=None):
03e267d67478 Major reorganization of the soc svn repo, to merge into a single App Engine
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
     6
    """
03e267d67478 Major reorganization of the soc svn repo, to merge into a single App Engine
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
     7
    Returns the SVN revision in the form SVN-XXXX,
03e267d67478 Major reorganization of the soc svn repo, to merge into a single App Engine
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
     8
    where XXXX is the revision number.
03e267d67478 Major reorganization of the soc svn repo, to merge into a single App Engine
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
     9
03e267d67478 Major reorganization of the soc svn repo, to merge into a single App Engine
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    10
    Returns SVN-unknown if anything goes wrong, such as an unexpected
03e267d67478 Major reorganization of the soc svn repo, to merge into a single App Engine
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    11
    format of internal SVN files.
03e267d67478 Major reorganization of the soc svn repo, to merge into a single App Engine
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    12
03e267d67478 Major reorganization of the soc svn repo, to merge into a single App Engine
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    13
    If path is provided, it should be a directory whose SVN info you want to
03e267d67478 Major reorganization of the soc svn repo, to merge into a single App Engine
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    14
    inspect. If it's not provided, this will use the root django/ package
03e267d67478 Major reorganization of the soc svn repo, to merge into a single App Engine
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    15
    directory.
03e267d67478 Major reorganization of the soc svn repo, to merge into a single App Engine
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    16
    """
03e267d67478 Major reorganization of the soc svn repo, to merge into a single App Engine
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    17
    rev = None
03e267d67478 Major reorganization of the soc svn repo, to merge into a single App Engine
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    18
    if path is None:
03e267d67478 Major reorganization of the soc svn repo, to merge into a single App Engine
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    19
        path = django.__path__[0]
03e267d67478 Major reorganization of the soc svn repo, to merge into a single App Engine
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    20
    entries_path = '%s/.svn/entries' % path
03e267d67478 Major reorganization of the soc svn repo, to merge into a single App Engine
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    21
1279
f85ac8856dca App Engine 1.1.9 update breaks django 1.0. Monkey patch django to only check for SVN revision number when not running using dev_appserver. On deployed version this doesn't apply since we use django from zipped file.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 54
diff changeset
    22
    if not os.environ['SERVER_SOFTWARE'].startswith('Dev'):
f85ac8856dca App Engine 1.1.9 update breaks django 1.0. Monkey patch django to only check for SVN revision number when not running using dev_appserver. On deployed version this doesn't apply since we use django from zipped file.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 54
diff changeset
    23
      if os.path.exists(entries_path):
f85ac8856dca App Engine 1.1.9 update breaks django 1.0. Monkey patch django to only check for SVN revision number when not running using dev_appserver. On deployed version this doesn't apply since we use django from zipped file.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 54
diff changeset
    24
          entries = open(entries_path, 'r').read()
f85ac8856dca App Engine 1.1.9 update breaks django 1.0. Monkey patch django to only check for SVN revision number when not running using dev_appserver. On deployed version this doesn't apply since we use django from zipped file.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 54
diff changeset
    25
          # Versions >= 7 of the entries file are flat text.  The first line is
f85ac8856dca App Engine 1.1.9 update breaks django 1.0. Monkey patch django to only check for SVN revision number when not running using dev_appserver. On deployed version this doesn't apply since we use django from zipped file.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 54
diff changeset
    26
          # the version number. The next set of digits after 'dir' is the revision.
f85ac8856dca App Engine 1.1.9 update breaks django 1.0. Monkey patch django to only check for SVN revision number when not running using dev_appserver. On deployed version this doesn't apply since we use django from zipped file.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 54
diff changeset
    27
          if re.match('(\d+)', entries):
f85ac8856dca App Engine 1.1.9 update breaks django 1.0. Monkey patch django to only check for SVN revision number when not running using dev_appserver. On deployed version this doesn't apply since we use django from zipped file.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 54
diff changeset
    28
              rev_match = re.search('\d+\s+dir\s+(\d+)', entries)
f85ac8856dca App Engine 1.1.9 update breaks django 1.0. Monkey patch django to only check for SVN revision number when not running using dev_appserver. On deployed version this doesn't apply since we use django from zipped file.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 54
diff changeset
    29
              if rev_match:
f85ac8856dca App Engine 1.1.9 update breaks django 1.0. Monkey patch django to only check for SVN revision number when not running using dev_appserver. On deployed version this doesn't apply since we use django from zipped file.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 54
diff changeset
    30
                  rev = rev_match.groups()[0]
f85ac8856dca App Engine 1.1.9 update breaks django 1.0. Monkey patch django to only check for SVN revision number when not running using dev_appserver. On deployed version this doesn't apply since we use django from zipped file.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 54
diff changeset
    31
          # Older XML versions of the file specify revision as an attribute of
f85ac8856dca App Engine 1.1.9 update breaks django 1.0. Monkey patch django to only check for SVN revision number when not running using dev_appserver. On deployed version this doesn't apply since we use django from zipped file.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 54
diff changeset
    32
          # the first entries node.
f85ac8856dca App Engine 1.1.9 update breaks django 1.0. Monkey patch django to only check for SVN revision number when not running using dev_appserver. On deployed version this doesn't apply since we use django from zipped file.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 54
diff changeset
    33
          else:
f85ac8856dca App Engine 1.1.9 update breaks django 1.0. Monkey patch django to only check for SVN revision number when not running using dev_appserver. On deployed version this doesn't apply since we use django from zipped file.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 54
diff changeset
    34
              from xml.dom import minidom
f85ac8856dca App Engine 1.1.9 update breaks django 1.0. Monkey patch django to only check for SVN revision number when not running using dev_appserver. On deployed version this doesn't apply since we use django from zipped file.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 54
diff changeset
    35
              dom = minidom.parse(entries_path)
f85ac8856dca App Engine 1.1.9 update breaks django 1.0. Monkey patch django to only check for SVN revision number when not running using dev_appserver. On deployed version this doesn't apply since we use django from zipped file.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 54
diff changeset
    36
              rev = dom.getElementsByTagName('entry')[0].getAttribute('revision')
54
03e267d67478 Major reorganization of the soc svn repo, to merge into a single App Engine
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    37
03e267d67478 Major reorganization of the soc svn repo, to merge into a single App Engine
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    38
    if rev:
03e267d67478 Major reorganization of the soc svn repo, to merge into a single App Engine
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    39
        return u'SVN-%s' % rev
03e267d67478 Major reorganization of the soc svn repo, to merge into a single App Engine
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    40
    return u'SVN-unknown'