OLD | NEW |
---|---|
(Empty) | |
1 #!/usr/bin/env python | |
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 | |
4 # found in the LICENSE file. | |
5 | |
6 import argparse | |
7 import os | |
8 import subprocess | |
9 import sys | |
10 import tempfile | |
11 import time | |
12 import zipfile | |
13 | |
14 | |
15 root_path = os.path.realpath( | |
eseidel
2014/11/05 00:04:26
ALL_CAPS for contstants last I knew:
http://legacy
| |
16 os.path.join( | |
17 os.path.dirname( | |
18 os.path.realpath(__file__)), | |
19 os.pardir, | |
20 os.pardir, | |
21 os.pardir)) | |
22 version = subprocess.check_output(["git", "rev-parse", "HEAD"], cwd=root_path) | |
eseidel
2014/11/05 00:04:26
We will eventually write a mojopy library to do th
| |
23 version = version.strip() | |
24 | |
25 if not sys.platform.startswith("linux"): | |
26 print "Only support linux for now" | |
27 sys.exit(1) | |
28 | |
29 platform = "linux-x64" # TODO: Parameterize | |
30 binary_dest = "gs://mojo/network/" + version + "/" + platform + ".zip" | |
31 | |
32 sys.path.insert(0, os.path.join(root_path, "tools")) | |
eseidel
2014/11/05 00:04:27
Are you sure you want to do this?
| |
33 import find_depot_tools # pylint: disable=W0611 | |
34 | |
35 depot_tools_path = find_depot_tools.add_depot_tools_to_path() | |
36 gsutil_exe = os.path.join(depot_tools_path, "third_party", "gsutil", "gsutil") | |
eseidel
2014/11/05 00:04:27
There is no gsutil helper library for this kind of
| |
37 | |
38 | |
39 def gsutil_cp(source, dest, dry_run): | |
40 if dry_run: | |
41 print "gsutil cp %s %s" % (source, dest) | |
42 else: | |
43 subprocess.check_call([gsutil_exe, "cp", source, dest]) | |
44 | |
45 | |
46 def upload_binary(binary_path, dry_run): | |
47 absolute_binary_path = os.path.join(root_path, binary_path) | |
48 with tempfile.NamedTemporaryFile() as binary_zip_file: | |
49 with zipfile.ZipFile(binary_zip_file, 'w') as z: | |
50 with open(absolute_binary_path) as service_binary: | |
51 zipinfo = zipfile.ZipInfo("libnetwork_service.so") | |
52 zipinfo.external_attr = 0o777 << 16 | |
53 zipinfo.compress_type = zipfile.ZIP_DEFLATED | |
54 zipinfo.date_time = time.gmtime(os.path.getmtime(absolute_binary_path)) | |
55 z.writestr(zipinfo, service_binary.read()) | |
56 gsutil_cp(binary_zip_file.name, binary_dest, dry_run) | |
57 | |
58 | |
59 def main(): | |
60 parser = argparse.ArgumentParser( | |
61 description="Upload network service binary to Google storage") | |
62 parser.add_argument("-n", "--dry-run", action="store_true", help="Dry run") | |
63 parser.add_argument( | |
64 "binary_path", | |
65 help="Path to network service binary relative to the repo root, e.g. " + | |
66 "out/Release/libnetwork_service.so") | |
67 args = parser.parse_args() | |
68 upload_binary(args.binary_path, args.dry_run) | |
69 print "Uploaded artifacts for %s %s" % (version, "linux-x64") | |
70 return 0 | |
71 | |
72 if __name__ == '__main__': | |
73 sys.exit(main()) | |
OLD | NEW |