37
34
import urllib.request
40
def copy_tree(src, dest, preserve_symlinks=False):
42
copy files from src to dest using rsync
44
links_option = "-l" if preserve_symlinks else "-L"
45
parent_dir = os.path.split(os.path.abspath(dest))[0]
46
# adding trailing slash if it's not already there
47
src = os.path.join(src, '')
48
if not os.path.exists(parent_dir):
49
os.makedirs(parent_dir)
50
subprocess.check_call(["rsync", "-a", links_option, src, dest])
52
def prepare_uris(get_autopilot):
53
"""Prepare cache and generate URIs for all packages."""
54
# additional packages needed to support autopilot tests. these were obtained by
55
# running apt-cache depends on python3-autopilot
56
ap_packages = ['python3-autopilot', 'python3-psutil', 'python3-testtools', 'python3-pil',
57
'libjs-jquery', 'libjs-underscore', 'libwebp5', 'libwebpmux1', 'python3-decorator',
58
'python3-testscenarios', 'python3-subunit', 'python3-fixtures', 'python3-junitxml',
59
'python3-extras', 'python3-evdev']
60
packages = ['libpython3.4', 'pyotherside', 'python3-xlsxwriter',
61
'python3-jinja2', 'python3-markupsafe', 'python3-padme',
62
'python3-requests', 'python3-urllib3', 'python3-guacamole',
63
'python3-requests-oauthlib']
65
packages += ap_packages
67
Source = collections.namedtuple('Source', ['uri', 'repositories'])
68
sources = [Source('http://ports.ubuntu.com/ubuntu-ports',
69
'main restricted universe'),
70
Source('http://ppa.launchpad.net/checkbox-dev/ppa/ubuntu',
72
with tempfile.TemporaryDirectory() as tmp:
73
new_etc_apt = os.path.join(tmp, 'etc', 'apt')
74
os.makedirs(new_etc_apt)
75
# copy over trusted.gpg
76
shutil.copyfile('/etc/apt/trusted.gpg',
77
os.path.join(new_etc_apt, 'trusted.gpg'))
78
# copy over additional keyrings
79
if os.path.exists('/etc/apt/trusted.gpg.d'):
80
shutil.copytree('/etc/apt/trusted.gpg.d',
81
os.path.join(new_etc_apt, 'trusted.gpg.d'))
82
sources_list = open(os.path.join(new_etc_apt, 'sources.list'), "w")
83
for source in sources:
85
"deb [arch=armhf] {uri} vivid {repositories}\n".format(
86
uri=source.uri, repositories=source.repositories))
88
apt_pkg.config["Apt::Architecture"] = 'armhf'
89
cache = apt.Cache(rootdir=tmp)
93
if pkg not in cache or len(cache[pkg].versions) < 1:
95
raise Exception('Package {0} not found!'.format(pkg))
96
# use first uri available
97
uris[pkg] = cache[pkg].versions[0].uri
98
# return filled dictionary
102
def get_package_from_url_and_extract(url, target_dir):
103
filename = os.path.join(target_dir, url.split('/')[-1])
104
print('retrieving {0}'.format(url))
105
urllib.request.urlretrieve(url, filename)
106
subprocess.check_call(["dpkg", "-x", filename, target_dir])
36
from utils import get_package_from_url_and_extract
37
from utils import prepare_uris
38
from utils import rsync_tree
109
41
def extract_plainbox(src_tarball, version):
112
44
members = [member for member in tarball.getmembers()
113
45
if member.name.startswith(
114
46
"plainbox-{}/plainbox/".format(version)) or
115
member.name.startswith(
47
member.name.startswith(
116
48
"plainbox-{}/plainbox.egg-info".format(version))]
117
49
tarball.extractall(tmp, members=members)
119
51
os.path.join(tmp, "plainbox-{}".format(version), "plainbox"),
120
52
os.path.join('lib', 'py', 'plainbox'),
121
53
preserve_symlinks=1)
122
54
# copy plainbox.egg
124
56
os.path.join(tmp, "plainbox-{}".format(version),
125
57
'plainbox.egg-info'),
126
58
os.path.join('lib', 'py', 'plainbox.egg-info'),
176
108
if args.plainbox_only:
177
109
# skip downloading rest of the libs
179
uris = prepare_uris(args.get_autopilot)
112
'libpython3.5', 'pyotherside', 'python3-xlsxwriter',
113
'python3-jinja2', 'python3-markupsafe', 'python3-padme',
114
'python3-requests', 'python3-urllib3', 'python3-guacamole',
115
'python3-requests-oauthlib']
116
# additional packages needed to support autopilot tests. these were obtained by
117
# running apt-cache depends on python3-autopilot
118
if args.get_autopilot:
120
'python3-autopilot', 'python3-psutil', 'python3-testtools',
121
'python3-pil', 'libjs-jquery', 'libjs-underscore', 'libwebp5',
122
'libwebpmux1', 'python3-decorator', 'python3-testscenarios',
123
'python3-subunit', 'python3-fixtures', 'python3-junitxml',
124
'python3-extras', 'python3-evdev']
125
uris = prepare_uris(packages)
180
126
# libs_urls contains list of .deb packages that will be downloaded and
181
127
# extracted. After extraction contents of ./usr/lib are copied to ./lib
183
129
with tempfile.TemporaryDirectory() as tmp:
184
130
get_package_from_url_and_extract(uris[lib], tmp)
185
131
# TODO: remove unwanted files from the extracted tree (e.g. *.h)
187
133
os.path.join(tmp, 'usr', 'lib'), 'lib',
188
134
preserve_symlinks=1)
189
135
# python3_libs_urls contains list of .deb packages that will be downloaded