testing/marionette/update-smoketests/stage-update.py

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rwxr-xr-x

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

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

mercurial