|
1 #!/usr/bin/env python |
|
2 # |
|
3 # This Source Code Form is subject to the terms of the Mozilla Public |
|
4 # License, v. 2.0. If a copy of the MPL was not distributed with this |
|
5 # file, You can obtain one at http://mozilla.org/MPL/2.0/. |
|
6 |
|
7 import argparse |
|
8 import json |
|
9 import os |
|
10 import shutil |
|
11 import stat |
|
12 import subprocess |
|
13 import sys |
|
14 |
|
15 from ConfigParser import ConfigParser |
|
16 from smoketest import * |
|
17 |
|
18 this_dir = os.path.abspath(os.path.dirname(__file__)) |
|
19 |
|
20 def stage_update(device, stage_dir): |
|
21 config = SmokeTestConfig(stage_dir) |
|
22 if device not in config.devices: |
|
23 raise SmokeTestConfigError('Device "%s" not found' % device) |
|
24 |
|
25 device_data = config.devices[device] |
|
26 |
|
27 b2g_config = b2g.import_update_tools().B2GConfig() |
|
28 target_out_dir = os.path.join(b2g.homedir, 'out', 'target', 'product', device) |
|
29 app_ini = os.path.join(b2g_config.gecko_objdir, 'dist', 'bin', |
|
30 'application.ini') |
|
31 gecko_mar = os.path.join(b2g_config.gecko_objdir, 'dist', 'b2g-update', |
|
32 'b2g-gecko-update.mar') |
|
33 |
|
34 build_data = ConfigParser() |
|
35 build_data.read(app_ini) |
|
36 build_id = build_data.get('App', 'buildid') |
|
37 app_version = build_data.get('App', 'version') |
|
38 |
|
39 build_dir = os.path.join(config.top_dir, device, build_id) |
|
40 if not os.path.exists(build_dir): |
|
41 os.makedirs(build_dir) |
|
42 |
|
43 if not os.path.exists(build_dir): |
|
44 raise SmokeTestError('Couldn\'t create directory: %s' % build_dir) |
|
45 |
|
46 build_flash_fota = os.path.join(b2g.update_tools, 'build-flash-fota.py') |
|
47 |
|
48 flash_zip = os.path.join(build_dir, 'flash.zip') |
|
49 |
|
50 print 'Building flash zip for device %s, version %s, build %s...' % \ |
|
51 (device, app_version, build_id) |
|
52 |
|
53 subprocess.check_call([sys.executable, build_flash_fota, |
|
54 '--system-dir', os.path.join(target_out_dir, 'system'), |
|
55 '--system-fs-type', device_data.system_fs_type, |
|
56 '--system-location', device_data.system_location, |
|
57 '--data-fs-type', device_data.data_fs_type, |
|
58 '--data-location', device_data.data_location, |
|
59 '--output', flash_zip]) |
|
60 |
|
61 complete_mar = os.path.join(build_dir, 'complete.mar') |
|
62 shutil.copy(gecko_mar, complete_mar) |
|
63 |
|
64 flash_template = open(os.path.join(this_dir, 'flash-template.sh')).read() |
|
65 flash_script = os.path.join(build_dir, 'flash.sh') |
|
66 open(os.path.join(build_dir, 'flash.sh'), 'w').write(flash_template % { |
|
67 'flash_zip': flash_zip, |
|
68 'sdcard': device_data.sdcard, |
|
69 'sdcard_recovery': device_data.sdcard_recovery |
|
70 }) |
|
71 os.chmod(flash_script, stat.S_IRUSR | stat.S_IWUSR | stat.S_IXUSR | |
|
72 stat.S_IRGRP | stat.S_IXGRP | |
|
73 stat.S_IROTH | stat.S_IXOTH) |
|
74 |
|
75 def main(): |
|
76 parser = argparse.ArgumentParser(prog='stage-update.py') |
|
77 parser.add_argument('device', help='device name for staging') |
|
78 parser.add_argument('stage_dir', |
|
79 help='directory to stage update and flash script for smoketests') |
|
80 args = parser.parse_args() |
|
81 |
|
82 try: |
|
83 global b2g |
|
84 b2g = find_b2g() |
|
85 except EnvironmentError, e: |
|
86 parser.exit(1, 'This tool must be run while inside the B2G directory, ' |
|
87 'or B2G_HOME must be set in the environment.') |
|
88 |
|
89 try: |
|
90 stage_update(args.device, args.stage_dir) |
|
91 except SmokeTestError, e: |
|
92 parser.exit(1, str(e)) |
|
93 |
|
94 if __name__ == '__main__': |
|
95 main() |