-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathphablet-demo-setup
119 lines (104 loc) · 4.2 KB
/
phablet-demo-setup
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
#! /usr/bin/python
# This program is free software: you can redistribute it and/or modify it
# under the terms of the the GNU General Public License version 3, as
# published by the Free Software Foundation.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranties of
# MERCHANTABILITY, SATISFACTORY QUALITY or FITNESS FOR A PARTICULAR
# PURPOSE. See the applicable version of the GNU Lesser General Public
# License for more details.
#.
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
# Copyright (C) 2013 Canonical, Ltd.
import argparse
import logging
import tempfile
import StringIO
from phabletutils.device import AndroidBridge
logging.basicConfig(level=logging.INFO, format='%(message)s')
log = logging.getLogger()
log.name = 'phablet-demo-setup'
basic_template = '''#!/bin/sh
set -ex
apt-get update
'''
def parse_arguments():
'''Parses arguments passed in to script.'''
parser = argparse.ArgumentParser(
description='''phablet demo setup tool. Requires a prior run
of phablet-networking-setup -i. If called with
no options all demo content available is setup.''')
parser.add_argument('-s',
'--serial',
help='''Device serial. Use when more than
one device is connected.''',
)
parser.add_argument('--disable-fake-contacts',
action='store_true',
required=False,
default=False,
help='Disables setup of demo contacts.'
)
parser.add_argument('--disable-fake-messages',
action='store_true',
required=False,
default=False,
help='Disables setup of demo messages.'
)
parser.add_argument('--disable-fake-pictures',
action='store_true',
required=False,
default=False,
help='Disables setup of demo pictures.'
)
return parser.parse_args()
def setup_fake_pictures(script):
script.write('tar -C /home/phablet/Pictures/ --strip-components=1 -xzf '
'/usr/share/demo-assets/pictures.tgz\n')
script.write('chown -R phablet:phablet /home/phablet/Pictures\n')
return script
def setup_fake_conversations(script):
script.write('mkdir -p /home/phablet/.local/share/TpLogger/logs\n')
script.write('cp -aRp '
'/usr/share/demo-assets/telephony-app/ofono_ofono_account0 '
'/home/phablet/.local/share/TpLogger/logs\n')
script.write('chown -R phablet.phablet /home/phablet/.local/\n')
return script
def provision_device(serial, script):
script_dst = '/data/ubuntu/tmp/provision'
if serial:
adb = AndroidBridge(serial)
else:
adb = AndroidBridge()
adb.root()
adb.push(script, script_dst)
adb.chmod(script_dst, '700')
adb.chroot('tmp/provision')
log.info('Getting ready to restart')
adb.shell('sync')
adb.reboot()
def main(args):
script = StringIO.StringIO()
script.write(basic_template)
if not args.disable_fake_contacts:
log.info('Setting up for demo contacts')
script.write('/usr/bin/apt-get install -y demo-assets-contacts\n')
script = setup_fake_conversations(script)
if not args.disable_fake_messages:
log.info('Setting up for demo message notifications')
script.write('/usr/bin/apt-get install -y indicators-client-examples\n')
if not args.disable_fake_pictures:
log.info('Setting up for demo pictures')
script.write('/usr/bin/apt-get install -y demo-assets-pictures\n')
script = setup_fake_pictures(script)
script_file = tempfile.NamedTemporaryFile(delete=False)
with script_file as f:
f.write(script.getvalue())
script.close()
provision_device(args.serial, script_file.name)
if __name__ == "__main__":
args = parse_arguments()
main(args)