forked from crossbario/autobahn-python
-
Notifications
You must be signed in to change notification settings - Fork 0
/
inject-build-id.py
47 lines (41 loc) · 1.64 KB
/
inject-build-id.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
#!python
import os
if __name__ == '__main__':
_EVAR = "AUTOBAHN_BUILD_ID"
_SEARCH = "__build__ = u'00000'"
_REPLACE = "__build__ = u'{}'"
if _EVAR in os.environ:
files = []
try:
from autobahn import _version
except ImportError:
pass
else:
files.append(os.path.abspath(_version.__file__))
fn = 'autobahn/_version.py'
if os.path.exists(fn):
files.append(os.path.abspath(fn))
done = []
for fn in files:
if fn in done:
print('Skipping file "{}": already processed'.format(fn))
else:
with open(fn) as f:
contents = f.read()
build_id_stmt = _REPLACE.format(os.environ[_EVAR])
if contents.find(_SEARCH):
contents = contents.replace(_SEARCH, build_id_stmt)
print(contents)
with open(fn, 'w') as f:
f.write(contents)
f.flush()
print('Ok: replaced placeholder build ID in file "{}" with "{}"'.format(fn, build_id_stmt))
done.append(fn)
else:
if contents.find(build_id_stmt):
print('Skipping file "{}": build ID already correct')
else:
error_msg = 'Error: could not find search string "{}" to inject build ID in file "{}"'.format(_SEARCH, _version.__file__)
raise Exception(error_msg)
else:
print('Skipping injection of build ID: AUTOBAHN_BUILD_ID not set')