forked from robotics-at-maryland/tortuga
-
Notifications
You must be signed in to change notification settings - Fork 0
/
bootstrap.py
197 lines (165 loc) · 7.01 KB
/
bootstrap.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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
# Copyright (C) 2007 Maryland Robotics Club
# Copyright (C) 2007 Joseph Lisee <[email protected]>
# All rights reserved.
#
# Author: Joseph Lisee <[email protected]>
# File: bootstrap.py
import os
import sys
import subprocess, re, getpass, platform
from buildfiles.common import util
from optparse import OptionParser
# Check Python Version, ensure 2.5.x
PYTHON_VERSION_STR = util.python_version_str()
ROOT_DIR = os.path.abspath(sys.path[0])
DEFAULT_TASKS = ['setup_directories',
'install_python_modules',
'gen_setenv']
DEFAULT_PREFIX = util.ram_prefix()
PYTHON_SITE_PACKAGE_SUFFIX = util.site_packages_suffix()
archives = ('boost-1.45.7z', 'fann-2.1.0.7z', 'gccxml-0.9.0.7z',
'log4cpp-1.0.0.7z', 'python-ogre-1.6.4.7z', 'segment-1.0.7z',
'unittestpp-1.3.7z')
platforms = {
('Ubuntu', '8.04', 'hardy') : 'ubuntu_804',
('Ubuntu', '8.10', 'intrepid') : 'ubuntu_810',
('Ubuntu', '9.04', 'jaunty') : 'ubuntu_904',
('Ubuntu', '9.10', 'karmic') : 'ubuntu_910',
('Ubuntu', '10.04', 'lucid') : 'ubuntu_1004',
('Ubuntu', '10.10', 'maverick') : 'ubuntu_1010',
('Ubuntu', '11.04', 'natty') : 'ubuntu_1104',
('LinuxMint', '11', 'katya') : 'ubuntu_1104',
}
class dependency(object):
def __init__(self, name, packages):
self._name = name
if isinstance(packages, str):
packages = packages.split(' ')
self.depends = packages
@property
def name(self):
return self._name
@property
def install_targets(self):
return self.depends[:]
def setup_dependencies():
# run dpkg and only continue if there's no error
re_install = re.compile(r'([^\s]+)\s+([^\s]+)')
try:
dpkg = subprocess.Popen(['dpkg', '--get-selections'],
stdout = subprocess.PIPE)
except OSError:
# dpkg doesn't exist
return
# setup dependency information
deps = []
deps.append(dependency('essential', 'build-essential p7zip'))
deps.append(dependency('cmake', 'cmake'))
deps.append(dependency('python', 'python-dev python-numpy'))
deps.append(dependency('opencv', 'libcv-dev libhighgui-dev libcvaux-dev'))
deps.append(dependency('dc1394', 'libdc1394-22-dev'))
deps.append(dependency('opengl', 'mesa-common-dev libglu1-mesa-dev'))
deps.append(dependency('libusb', 'libusb-dev'))
deps.append(dependency('wx', 'python-wxgtk2.8 libwxgtk2.8-dev'))
# uncomment when fann is fixed in ubuntu
#deps.append(dependency('fann', 'libfann-dev'))
deps.append(dependency('fftw', 'libfftw3-dev'))
# find all packages we're interested in
interesting_packages = set()
for d in deps:
interesting_packages.update(d.install_targets)
depends = {}
for name, status in (x.groups()
for x in (re_install.search(y)
for y in dpkg.communicate()[0].split('\n'))
if x):
if name in interesting_packages:
depends[name] = status
# find what packages we actually need to install
to_install = [x for x in interesting_packages
if not depends.has_key(x) or depends[x] != 'install']
# execute command to install needed packages (requires root)
if to_install:
cmd = ['apt-get', 'install']
cmd.extend(to_install)
if os.geteuid() != 0: # insert sudo to get root privelages
cmd.insert(0, 'sudo')
subprocess.call(cmd)
def download_precompiled(quiet=False):
# find the correct url
arch = 'x86' if re.search(r'i\d86', platform.machine()) else 'x86_64'
if arch == 'x86_64':
print 'warning: x86_64 architecture is not fully supported'
distro = platform.linux_distribution()
if not platforms.has_key(distro):
print 'error: download feature is not supported for this platform %r' % distro
return
distro = platforms[distro]
file_exists, join_path = os.path.exists, os.path.join
needed = [x for x in archives
if not file_exists(join_path('/opt/ram/local', x))]
if needed:
url = 'https://ram.umd.edu/software/%s/%s' % (arch, distro)
print 'authentication for %s' % url
username = raw_input('username: ')
password = getpass.getpass('password: ')
call = subprocess.call
if quiet:
def call(*args, **kwargs):
return subprocess.call(*args, stdout=open(os.devnull), stderr=open(os.devnull), **kwargs)
for dep in needed:
dest = join_path('/opt/ram/local', dep)
subprocess.call(['wget', '--user', username,
'--password', password, '--no-check-certificate',
'%s/%s' % (url, dep)], cwd = '/opt/ram/local')
subprocess.call(['7zr', 'x', dest], cwd = '/opt/ram/local')
print 'success: all archives installed'
def main(argv=None):
# Parse Arguments
parser = OptionParser()
parser.set_defaults(task = str(DEFAULT_TASKS), prefix = DEFAULT_PREFIX)
parser.add_option('-t','--task', nargs = 1,
help = 'Bootstrap tasks to run', default = None)
parser.add_option('-p','--prefix', nargs = 1,
help = 'The prefix to install all packages into'
' [default: %default]')
parser.add_option('--download', action='store_true', dest='download',
help = 'Turn on automatic downloading of dependencies')
parser.add_option('-q', '--quiet', action='store_true')
(options, args) = parser.parse_args()
site_package_dir = os.path.join(options.prefix, PYTHON_SITE_PACKAGE_SUFFIX)
if options.download:
setup_dependencies()
download_precompiled(options.quiet)
# Buildit imports
util.ensure_buildit_installed(ROOT_DIR, site_package_dir, options.prefix)
from buildit.context import Context
from buildit.context import Software
# Make sure out site package dir is on the python path
default_path = os.environ.get('PYTHONPATH', '')
os.environ['PYTHONPATH'] = site_package_dir + os.pathsep + default_path
# Task information
import buildfiles.bootstrap.tasks as build_tasks
# Create and check buildit context
context = Context(os.path.join(ROOT_DIR, 'buildfiles', 'bootstrap',
'root.ini'))
context.globals['ram_prefix'] = options.prefix
context.globals['python_version_str'] = PYTHON_VERSION_STR
context.globals['py_site_packages'] = site_package_dir
context.globals['py_site_packages_suffix'] = PYTHON_SITE_PACKAGE_SUFFIX
context.globals['python_executable'] = sys.executable
# Determing and run build tasks
if options.task is not None:
tasks = [options.task]
elif len(args) > 0:
tasks = args
else:
tasks = DEFAULT_TASKS
for task_name in tasks:
print 'Attempting Task',task_name
task = getattr(build_tasks, task_name)
software = Software(task, context)
software.install()
return 0
if __name__ == "__main__":
sys.exit(main())