Upstream version 11.40.271.0
[platform/framework/web/crosswalk.git] / src / mojo / services / network / upload_network_service.py
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 imp
8 import os
9 import subprocess
10 import sys
11 import tempfile
12 import time
13 import zipfile
14
15 root_path = os.path.realpath(
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)
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 find_depot_tools_path = os.path.join(root_path, "tools", "find_depot_tools.py")
33 find_depot_tools = imp.load_source("find_depot_tools", find_depot_tools_path)
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")
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())