Skip to content

Commit

Permalink
add version handler
Browse files Browse the repository at this point in the history
  • Loading branch information
hisham waleed karam committed Aug 5, 2018
1 parent 9002ab3 commit 54f09de
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 4 deletions.
4 changes: 2 additions & 2 deletions cartoview/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@


def get_current_version():
import geonode.version
return geonode.version.get_version(__version__)
from .version import get_version
return get_version(__version__)
71 changes: 69 additions & 2 deletions cartoview/version.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,75 @@
import datetime
import json
import os
import subprocess
from cartoview import __compatible_with__, __version__

from geonode.version import get_version
# -*- coding: utf-8 -*-
#########################################################################
#
# Copyright (C) 2016 OSGeo
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
#########################################################################

from cartoview import __compatible_with__, __version__

def get_version(version=None):
"Returns a PEP 386-compliant version number from VERSION."
if version is None:
from cartoview import __version__ as version
else:
assert len(version) == 5
assert version[3] in ('unstable', '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] == 'unstable':
git_changeset = get_git_changeset()
if git_changeset:
sub = '.dev%s' % git_changeset

elif version[3] != 'final':
mapping = {'beta': 'b', 'rc': 'rc'}
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')


def get_current_version():
Expand Down

0 comments on commit 54f09de

Please sign in to comment.