~jocave/checkbox/hybrid-amd-gpu-mods

« back to all changes in this revision

Viewing changes to checkbox-touch/get-libs

  • Committer: Sylvain Pineau
  • Date: 2014-07-29 16:05:54 UTC
  • mto: This revision was merged to the branch mainline in revision 3149.
  • Revision ID: sylvain.pineau@canonical.com-20140729160554-qev8887xbunn9tmi
checkbox-ng:launchers:checkbox-cli: The checkbox-cli launcher

Running the default whitelist (with the suite selection screen skipped)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#!/usr/bin/env python3
2
 
# this file is part of checkbox.
3
 
#
4
 
# copyright 2014 canonical ltd.
5
 
# written by:
6
 
#   maciej kisielewski <maciej.kisielewski@canonical.com>
7
 
#
8
 
# checkbox is free software: you can redistribute it and/or modify
9
 
# it under the terms of the gnu general public license version 3,
10
 
# as published by the free software foundation.
11
 
#
12
 
# checkbox is distributed in the hope that it will be useful,
13
 
# but without any warranty; without even the implied warranty of
14
 
# merchantability or fitness for a particular purpose.  see the
15
 
# gnu general public license for more details.
16
 
#
17
 
# you should have received a copy of the gnu general public license
18
 
# along with checkbox.  if not, see <http://www.gnu.org/licenses/>.
19
 
"""
20
 
Download and extract .deb packages necessary to run checkbox-touch
21
 
Extraction is done to specific directories as required by click package
22
 
 
23
 
For typical development iteration, after hacking something in plainbox,
24
 
run ./get-libs --plainbox-only
25
 
"""
26
 
 
27
 
import argparse
28
 
import os
29
 
import shutil
30
 
import subprocess
31
 
import sys
32
 
import tarfile
33
 
import tempfile
34
 
import urllib.request
35
 
 
36
 
from utils import get_package_from_url_and_extract
37
 
from utils import prepare_uris
38
 
from utils import rsync_tree
39
 
 
40
 
 
41
 
def extract_plainbox(src_tarball, version):
42
 
    with tempfile.TemporaryDirectory() as tmp:
43
 
        tarball = tarfile.open(src_tarball)
44
 
        members = [member for member in tarball.getmembers()
45
 
                   if member.name.startswith(
46
 
                       "plainbox-{}/plainbox/".format(version)) or
47
 
                   member.name.startswith(
48
 
                       "plainbox-{}/plainbox.egg-info".format(version))]
49
 
        tarball.extractall(tmp, members=members)
50
 
        rsync_tree(
51
 
            os.path.join(tmp, "plainbox-{}".format(version), "plainbox"),
52
 
            os.path.join('lib', 'py', 'plainbox'),
53
 
            preserve_symlinks=1)
54
 
        # copy plainbox.egg
55
 
        rsync_tree(
56
 
            os.path.join(tmp, "plainbox-{}".format(version),
57
 
                         'plainbox.egg-info'),
58
 
            os.path.join('lib', 'py', 'plainbox.egg-info'),
59
 
            preserve_symlinks=1)
60
 
 
61
 
 
62
 
def get_plainbox_from_pypi(version='0.22.2'):
63
 
    # plaibox_pypi contains URL from which to download plainbox
64
 
    plainbox_pypi = ('https://pypi.python.org/packages/source'
65
 
                     '/p/plainbox/plainbox-{}.tar.gz'.format(version))
66
 
    with tempfile.TemporaryDirectory() as tmp:
67
 
        filename = os.path.join(tmp, plainbox_pypi.split('/')[-1])
68
 
        print('retrieving {0}'.format(plainbox_pypi))
69
 
        urllib.request.urlretrieve(plainbox_pypi, filename)
70
 
        extract_plainbox(filename, version)
71
 
 
72
 
 
73
 
def get_local_plainbox():
74
 
    # TODO: user shouldn't specify version of local plainbox
75
 
    plainbox_setup_path = os.path.join(os.getcwd(), '..', 'plainbox',
76
 
                                       'setup.py')
77
 
    plainbox_version = subprocess.check_output([plainbox_setup_path,
78
 
        '--version']).decode(sys.stdout.encoding).strip()
79
 
 
80
 
    plainbox_setup_dir = os.path.split(plainbox_setup_path)[0]
81
 
    print('building local plainbox')
82
 
    ret = subprocess.check_call([plainbox_setup_path, '-q', 'sdist'],
83
 
                                cwd=plainbox_setup_dir)
84
 
    if ret != 0:
85
 
        raise Exception(
86
 
            "Could not build plainbox using {}. Check above output"
87
 
            .format(plainbox_setup_path))
88
 
    filename = os.path.join(plainbox_setup_dir, 'dist', 'plainbox-{}.tar.gz'
89
 
                            .format(plainbox_version))
90
 
    extract_plainbox(filename, plainbox_version)
91
 
 
92
 
 
93
 
def main():
94
 
    parser = argparse.ArgumentParser("Get necessary libs for checkbox-touch")
95
 
    parser.add_argument("--get-pypi-plainbox",
96
 
                        action='store_true',
97
 
                        help="Use plainbox downloaded from pypi")
98
 
    parser.add_argument("--plainbox-only", action='store_true',
99
 
                        help="Get plainbox only")
100
 
    parser.add_argument("--get-autopilot",
101
 
                        action='store_true',
102
 
                        help="Download libs for autopilot")
103
 
    args = parser.parse_args()
104
 
    if args.get_pypi_plainbox:
105
 
        get_plainbox_from_pypi()
106
 
    else:
107
 
        get_local_plainbox()
108
 
    if args.plainbox_only:
109
 
        # skip downloading rest of the libs
110
 
        return
111
 
    packages = [
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:
119
 
        packages += [
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)
126
 
    # libs_urls contains list of .deb packages that will be downloaded and
127
 
    # extracted. After extraction contents of ./usr/lib are copied to ./lib
128
 
    for lib in uris:
129
 
        with tempfile.TemporaryDirectory() as tmp:
130
 
            get_package_from_url_and_extract(uris[lib], tmp)
131
 
            # TODO: remove unwanted files from the extracted tree (e.g. *.h)
132
 
            rsync_tree(
133
 
                os.path.join(tmp, 'usr', 'lib'), 'lib',
134
 
                preserve_symlinks=1)
135
 
    # python3_libs_urls contains list of .deb packages that will be downloaded
136
 
    # and extracted. After extraction contents of
137
 
    # ./usr/lib/python3/dist-packages are copied to ./lib/py.
138
 
    python3_libs = ['python3-xlsxwriter', 'python3-jinja2',
139
 
                    'python3-markupsafe', 'python3-padme', 'python3-requests',
140
 
                    'python3-urllib3', 'python3-guacamole',
141
 
                    'python3-requests-oauthlib']
142
 
 
143
 
    # additional libs needed to support autopilot tests.  these were obtained by
144
 
    # running apt-cache depends on python3-autopilot
145
 
    python3_ap_libs = ['python3-autopilot', 'python3-psutil',
146
 
                       'python3-pil', 'python3-decorator', 'python3-testtools',
147
 
                       'python3-subunit', 'python3-testscenarios', 'python3-junitxml', 'python3-fixtures',
148
 
                       'python3-extras', 'python3-evdev']
149
 
    if args.get_autopilot:
150
 
        python3_libs += python3_ap_libs
151
 
    for pylib in [uris[lib] for lib in python3_libs]:
152
 
        with tempfile.TemporaryDirectory() as tmp:
153
 
            get_package_from_url_and_extract(pylib, tmp)
154
 
            rsync_tree(
155
 
                os.path.join(tmp, 'usr', 'lib', 'python3',
156
 
                             'dist-packages'),
157
 
                os.path.join('lib', 'py'),
158
 
                preserve_symlinks=1)
159
 
    with tempfile.TemporaryDirectory() as tmp:
160
 
        get_package_from_url_and_extract(uris['pyotherside'], tmp)
161
 
        src = os.path.join(
162
 
            tmp, 'usr', 'lib', 'arm-linux-gnueabihf', 'qt5', 'qml')
163
 
        dest = os.path.join('lib', 'arm-linux-gnueabihf')
164
 
        if os.path.exists(src) and os.path.isdir(src):
165
 
            rsync_tree(src, dest, preserve_symlinks=1)
166
 
 
167
 
    # Remove the python3.4 directory
168
 
    # currently it only holds a few config-directories with symlinks
169
 
    # and those are not used by anything from this location
170
 
    if os.path.exists('lib/python3.4'):
171
 
        shutil.rmtree('lib/python3.4')
172
 
 
173
 
 
174
 
if __name__ == "__main__":
175
 
    main()