forked from v3io/dockerregistrypusher
-
Notifications
You must be signed in to change notification settings - Fork 0
/
install
executable file
·72 lines (53 loc) · 2.12 KB
/
install
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
#!/usr/bin/env python3
import os
import sys
import argparse
import subprocess
def run(command):
subprocess.check_call(['/bin/bash', '-c', command],
stdout=sys.stdout, stderr=sys.stderr)
def register_arguments():
parser = argparse.ArgumentParser()
parser.add_argument('-o', '--offline-install-path', help='The dir path to install pip packages from.')
parser.add_argument('--no-link', action='store_true',
help='Do not remove or create symlink')
parser.add_argument('--dev', action='store_true',
help='Install dev requirements in addition to common requirements')
return parser.parse_args()
def _create_sym_link():
# symlink to run
ln_cmd = 'ln -sfF {0}/dockerregistrypusher /usr/local/bin/dockerregistrypusher'.format(os.getcwd())
# first try without sudo, then with
try:
run(ln_cmd)
except subprocess.CalledProcessError:
run('sudo {0}'.format(ln_cmd))
def main():
args = register_arguments()
if args.offline_install_path is None:
local_pip_packages = ''
else:
local_pip_packages = '--no-index --find-links=file:{}'.format(
args.offline_install_path)
retval = 0
try:
requirements_file = 'requirements.txt'
if args.dev:
requirements_file = 'requirements_all.txt'
# create venv, activate it and install requirements to it
# (from a local dir if it exists)
# "python -m pip install" instead of "pip install" handles a pip
# issue where it fails in a long-named dir
run('virtualenv --python=python3 venv && '
'source venv/bin/activate && '
'python -m pip install {0} incremental && '.format(local_pip_packages) +
'python -m pip install {0} -r {1}'.format(local_pip_packages, requirements_file))
if not args.no_link:
_create_sym_link()
except subprocess.CalledProcessError as e:
retval = e.returncode
else:
print('Installation complete. Enjoy your dockerregistrypusher!')
sys.exit(retval)
if __name__ == '__main__':
main()