Ticket #18224: 18224.patch
File 18224.patch, 4.0 KB (added by , 13 years ago) |
---|
-
django/__init__.py
diff --git a/django/__init__.py b/django/__init__.py index 20ca234..6191e26 100644
a b 1 import datetime 2 import os 3 import subprocess 4 5 1 6 VERSION = (1, 5, 0, 'alpha', 0) 2 7 8 3 9 def get_version(version=None): 4 10 """Derives a PEP386-compliant version number from VERSION.""" 5 11 if version is None: … … def get_version(version=None): 17 23 18 24 sub = '' 19 25 if version[3] == 'alpha' and version[4] == 0: 20 # At the toplevel, this would cause an import loop. 21 from django.utils.version import get_svn_revision 22 svn_revision = get_svn_revision()[4:] 23 if svn_revision != 'unknown': 24 sub = '.dev%s' % svn_revision 26 git_changeset = get_git_changeset() 27 if git_changeset: 28 sub = '.dev%s' % git_changeset 25 29 26 30 elif version[3] != 'final': 27 31 mapping = {'alpha': 'a', 'beta': 'b', 'rc': 'c'} 28 32 sub = mapping[version[3]] + str(version[4]) 29 33 30 34 return main + sub 35 36 37 def get_git_changeset(): 38 """Return an identifier the latest git changeset. 39 40 The result is the UTC timestamp of the changeset in YYYYMMDDHHMMSS format. 41 This value isn't guaranteed to be unique but collisions are very unlikely, 42 so it's sufficient for generating the development version numbers. 43 """ 44 repo_dir = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) 45 git_show = subprocess.Popen('git show --pretty=format:%ct --quiet HEAD', 46 stdout=subprocess.PIPE, stderr=subprocess.PIPE, 47 shell=True, cwd=repo_dir, universal_newlines=True) 48 timestamp = git_show.communicate()[0].partition('\n')[0] 49 try: 50 timestamp = datetime.datetime.utcfromtimestamp(int(timestamp)) 51 except ValueError: 52 return None 53 return timestamp.strftime('%Y%m%d%H%M%S') -
deleted file django/utils/version.py
diff --git a/django/utils/version.py b/django/utils/version.py deleted file mode 100644 index cb8623b..0000000
+ - 1 import django2 import re3 4 def get_svn_revision(path=None):5 """6 Returns the SVN revision in the form SVN-XXXX,7 where XXXX is the revision number.8 9 Returns SVN-unknown if anything goes wrong, such as an unexpected10 format of internal SVN files.11 12 If path is provided, it should be a directory whose SVN info you want to13 inspect. If it's not provided, this will use the root django/ package14 directory.15 """16 rev = None17 if path is None:18 path = django.__path__[0]19 entries_path = '%s/.svn/entries' % path20 21 try:22 entries = open(entries_path, 'r').read()23 except IOError:24 pass25 else:26 # Versions >= 7 of the entries file are flat text. The first line is27 # the version number. The next set of digits after 'dir' is the revision.28 if re.match('(\d+)', entries):29 rev_match = re.search('\d+\s+dir\s+(\d+)', entries)30 if rev_match:31 rev = rev_match.groups()[0]32 # Older XML versions of the file specify revision as an attribute of33 # the first entries node.34 else:35 from xml.dom import minidom36 dom = minidom.parse(entries_path)37 rev = dom.getElementsByTagName('entry')[0].getAttribute('revision')38 39 if rev:40 return u'SVN-%s' % rev41 return u'SVN-unknown' -
tests/regressiontests/version/tests.py
diff --git a/tests/regressiontests/version/tests.py b/tests/regressiontests/version/tests.py index 1a67483..9b849ee 100644
a b class VersionTests(TestCase): 8 8 def test_development(self): 9 9 ver_tuple = (1, 4, 0, 'alpha', 0) 10 10 # This will return a different result when it's run within or outside 11 # of a SVN checkout: 1.4.devNNNNNor 1.4.11 # of a git clone: 1.4.devYYYYMMDDHHMMSS or 1.4. 12 12 ver_string = get_version(ver_tuple) 13 13 self.assertRegexpMatches(ver_string, r'1\.4(\.dev\d+)?') 14 14