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
|
#!/usr/bin/env python
import os
import sys
def _usage():
print('Usage: %s script [arg [arg...]]' % sys.argv[0])
print('Sets up a PYTHONPATH with our ci-utils so that python scripts '
'can be launched properly')
exit(0)
def _parse_args(args):
if not args or args[0] in ['-h', '--help', '-help']:
_usage()
return args[0], args
def _component_path(basedir, script):
'''return the path to the component of the script'''
script = os.path.abspath(script)
if basedir not in script:
exit('ERROR: scripts must reside in source tree')
script = script[len(basedir) + 1:]
return script.split('/')[0]
def main(args):
script, args = _parse_args(args)
here = os.path.abspath(os.path.dirname(__file__))
ci_utils = os.path.join(here, 'ci-utils')
comp = _component_path(here, script)
python_path = os.environ.get('PYTHONPATH')
if python_path:
python_path = '{}:{}:{}'.format(ci_utils, comp, python_path)
else:
python_path = '{}:{}'.format(ci_utils, comp)
os.environ['PYTHONPATH'] = python_path
os.execv(script, args)
if __name__ == '__main__':
exit(main(sys.argv[1:]))
|