Fix get_version, insert and use get_git_commit_id.

This commit is contained in:
Norman Jäckel 2012-11-23 11:31:30 +01:00
parent a029a66a7c
commit baebfbb585
2 changed files with 32 additions and 21 deletions

View File

@ -5,7 +5,8 @@
:license: GNU GPL, see LICENSE for more details. :license: GNU GPL, see LICENSE for more details.
""" """
VERSION = (1, 3, 0, 'beta', 2) VERSION = (1, 3, 0, 'final', 0) # During development it is the next release
RELEASE = False
def get_version(version=None): def get_version(version=None):
@ -16,29 +17,33 @@ def get_version(version=None):
if version is None: if version is None:
version = VERSION version = VERSION
assert len(version) == 5 assert len(version) == 5
assert version[3] in ('dev', 'alpha', 'beta', 'rc', 'final') assert version[3] in ('alpha', 'beta', 'rc', 'final')
# Now build the two parts of the version number: # Now build the two parts of the version number:
# main = X.Y[.Z] # main = X.Y[.Z]
# sub = {a|b|c}N for alpha, beta and rc releases # sub = {a|b|c}N for alpha, beta and rc releases
# git's commit id is added # Add '-dev', if it is not a release commit
main_parts = 2 if version[2] == 0 else 3 main_parts = 2 if version[2] == 0 else 3
main = '.'.join(str(x) for x in version[:main_parts]) main = '.'.join(str(x) for x in version[:main_parts])
if version[3] != 'final': if version[3] != 'final':
if version[3] == 'dev': mapping = {'alpha': 'a', 'beta': 'b', 'rc': 'c'}
try: sub = mapping[version[3]] + str(version[4])
git_head_path = '.git/' + open('.git/HEAD', 'r').read()[5:].rstrip()
except IOError:
git_commit_id = 'unknown'
else:
import os
git_commit_id = open(os.path.abspath(git_head_path), 'r').read().rstrip()
sub = '-%s%s' % (version[3], git_commit_id)
else:
sub = '-' + version[3] + str(version[4])
else: else:
sub = '' sub = ''
if not RELEASE:
sub += '-dev'
return main + sub return main + sub
def get_git_commit_id():
"""
Catches the commit id of the git head.
"""
try:
git_head = open('.git/HEAD', 'r').read().rstrip()
if True: #starts with 'ref: '
git_commit_id = open('.git/%s' % git_head[5:], 'r').read().rstrip()
else:
git_commit_id = git_head
except IOError:
git_commit_id = 'unknown'
return str(git_commit_id)

View File

@ -17,7 +17,7 @@ from django.core.urlresolvers import reverse
from django.utils.importlib import import_module from django.utils.importlib import import_module
from django.utils.translation import ugettext as _ from django.utils.translation import ugettext as _
from openslides import get_version from openslides import get_version, get_git_commit_id, RELEASE
from openslides.utils.template import Tab from openslides.utils.template import Tab
from openslides.utils.views import FormView, TemplateView from openslides.utils.views import FormView, TemplateView
@ -94,7 +94,14 @@ class VersionConfig(TemplateView):
def get_context_data(self, **kwargs): def get_context_data(self, **kwargs):
context = super(VersionConfig, self).get_context_data(**kwargs) context = super(VersionConfig, self).get_context_data(**kwargs)
context['versions'] = [('OpenSlides', get_version())]
# OpenSlides version. During development the git commit id is added.
openslides_version_string = get_version()
if not RELEASE:
openslides_version_string += ' Commit: %s' % get_git_commit_id()
context['versions'] = [('OpenSlides', openslides_version_string)]
# Version of plugins.
for plugin in settings.INSTALLED_PLUGINS: for plugin in settings.INSTALLED_PLUGINS:
try: try:
mod = import_module(plugin) mod = import_module(plugin)
@ -105,7 +112,6 @@ class VersionConfig(TemplateView):
plugin_name = mod.NAME plugin_name = mod.NAME
except AttributeError: except AttributeError:
plugin_name = mod.__name__.split('.')[0] plugin_name = mod.__name__.split('.')[0]
context['versions'].append((plugin_name, plugin_version)) context['versions'].append((plugin_name, plugin_version))
return context return context