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

« back to all changes in this revision

Viewing changes to checkbox-touch/confinement/generate.py

  • 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 2015 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
 
import argparse
20
 
import json
21
 
import os
22
 
import string
23
 
import sys
24
 
 
25
 
 
26
 
CONTENT_HUB = """{
27
 
    "destination": [ "documents"],
28
 
    "source": [ "documents"],
29
 
    "share": [ "documents"]
30
 
}"""
31
 
 
32
 
APPARMOR = """{
33
 
    "policy_groups": [
34
 
        "networking",
35
 
        "webview",
36
 
        "content_exchange",
37
 
        "content_exchange_source"
38
 
    ],
39
 
    "policy_version": 1.2
40
 
}"""
41
 
 
42
 
 
43
 
DESKTOP = """[Desktop Entry]
44
 
Name=Checkbox-${partial_id}
45
 
Comment=${partial_id} - confined test from Checkbox
46
 
Exec=qmlscene -I lib/py/plainbox/data/plainbox-qml-modules/ -I providers/${provider_name}/data/ --checkbox-name=${full_checkbox_name} --job ../providers/${provider_name}/data/${qml_file} $$@ confinement/plainbox-confined-shell.qml
47
 
Icon=checkbox-touch.svg
48
 
Terminal=false
49
 
Type=Application
50
 
X-Ubuntu-Touch=true
51
 
"""
52
 
 
53
 
 
54
 
def generate_confinement(provider_name, partial_id, full_checkbox_name,
55
 
                         qml_file):
56
 
    # generate content-hub file
57
 
    target_dir = os.path.join('data', 'confined')
58
 
    if not os.path.exists(target_dir):
59
 
        os.makedirs(target_dir)
60
 
 
61
 
    content_hub_path = os.path.join(target_dir, partial_id + '-ch.json')
62
 
    with open(content_hub_path, "wt") as f:
63
 
        f.write(CONTENT_HUB)
64
 
 
65
 
    # generate apparmor file
66
 
    apparmor_path = os.path.join(target_dir, partial_id + '.apparmor')
67
 
    with open(apparmor_path, "wt") as f:
68
 
        f.write(APPARMOR)
69
 
 
70
 
    # generate desktop file
71
 
    desktop_path = os.path.join(target_dir, partial_id + '.desktop')
72
 
    template = string.Template(DESKTOP)
73
 
    with open(desktop_path, "wt") as f:
74
 
        f.write(template.substitute(
75
 
            partial_id=partial_id, provider_name=provider_name,
76
 
            full_checkbox_name=full_checkbox_name, qml_file=qml_file))
77
 
 
78
 
    base = 'providers/{provider_name}/data/confined/{partial_id}'.format(
79
 
        provider_name=provider_name, partial_id=partial_id)
80
 
    hook = {
81
 
        partial_id: {
82
 
            'apparmor': base + '.apparmor',
83
 
            'desktop': base + '.desktop',
84
 
            'content-hub': base + '-ch.json',
85
 
        }
86
 
    }
87
 
    return hook
88
 
 
89
 
 
90
 
def main():
91
 
    parser = argparse.ArgumentParser(
92
 
        description="Generate confinement files for Checkbox")
93
 
    parser.add_argument('--checkbox_version', action='store', type=str)
94
 
    parser.add_argument('job_ids', nargs='+')
95
 
    args = parser.parse_args()
96
 
    checkbox_name = ("com.ubuntu.checkbox_checkbox-touch_" +
97
 
                     args.checkbox_version)
98
 
 
99
 
    # check if current dir looks like a provider - very dumb heuristic
100
 
    if not os.path.exists('manage.py'):
101
 
        sys.exit("Current directory doesn't look like a plainbox provider")
102
 
    provider_name = os.path.split(os.getcwd())[-1]
103
 
 
104
 
    hooks = ''
105
 
    for job in args.job_ids:
106
 
        hook = generate_confinement(
107
 
            provider_name, job, checkbox_name, job + '.qml')
108
 
        hooks += json.dumps(hook, sort_keys=True, indent=4)[1:-1]
109
 
 
110
 
    print("Add following hooks to your checkbox-touch.manifest:")
111
 
    print(hooks)
112
 
 
113
 
 
114
 
if __name__ == '__main__':
115
 
    main()