-
Notifications
You must be signed in to change notification settings - Fork 0
/
version.py
70 lines (52 loc) · 1.74 KB
/
version.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# -*- coding: utf-8 -*-
from __future__ import absolute_import, unicode_literals
#-----------------------------------------------------------------------------#
version = '2.0.5'
release = False
#-----------------------------------------------------------------------------#
import sys
if (sys.version_info < (3, )):
from commands import getstatusoutput
else:
from subprocess import getstatusoutput # lint:ok
import datetime
import os
import glob
class CommandError(Exception):
pass
def execute_command(commandstring):
status, output = getstatusoutput(commandstring)
if status != 0:
raise CommandError
return output
def parse_version_from_package():
try:
pkginfo = os.path.join(glob.glob('*.egg-info')[0], 'PKG-INFO')
except:
pkginfo = ''
version_string = ''
if os.path.exists(pkginfo):
for line in open(pkginfo):
if line.find('Version: ') == 0:
version_string = line.strip().split('Version: ')[1].strip()
if not version_string:
version_string = '%s-dev' % version
else:
version_string = version
return version_string
def get_version():
try:
gitLog = execute_command('git log -1 --format="%ct-%H"')
(commitdate, dash, commithash) = gitLog.partition('-')
dt = datetime.datetime.utcfromtimestamp(float(commitdate))
datestring = dt.strftime('%Y%m%d%H%M%S')
if release:
version_string = version
else:
version_string = "%s.dev%s" % (version, datestring)
except CommandError:
version_string = parse_version_from_package()
return version_string
if __name__ == '__main__':
import sys
sys.stdout.write('{0}\n'.format(get_version()))