Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(176)

Side by Side Diff: mojo/tools/upload_binaries.py

Issue 945423002: Change structure of pointers to latest versions of apps in Google Storage. (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Self-review Created 5 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 #!/usr/bin/env python 1 #!/usr/bin/env python
2 # Copyright 2015 The Chromium Authors. All rights reserved. 2 # Copyright 2015 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 glob 7 import glob
8 import os 8 import os
9 import subprocess 9 import subprocess
10 import sys 10 import sys
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
50 gsutil_exe = os.path.join(depot_tools_path, "third_party", "gsutil", "gsutil") 50 gsutil_exe = os.path.join(depot_tools_path, "third_party", "gsutil", "gsutil")
51 51
52 if dry_run: 52 if dry_run:
53 print str([gsutil_exe, "cp", source, dest]) 53 print str([gsutil_exe, "cp", source, dest])
54 else: 54 else:
55 subprocess.check_call([gsutil_exe, "cp", source, dest]) 55 subprocess.check_call([gsutil_exe, "cp", source, dest])
56 56
57 def upload_shell(config, dry_run, verbose): 57 def upload_shell(config, dry_run, verbose):
58 paths = Paths(config) 58 paths = Paths(config)
59 zipfile_name = target(config) 59 zipfile_name = target(config)
60 version = Version().version
61
62 # Upload the binary.
60 # TODO(blundell): Change this to be in the same structure as the LATEST files, 63 # TODO(blundell): Change this to be in the same structure as the LATEST files,
61 # e.g., gs://mojo/shell/linux-x64/<version>/shell.zip. 64 # e.g., gs://mojo/shell/linux-x64/<version>/shell.zip.
62 dest = "gs://mojo/shell/" + Version().version + "/" + zipfile_name + ".zip" 65 dest = "gs://mojo/shell/" + version + "/" + zipfile_name + ".zip"
63 with tempfile.NamedTemporaryFile() as zip_file: 66 with tempfile.NamedTemporaryFile() as zip_file:
64 with zipfile.ZipFile(zip_file, 'w') as z: 67 with zipfile.ZipFile(zip_file, 'w') as z:
65 shell_path = paths.target_mojo_shell_path 68 shell_path = paths.target_mojo_shell_path
66 with open(shell_path) as shell_binary: 69 with open(shell_path) as shell_binary:
67 shell_filename = os.path.basename(shell_path) 70 shell_filename = os.path.basename(shell_path)
68 zipinfo = zipfile.ZipInfo(shell_filename) 71 zipinfo = zipfile.ZipInfo(shell_filename)
69 zipinfo.external_attr = 0777 << 16L 72 zipinfo.external_attr = 0777 << 16L
70 compress_type = zipfile.ZIP_DEFLATED 73 compress_type = zipfile.ZIP_DEFLATED
71 if config.target_os == Config.OS_ANDROID: 74 if config.target_os == Config.OS_ANDROID:
72 # The APK is already compressed. 75 # The APK is already compressed.
73 compress_type = zipfile.ZIP_STORED 76 compress_type = zipfile.ZIP_STORED
74 zipinfo.compress_type = compress_type 77 zipinfo.compress_type = compress_type
75 zipinfo.date_time = time.gmtime(os.path.getmtime(shell_path)) 78 zipinfo.date_time = time.gmtime(os.path.getmtime(shell_path))
76 if verbose: 79 if verbose:
77 print "zipping %s" % shell_path 80 print "zipping %s" % shell_path
78 z.writestr(zipinfo, shell_binary.read()) 81 z.writestr(zipinfo, shell_binary.read())
79 upload(config, zip_file.name, dest, dry_run) 82 upload(config, zip_file.name, dest, dry_run)
80 83
84 # Update the LATEST file to contain the version of the new binary.
85 latest_file = "gs://mojo/shell/%s/LATEST" % target(config)
86 write_file_to_gs(version, latest_file, config, dry_run)
87
81 def upload_app(app_binary_path, config, dry_run): 88 def upload_app(app_binary_path, config, dry_run):
82 app_binary_name = os.path.basename(app_binary_path) 89 app_binary_name = os.path.basename(app_binary_path)
90 app_name = os.path.splitext(app_binary_name)[0]
qsr 2015/02/23 10:52:39 I would write this as app_name, _ = os.path.split
blundell 2015/02/23 11:06:54 Done.
83 version = Version().version 91 version = Version().version
84 dest = ("gs://mojo/services/" + target(config) + "/" + version + "/" + 92 app_location_in_gs = ("mojo/services/" + target(config) + "/" + version +
85 app_binary_name) 93 "/" + app_binary_name)
86 upload(config, app_binary_path, dest, dry_run) 94 gsutil_app_location = "gs://" + app_location_in_gs
95 https_app_location = "https://storage.googleapis.com/" + app_location_in_gs
87 96
88 def update_version(config, subdir, dry_run): 97 # Upload the new binary.
98 upload(config, app_binary_path, gsutil_app_location, dry_run)
99
100 # Update the app's location file to point to the new binary.
101 app_location_file = ("gs://mojo/services/" + target(config) + "/" +
102 app_name + "_location")
103 write_file_to_gs(https_app_location, app_location_file, config, dry_run)
104
105 def write_file_to_gs(file_contents, dest, config, dry_run):
89 with tempfile.NamedTemporaryFile() as temp_version_file: 106 with tempfile.NamedTemporaryFile() as temp_version_file:
90 version = Version().version 107 temp_version_file.write(file_contents)
91 temp_version_file.write(version)
92 temp_version_file.flush() 108 temp_version_file.flush()
93 dest = "gs://mojo/%s/%s/LATEST" % (subdir, target(config))
94 upload(config, temp_version_file.name, dest, dry_run) 109 upload(config, temp_version_file.name, dest, dry_run)
95 110
96 def main(): 111 def main():
97 parser = argparse.ArgumentParser(description="Upload binaries for apps and " 112 parser = argparse.ArgumentParser(description="Upload binaries for apps and "
98 "the Mojo shell to google storage (by default on Linux, but this can be " 113 "the Mojo shell to google storage (by default on Linux, but this can be "
99 "changed via options).") 114 "changed via options).")
100 parser.add_argument("-n", "--dry_run", help="Dry run, do not actually "+ 115 parser.add_argument("-n", "--dry_run", help="Dry run, do not actually "+
101 "upload", action="store_true") 116 "upload", action="store_true")
102 parser.add_argument("-v", "--verbose", help="Verbose mode", 117 parser.add_argument("-v", "--verbose", help="Verbose mode",
103 action="store_true") 118 action="store_true")
104 parser.add_argument("--android", 119 parser.add_argument("--android",
105 action="store_true", 120 action="store_true",
106 help="Upload the shell and apps for Android") 121 help="Upload the shell and apps for Android")
107 args = parser.parse_args() 122 args = parser.parse_args()
108 123
109 target_os = Config.OS_LINUX 124 target_os = Config.OS_LINUX
110 if args.android: 125 if args.android:
111 target_os = Config.OS_ANDROID 126 target_os = Config.OS_ANDROID
112 config = Config(target_os=target_os, is_debug=False) 127 config = Config(target_os=target_os, is_debug=False)
113 upload_shell(config, args.dry_run, args.verbose) 128 upload_shell(config, args.dry_run, args.verbose)
114 update_version(config, "shell", args.dry_run)
115 129
116 apps_to_upload = find_apps_to_upload( 130 apps_to_upload = find_apps_to_upload(
117 gn.BuildDirectoryForConfig(config, Paths(config).src_root)) 131 gn.BuildDirectoryForConfig(config, Paths(config).src_root))
118 for app in apps_to_upload: 132 for app in apps_to_upload:
119 upload_app(app, config, args.dry_run) 133 upload_app(app, config, args.dry_run)
120 update_version(config, "services", args.dry_run)
121 134
122 return 0 135 return 0
123 136
124 if __name__ == "__main__": 137 if __name__ == "__main__":
125 sys.exit(main()) 138 sys.exit(main())
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698