author | Lennard de Rijk <ljvderijk@gmail.com> |
Sat, 14 Mar 2009 18:02:01 +0000 | |
changeset 1853 | 6cd70644892d |
parent 1279 | f85ac8856dca |
permissions | -rw-r--r-- |
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' |