forked from cibomahto/s3g
-
Notifications
You must be signed in to change notification settings - Fork 33
/
Copy pathsetup_s3g_env.py
90 lines (73 loc) · 2.17 KB
/
setup_s3g_env.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
import os
import sys
import subprocess
python_version = ".".join(sys.version.split()[0].split(".")[0:2])
req_eggs = [
'mock-1.0.1',
'lockfile-0.9.1',
'argparse-1.2.1',
'unittest2-0.5.1',
'pyserial-2.7_mb2.1'
]
req_eggs = [egg + '-py' + python_version + '.egg' for egg in req_eggs]
opt_eggs = [
'makerbot_driver-0.1.1'
]
opt_eggs = [egg + '-py' + python_version + '.egg' for egg in opt_eggs]
def find_egg(paths, egg):
for path in paths:
egg_in_path = os.path.join(path, egg)
if os.path.exists(egg_in_path):
return egg_in_path
return None
python_exe = sys.executable
env_dir = 'virtualenv'
if '2.6' == python_version:
env_dir += '26'
search_paths = sys.argv[1:]
virtualenv_command = [
python_exe,
'virtualenv.py',
'--never-download'
]
for path in search_paths:
virtualenv_command.append('--extra-search-dir=' + path)
virtualenv_command.append(env_dir)
try:
subprocess.check_call(virtualenv_command)
except subprocess.CalledProcessError as e:
print 'something went wrong calling virtualenv:'
print e
print '\nDid you forget to pass the path to the setuptools egg?'
sys.exit(2)
if 'win32' == sys.platform:
virtualenv_easy_install = os.path.join(env_dir, 'Scripts', 'easy_install.exe')
else:
virtualenv_easy_install = os.path.join(env_dir, 'bin', 'easy_install')
e_install = [virtualenv_easy_install, '-q']
missing_required_eggs = False
try:
for egg in req_eggs:
egg_found = find_egg(search_paths, egg)
if egg_found != None:
subprocess.check_call(e_install + [egg_found])
else:
print 'egg ' + egg + ' not found'
missing_required_eggs = True
except subprocess.CalledProcessError as e:
print 'something went wrong installing the required eggs'
sys.exit(4)
try:
for egg in opt_eggs:
egg_found = find_egg(search_paths, egg)
if egg_found != None:
subprocess.check_call(e_install + [egg_found])
else:
print 'skipping egg ' + egg
except subprocess.CalledProcessError as e:
print 'something went wrong installing the optional eggs'
sys.exit(5)
if missing_required_eggs:
print 'Some of the required eggs were not found.'
print '\nDid you forget to pass search paths for those eggs?'
sys.exit(6)