-
Notifications
You must be signed in to change notification settings - Fork 0
/
version.py
executable file
·57 lines (42 loc) · 1.42 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
version='2.0'
release=False
#-------------------------------------------------------------------------------------#
import commands
import datetime
import os
import glob
class CommandError(Exception):
pass
def execute_command(commandstring):
status, output = commands.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 file(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')
version_string = "%s-%s-%s" % (version, datestring, commithash)
except CommandError, IntegerError:
version_string = parse_version_from_package()
return version_string
if __name__ == '__main__':
print get_version()