~pieq/checkbox/fix-1484872-env-variables-forced-to-non-international

« back to all changes in this revision

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

  • Committer: Zygmunt Krynicki
  • Date: 2014-12-19 12:11:52 UTC
  • mto: This revision was merged to the branch mainline in revision 3516.
  • Revision ID: zygmunt.krynicki@canonical.com-20141219121152-y9vtxajhrd6e1c3l
cep: merge CEPs in to trunk

This patch merges CEPs (aka Checkbox Enhancement Proposals) into trunk.
Those lived on separately for a while as lp:checkbox/cep but in
retrospective nobody knows about them and this should give them some
more exposure. In addition, the move allows new features to land a CEP
document along, making review of complex new features easier to make as
their specification can be seen alongside the patches that implement it.

Due to bazaar limitations in merging separate repositories together I've
discarded history entries (not that there were many) and just added
those files in directly.

Signed-off-by: Zygmunt Krynicki <zygmunt.krynicki@canonical.com>

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