Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
| 2 # Copyright 2014 The Chromium Authors. All rights reserved. | 2 # Copyright 2014 The Chromium Authors. All rights reserved. |
| 3 # Use of this source code is governed by a BSD-style license that can be | 3 # Use of this source code is governed by a BSD-style license that can be |
| 4 # found in the LICENSE file. | 4 # found in the LICENSE file. |
| 5 | 5 |
| 6 import argparse | 6 import argparse |
| 7 import os | 7 import os |
| 8 import subprocess | 8 import subprocess |
| 9 import sys | 9 import sys |
| 10 import tempfile | 10 import tempfile |
| 11 import time | 11 import time |
| 12 import zipfile | 12 import zipfile |
| 13 | 13 |
| 14 from mopy.config import Config | 14 from mopy.config import Config |
| 15 from mopy.paths import Paths | 15 from mopy.paths import Paths |
| 16 from mopy.version import Version | 16 from mopy.version import Version |
| 17 | 17 |
| 18 paths = Paths(Config(target_os=Config.OS_LINUX, is_debug=False)) | 18 def upload(dry_run, verbose, android): |
|
qsr
2015/01/26 15:57:47
Should you take a config instead of just android?
blundell
2015/01/26 16:22:43
Done.
| |
| 19 target_os = Config.OS_LINUX | |
| 20 if android: | |
| 21 target_os = Config.OS_ANDROID | |
| 22 paths = Paths(Config(target_os=target_os, is_debug=False)) | |
| 19 | 23 |
| 20 sys.path.insert(0, os.path.join(paths.src_root, "tools")) | 24 sys.path.insert(0, os.path.join(paths.src_root, "tools")) |
| 21 # pylint: disable=F0401 | 25 # pylint: disable=F0401 |
| 22 import find_depot_tools | 26 import find_depot_tools |
| 23 | 27 |
| 24 depot_tools_path = find_depot_tools.add_depot_tools_to_path() | 28 depot_tools_path = find_depot_tools.add_depot_tools_to_path() |
| 25 gsutil_exe = os.path.join(depot_tools_path, "third_party", "gsutil", "gsutil") | 29 gsutil_exe = os.path.join(depot_tools_path, "third_party", "gsutil", "gsutil") |
| 26 | 30 |
| 27 def upload(dry_run, verbose): | 31 zipfile_name = "linux-x64" |
| 28 dest = "gs://mojo/shell/" + Version().version + "/linux-x64.zip" | 32 if android: |
| 33 zipfile_name = "android-arm32" | |
|
qsr
2015/01/26 15:57:47
The usual name of android is just arm (see our gn
blundell
2015/01/26 16:22:43
Done.
| |
| 34 dest = "gs://mojo/shell/" + Version().version + "/" + zipfile_name + ".zip" | |
| 29 | 35 |
| 30 with tempfile.NamedTemporaryFile() as zip_file: | 36 with tempfile.NamedTemporaryFile() as zip_file: |
| 31 with zipfile.ZipFile(zip_file, 'w') as z: | 37 with zipfile.ZipFile(zip_file, 'w') as z: |
| 32 with open(paths.mojo_shell_path) as shell_binary: | 38 shell_path = paths.mojo_shell_path |
| 33 zipinfo = zipfile.ZipInfo("mojo_shell") | 39 if android: |
| 40 shell_path = paths.target_mojo_shell_path | |
|
qsr
2015/01/26 15:57:47
Can you try to aggregate those by always setting s
blundell
2015/01/26 16:22:43
Done.
| |
| 41 with open(shell_path) as shell_binary: | |
| 42 shell_filename = os.path.basename(shell_path) | |
| 43 zipinfo = zipfile.ZipInfo(shell_filename) | |
| 34 zipinfo.external_attr = 0777 << 16L | 44 zipinfo.external_attr = 0777 << 16L |
| 35 zipinfo.compress_type = zipfile.ZIP_DEFLATED | 45 zipinfo.compress_type = zipfile.ZIP_DEFLATED |
| 36 zipinfo.date_time = time.gmtime(os.path.getmtime(paths.mojo_shell_path)) | 46 zipinfo.date_time = time.gmtime(os.path.getmtime(shell_path)) |
| 37 if verbose: | 47 if verbose: |
| 38 print "zipping %s" % paths.mojo_shell_path | 48 print "zipping %s" % shell_path |
| 39 z.writestr(zipinfo, shell_binary.read()) | 49 z.writestr(zipinfo, shell_binary.read()) |
| 40 if dry_run: | 50 if dry_run: |
| 41 print str([gsutil_exe, "cp", zip_file.name, dest]) | 51 print str([gsutil_exe, "cp", zip_file.name, dest]) |
| 42 else: | 52 else: |
| 43 subprocess.check_call([gsutil_exe, "cp", zip_file.name, dest]) | 53 subprocess.check_call([gsutil_exe, "cp", zip_file.name, dest]) |
| 44 | 54 |
| 45 def main(): | 55 def main(): |
| 46 parser = argparse.ArgumentParser(description="Upload mojo_shell binary to "+ | 56 parser = argparse.ArgumentParser(description="Upload mojo_shell binary to "+ |
| 47 "google storage") | 57 "google storage") |
| 48 parser.add_argument("-n", "--dry_run", help="Dry run, do not actually "+ | 58 parser.add_argument("-n", "--dry_run", help="Dry run, do not actually "+ |
| 49 "upload", action="store_true") | 59 "upload", action="store_true") |
| 50 parser.add_argument("-v", "--verbose", help="Verbose mode", | 60 parser.add_argument("-v", "--verbose", help="Verbose mode", |
| 51 action="store_true") | 61 action="store_true") |
| 62 parser.add_argument("--android", help="Upload the shell for Android", | |
| 63 action="store_true") | |
|
qsr
2015/01/26 15:57:47
Should you instead pass a build_dir? Then using mo
blundell
2015/01/26 16:22:43
Done.
| |
| 52 args = parser.parse_args() | 64 args = parser.parse_args() |
| 53 upload(args.dry_run, args.verbose) | 65 upload(args.dry_run, args.verbose, args.android) |
| 54 return 0 | 66 return 0 |
| 55 | 67 |
| 56 if __name__ == "__main__": | 68 if __name__ == "__main__": |
| 57 sys.exit(main()) | 69 sys.exit(main()) |
| OLD | NEW |