app/django/utils/version.py
author Daniel Bentley <dbentley@google.com>
Sun, 12 Apr 2009 09:06:45 +0000
branchgae-fetch-limitation-fix
changeset 2313 c39a81bce1bd
parent 1279 f85ac8856dca
permissions -rw-r--r--
Use offset_linkid instead of offset to scan >1000 entities. this is a first-cut. It works in all the ways I could make earlier versions fail. It passes link_id as URL parameters. It also has a new class LinkCreator which makes the main body of getListContents even easier to write. I wasn't sure if link_id's could have non alphanumeric characters; if so, they need to be URL encoded/decoded. I also need to go and remove any mention of raw offsets now, because we don't use them. I believe I've talked about this approach with a few of you and it sounded reasonable. Feel free to roll-back/fix/amend/comment-for-me-to-fix. This is my first big-logic-change to Melange. Patch by: Dan Bentley
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'