summaryrefslogtreecommitdiff
path: root/django/__init__.py
diff options
context:
space:
mode:
authorAymeric Augustin <aymeric.augustin@m4x.org>2012-04-29 13:40:10 +0200
committerAymeric Augustin <aymeric.augustin@m4x.org>2012-04-29 13:40:10 +0200
commit02a5b41db4ff8544f93a5d9854b346a9aae4f556 (patch)
treeb9041003697ed9a2e803cde8db12aed98a1b6f0b /django/__init__.py
parent905bd7fb44a0dbd0be0d455ab428c388714ae700 (diff)
Fixed #18224 -- Changed the dev version number.
Following the move from SVN to git.
Diffstat (limited to 'django/__init__.py')
-rw-r--r--django/__init__.py33
1 files changed, 28 insertions, 5 deletions
diff --git a/django/__init__.py b/django/__init__.py
index 20ca23496c..85cf02c9a4 100644
--- a/django/__init__.py
+++ b/django/__init__.py
@@ -1,5 +1,11 @@
+import datetime
+import os
+import subprocess
+
+
VERSION = (1, 5, 0, 'alpha', 0)
+
def get_version(version=None):
"""Derives a PEP386-compliant version number from VERSION."""
if version is None:
@@ -17,14 +23,31 @@ def get_version(version=None):
sub = ''
if version[3] == 'alpha' and version[4] == 0:
- # At the toplevel, this would cause an import loop.
- from django.utils.version import get_svn_revision
- svn_revision = get_svn_revision()[4:]
- if svn_revision != 'unknown':
- sub = '.dev%s' % svn_revision
+ git_changeset = get_git_changeset()
+ if git_changeset:
+ sub = '.dev%s' % git_changeset
elif version[3] != 'final':
mapping = {'alpha': 'a', 'beta': 'b', 'rc': 'c'}
sub = mapping[version[3]] + str(version[4])
return main + sub
+
+
+def get_git_changeset():
+ """Returns a numeric identifier of the latest git changeset.
+
+ The result is the UTC timestamp of the changeset in YYYYMMDDHHMMSS format.
+ This value isn't guaranteed to be unique but collisions are very unlikely,
+ so it's sufficient for generating the development version numbers.
+ """
+ repo_dir = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
+ git_show = subprocess.Popen('git show --pretty=format:%ct --quiet HEAD',
+ stdout=subprocess.PIPE, stderr=subprocess.PIPE,
+ shell=True, cwd=repo_dir, universal_newlines=True)
+ timestamp = git_show.communicate()[0].partition('\n')[0]
+ try:
+ timestamp = datetime.datetime.utcfromtimestamp(int(timestamp))
+ except ValueError:
+ return None
+ return timestamp.strftime('%Y%m%d%H%M%S')