The Version of openslides can be written in openslides/__init__.py

This commit is contained in:
Oskar Hahn 2012-02-09 13:43:39 +01:00
parent 28170becb3
commit 21a13b4d1a
3 changed files with 47 additions and 27 deletions

View File

@ -1,3 +1,35 @@
VERSION = (1, 2, 0, 'alpha', 0)
from django.template import add_to_builtins
def get_version(version=None):
"""Derives a PEP386-compliant version number from VERSION."""
if version is None:
version = VERSION
assert len(version) == 5
assert version[3] in ('alpha', 'beta', 'rc', 'final')
# Now build the two parts of the version number:
# main = X.Y[.Z]
# sub = .devN - for pre-alpha releases
# | {a|b|c}N - for alpha, beta and rc releases
parts = 2 if version[2] == 0 else 3
main = '.'.join(str(x) for x in version[:parts])
sub = ''
if version[3] == 'alpha' and version[4] == 0:
mercurial_version = hg_version()
if mercurial_version != 'unknown':
sub = '.dev%s' % mercurial_version
elif version[3] != 'final':
mapping = {'alpha': 'a', 'beta': 'b', 'rc': 'c'}
sub = mapping[version[3]] + str(version[4])
return main + sub
def hg_version():
import socket import socket
import os import os
import sys import sys
@ -8,21 +40,10 @@ try:
from mercurial.node import short as shorthex from mercurial.node import short as shorthex
from mercurial.error import RepoError from mercurial.error import RepoError
nomercurial = False nomercurial = False
except: except ImportError:
nomercurial = True return 'unknown'
from django.template import add_to_builtins
add_to_builtins('django.templatetags.i18n')
OPENSLIDES_REVISION = 'unknown'
# Don't read ~/.hgrc, as extensions aren't available in the venvs
os.environ['HGRCPATH'] = '' os.environ['HGRCPATH'] = ''
def _bootstrap():
conts = realpath(join(dirname(__file__))) conts = realpath(join(dirname(__file__)))
try: try:
ui = hgui.ui() ui = hgui.ui()
@ -30,13 +51,13 @@ def _bootstrap():
#repository = localrepository(ui, conts) #repository = localrepository(ui, conts)
ctx = repository['.'] ctx = repository['.']
if ctx.tags() and ctx.tags() != ['tip']: if ctx.tags() and ctx.tags() != ['tip']:
revision = ' '.join(ctx.tags()) version = ' '.join(ctx.tags())
else: else:
revision = '%(num)s:%(id)s' % { version = '%(num)s:%(id)s' % {
'num': ctx.rev(), 'id': shorthex(ctx.node()) 'num': ctx.rev(), 'id': shorthex(ctx.node())
} }
except TypeError: except TypeError:
revision = 'unknown' version = 'unknown'
except RepoError: except RepoError:
return 0 return 0
@ -46,8 +67,7 @@ def _bootstrap():
# The value *must* be a floating point value. # The value *must* be a floating point value.
socket.setdefaulttimeout(10.0) socket.setdefaulttimeout(10.0)
return revision return version
if not nomercurial:
OPENSLIDES_REVISION = _bootstrap() add_to_builtins('django.templatetags.i18n')
del _bootstrap

View File

@ -79,7 +79,7 @@
<div id="footer"> <div id="footer">
<small> <small>
&copy; Copyright 2011 | Powered by <a href="http://openslides.org">OpenSlides</a><br /> &copy; Copyright 2011 | Powered by <a href="http://openslides.org">OpenSlides</a><br />
Version: {{ OPENSLIDES_REVISION }} Version: {{ openslides_version }}
</small> </small>
</div> </div>
</div> </div>

View File

@ -25,10 +25,10 @@ from django.contrib import messages
from django.contrib.auth.models import Permission from django.contrib.auth.models import Permission
from django.utils.translation import ugettext as _ from django.utils.translation import ugettext as _
from openslides import OPENSLIDES_REVISION from openslides import get_version
def revision(request): def revision(request):
return {'OPENSLIDES_REVISION': OPENSLIDES_REVISION} return {'openslides_version': get_version()}
def gen_confirm_form(request, message, url): def gen_confirm_form(request, message, url):