-
Notifications
You must be signed in to change notification settings - Fork 2
/
write_version.py
98 lines (82 loc) · 2.93 KB
/
write_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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
#! /usr/bin/env python
#
# ESA (C) 2000-{creationyear}
#
# This file is part of ESA's XMM-Newton Scientific Analysis System (SAS).
#
# SAS 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.
#
# SAS 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 SAS. If not, see <http://www.gnu.org/licenses/>.
#
# write_version.py
#
# Writes version.py from $SAS_DIR/SasVersion.h.
# Values are written as constants to be used later on by importing them
# from version.py.
# The version of the package is also written as VERSION
# Standard library imports
import os, re
from datetime import date
# current date and year in string format
today = date.today()
creationyear = today.year
creationdate = today.strftime('%d-%b-%Y')
creationdate_chlog = today.strftime('%Y-%m-%d')
# readSasVersion reads the SAS release information from SasVersion.h
def readSasVersion(sas_dir):
sasversion_h = {}
sasversion_h_keys = [
'sas_compilation_date',
'sas_compilation_host',
'sas_compilation_user',
'sas_platform',
'sas_release',
'sas_aka'
]
with open(os.path.join(sas_dir, 'SasVersion.h')) as inf:
lines = inf.readlines()
for key in sasversion_h_keys:
for line in lines:
if key in line:
# [^"] = match any characterxs excluding "
# ([^"]*) = match any text excluding "
# '"([^"]*)"' = any text between " and "
k = re.findall(r'"([^"]*)"', line)
sasversion_h[key] = k[0]
return sasversion_h
# main
if __name__ == '__main__':
sas_dir = os.environ.get('SAS_DIR')
if sas_dir == None:
print('Error: sasver : SAS_DIR is undefined')
sys.exit()
pkgdir = '../../'
with open(os.path.join(pkgdir, 'VERSION')) as f:
v = f.readline().strip()
# reads the SasVersion.h
svh = readSasVersion(sas_dir)
# writes version.py taking version.py.in as template
with open('version.py.in') as inf, open('version.py', 'w') as outf:
template = inf.read()
outf.write(template.format(
creationdate=creationdate,
creationyear=creationyear,
release=svh['sas_release'],
aka=svh['sas_aka'],
date=svh['sas_compilation_date'],
host=svh['sas_compilation_host'],
user=svh['sas_compilation_user'],
platform=svh['sas_platform'],
version=v)
)
inf.close()
outf.close()