| #!/usr/bin/env python3 |
| # -*- coding: utf-8 -*- |
| # Copyright 2018 The Chromium OS Authors. All rights reserved. |
| # Use of this source code is governed by a BSD-style license that can be |
| # found in the LICENSE file. |
| |
| """Create a zip file for uploading to the CWS.""" |
| |
| from __future__ import print_function |
| |
| import argparse |
| import json |
| import os |
| import shutil |
| import subprocess |
| import sys |
| |
| import common |
| |
| |
| def get_parser(): |
| """Get a CLI parser.""" |
| parser = argparse.ArgumentParser(description=__doc__) |
| return parser |
| |
| |
| def main(argv): |
| """The main func!""" |
| parser = get_parser() |
| _ = parser.parse_args(argv) |
| |
| os.chdir(common.TOPDIR) |
| |
| manifest = common.read_crx_manifest() |
| pn = 'adb' |
| pv = manifest['version'] |
| p = '%s-%s' % (pn, pv) |
| |
| print('Creating', p) |
| |
| distdir = os.path.join(common.DISTDIR, 'crx') |
| tmpdir = os.path.join(common.BUILDDIR, p) |
| common.rmtree(tmpdir) |
| common.makedirs(tmpdir) |
| common.makedirs(distdir) |
| |
| # Create all the nacl dirs in case they don't already. |
| # Even if they're empty, that's OK. |
| for arch in manifest['platforms']: |
| common.makedirs(arch['sub_package_path']) |
| |
| for subfile in ('manifest.json',): |
| shutil.copyfile(subfile, os.path.join(tmpdir, subfile)) |
| for subdir in ('html', 'images', 'js', '_platform_specific'): |
| shutil.copytree(subdir, os.path.join(tmpdir, subdir)) |
| |
| # Sanity check the registerd versions in case some files were updated |
| # but others were forgotten. |
| abort = False |
| # pylint: disable=not-an-iterable |
| for root, _, files in os.walk(os.path.join(tmpdir, '_platform_specific')): |
| if 'container.json' in files: |
| path = os.path.join(root, 'container.json') |
| with open(path) as f: |
| data = json.load(f) |
| if data['version'] != pv: |
| abort = True |
| print('ERROR: version is out of sync') |
| print(os.path.relpath(path, tmpdir), 'is version', |
| data['version']) |
| print('But manifest.json is', pv) |
| |
| if 'imageloader.json' in files: |
| path = os.path.join(root, 'imageloader.json') |
| with open(path) as f: |
| data = json.load(f) |
| if data['version'] != pv: |
| abort = True |
| print('ERROR: version is out of sync') |
| print(os.path.relpath(path, tmpdir), 'is version', |
| data['version']) |
| print('But manifest.json is', pv) |
| |
| if abort: |
| return 1 |
| |
| archive = '%s.zip' % (p,) |
| subprocess.check_call(['zip', '-r', archive, p], cwd=common.BUILDDIR) |
| dest = os.path.join(distdir, archive) |
| common.remove(dest) |
| os.rename(os.path.join(common.BUILDDIR, archive), dest) |
| |
| print('Finished', dest, os.path.getsize(dest), 'bytes') |
| |
| |
| if __name__ == '__main__': |
| sys.exit(main(sys.argv[1:])) |