OLD | NEW |
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 ''' | 6 ''' |
7 Script to help uploading and downloading the Google Play services client | 7 Script to help uploading and downloading the Google Play services client |
8 library to and from a Google Cloud storage. | 8 library to and from a Google Cloud storage. |
9 ''' | 9 ''' |
10 | 10 |
(...skipping 24 matching lines...) Expand all Loading... |
35 # It should be managed by git to provided information about new versions. | 35 # It should be managed by git to provided information about new versions. |
36 SHA1_DIRECTORY = os.path.join(constants.DIR_SOURCE_ROOT, 'build', 'android', | 36 SHA1_DIRECTORY = os.path.join(constants.DIR_SOURCE_ROOT, 'build', 'android', |
37 'play_services') | 37 'play_services') |
38 | 38 |
39 # Default bucket used for storing the files. | 39 # Default bucket used for storing the files. |
40 GMS_CLOUD_STORAGE = 'chrome-sdk-extras' | 40 GMS_CLOUD_STORAGE = 'chrome-sdk-extras' |
41 | 41 |
42 # Path to the default configuration file. It exposes the currently installed | 42 # Path to the default configuration file. It exposes the currently installed |
43 # version of the library in a human readable way. | 43 # version of the library in a human readable way. |
44 CONFIG_DEFAULT_PATH = os.path.join(constants.DIR_SOURCE_ROOT, 'build', | 44 CONFIG_DEFAULT_PATH = os.path.join(constants.DIR_SOURCE_ROOT, 'build', |
45 'android', 'play_services', 'config.yaml') | 45 'android', 'play_services', 'config.json') |
46 | 46 |
47 LICENSE_FILE_NAME = 'LICENSE' | 47 LICENSE_FILE_NAME = 'LICENSE' |
48 LIBRARY_FILE_NAME = 'google_play_services_library.zip' | 48 LIBRARY_FILE_NAME = 'google_play_services_library.zip' |
49 GMS_PACKAGE_ID = 'extra-google-google_play_services' # used by sdk manager | 49 GMS_PACKAGE_ID = 'extra-google-google_play_services' # used by sdk manager |
50 | 50 |
51 LICENSE_PATTERN = re.compile(r'^Pkg\.License=(?P<text>.*)$', re.MULTILINE) | 51 LICENSE_PATTERN = re.compile(r'^Pkg\.License=(?P<text>.*)$', re.MULTILINE) |
52 | 52 |
53 | 53 |
54 def Main(): | 54 def Main(): |
55 parser = argparse.ArgumentParser( | 55 parser = argparse.ArgumentParser( |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
116 ''' | 116 ''' |
117 Defines the common arguments on subparser rather than the main one. This | 117 Defines the common arguments on subparser rather than the main one. This |
118 allows to put arguments after the command: `foo.py upload --debug --force` | 118 allows to put arguments after the command: `foo.py upload --debug --force` |
119 instead of `foo.py --debug upload --force` | 119 instead of `foo.py --debug upload --force` |
120 ''' | 120 ''' |
121 | 121 |
122 parser.add_argument('--bucket', | 122 parser.add_argument('--bucket', |
123 help='name of the bucket where the files are stored', | 123 help='name of the bucket where the files are stored', |
124 default=GMS_CLOUD_STORAGE) | 124 default=GMS_CLOUD_STORAGE) |
125 parser.add_argument('--config', | 125 parser.add_argument('--config', |
126 help='YAML Configuration file', | 126 help='JSON Configuration file', |
127 default=CONFIG_DEFAULT_PATH) | 127 default=CONFIG_DEFAULT_PATH) |
128 parser.add_argument('--dry-run', | 128 parser.add_argument('--dry-run', |
129 action='store_true', | 129 action='store_true', |
130 help=('run the script in dry run mode. Files will be ' | 130 help=('run the script in dry run mode. Files will be ' |
131 'copied to a local directory instead of the cloud ' | 131 'copied to a local directory instead of the cloud ' |
132 'storage. The bucket name will be as path to that ' | 132 'storage. The bucket name will be as path to that ' |
133 'directory relative to the repository root.')) | 133 'directory relative to the repository root.')) |
134 parser.add_argument('-v', '--verbose', | 134 parser.add_argument('-v', '--verbose', |
135 action='store_true', | 135 action='store_true', |
136 help='print debug information') | 136 help='print debug information') |
(...skipping 13 matching lines...) Expand all Loading... |
150 | 150 |
151 new_lib_zip_sha1 = os.path.join(SHA1_DIRECTORY, LIBRARY_FILE_NAME + '.sha1') | 151 new_lib_zip_sha1 = os.path.join(SHA1_DIRECTORY, LIBRARY_FILE_NAME + '.sha1') |
152 old_lib_zip_sha1 = os.path.join(paths.package, LIBRARY_FILE_NAME + '.sha1') | 152 old_lib_zip_sha1 = os.path.join(paths.package, LIBRARY_FILE_NAME + '.sha1') |
153 | 153 |
154 logging.debug('Comparing library hashes: %s and %s', new_lib_zip_sha1, | 154 logging.debug('Comparing library hashes: %s and %s', new_lib_zip_sha1, |
155 old_lib_zip_sha1) | 155 old_lib_zip_sha1) |
156 if utils.FileEquals(new_lib_zip_sha1, old_lib_zip_sha1) and not args.force: | 156 if utils.FileEquals(new_lib_zip_sha1, old_lib_zip_sha1) and not args.force: |
157 logging.debug('The Google Play services library is up to date.') | 157 logging.debug('The Google Play services library is up to date.') |
158 return 0 | 158 return 0 |
159 | 159 |
| 160 config = utils.ConfigParser(args.config) |
160 bucket_path = _VerifyBucketPathFormat(args.bucket, | 161 bucket_path = _VerifyBucketPathFormat(args.bucket, |
161 utils.GetVersionNumber(args.config), | 162 config.version_number, |
162 args.dry_run) | 163 args.dry_run) |
163 | 164 |
164 tmp_root = tempfile.mkdtemp() | 165 tmp_root = tempfile.mkdtemp() |
165 try: | 166 try: |
166 if not os.environ.get('CHROME_HEADLESS'): | 167 if not os.environ.get('CHROME_HEADLESS'): |
167 if not os.path.isdir(paths.package): | 168 if not os.path.isdir(paths.package): |
168 os.makedirs(paths.package) | 169 os.makedirs(paths.package) |
169 | 170 |
170 # download license file from bucket/{version_number}/license.sha1 | 171 # download license file from bucket/{version_number}/license.sha1 |
171 new_license = os.path.join(tmp_root, LICENSE_FILE_NAME) | 172 new_license = os.path.join(tmp_root, LICENSE_FILE_NAME) |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
238 # and setup related reasons. Also, exceptions here are not caught, so we | 239 # and setup related reasons. Also, exceptions here are not caught, so we |
239 # disable breakpad to avoid spamming the logs. | 240 # disable breakpad to avoid spamming the logs. |
240 breakpad.IS_ENABLED = False | 241 breakpad.IS_ENABLED = False |
241 | 242 |
242 paths = _InitPaths(args.sdk_root) | 243 paths = _InitPaths(args.sdk_root) |
243 | 244 |
244 if not args.skip_git and utils.IsRepoDirty(constants.DIR_SOURCE_ROOT): | 245 if not args.skip_git and utils.IsRepoDirty(constants.DIR_SOURCE_ROOT): |
245 logging.error('The repo is dirty. Please commit or stash your changes.') | 246 logging.error('The repo is dirty. Please commit or stash your changes.') |
246 return -1 | 247 return -1 |
247 | 248 |
248 old_version_number = utils.GetVersionNumber(args.config) | 249 config = utils.ConfigParser(args.config) |
249 | 250 |
250 version_xml = os.path.join(paths.lib, 'res', 'values', 'version.xml') | 251 version_xml = os.path.join(paths.lib, 'res', 'values', 'version.xml') |
251 new_version_number = utils.GetVersionNumberFromLibraryResources(version_xml) | 252 new_version_number = utils.GetVersionNumberFromLibraryResources(version_xml) |
252 logging.debug('comparing versions: new=%d, old=%s', | 253 logging.debug('comparing versions: new=%d, old=%s', |
253 new_version_number, old_version_number) | 254 new_version_number, config.version_number) |
254 if new_version_number <= old_version_number and not args.force: | 255 if new_version_number <= config.version_number and not args.force: |
255 logging.info('The checked in version of the library is already the latest ' | 256 logging.info('The checked in version of the library is already the latest ' |
256 'one. No update needed. Please rerun with --force to skip ' | 257 'one. No update needed. Please rerun with --force to skip ' |
257 'this check.') | 258 'this check.') |
258 return 0 | 259 return 0 |
259 | 260 |
260 tmp_root = tempfile.mkdtemp() | 261 tmp_root = tempfile.mkdtemp() |
261 try: | 262 try: |
262 new_lib_zip = os.path.join(tmp_root, LIBRARY_FILE_NAME) | 263 new_lib_zip = os.path.join(tmp_root, LIBRARY_FILE_NAME) |
263 new_license = os.path.join(tmp_root, LICENSE_FILE_NAME) | 264 new_license = os.path.join(tmp_root, LICENSE_FILE_NAME) |
264 | 265 |
265 # need to strip '.zip' from the file name here | 266 # need to strip '.zip' from the file name here |
266 shutil.make_archive(new_lib_zip[:-4], 'zip', paths.lib) | 267 shutil.make_archive(new_lib_zip[:-4], 'zip', paths.lib) |
267 _ExtractLicenseFile(new_license, paths.package) | 268 _ExtractLicenseFile(new_license, paths.package) |
268 | 269 |
269 bucket_path = _VerifyBucketPathFormat(args.bucket, new_version_number, | 270 bucket_path = _VerifyBucketPathFormat(args.bucket, new_version_number, |
270 args.dry_run) | 271 args.dry_run) |
271 files_to_upload = [new_lib_zip, new_license] | 272 files_to_upload = [new_lib_zip, new_license] |
272 logging.debug('Uploading %s to %s', files_to_upload, bucket_path) | 273 logging.debug('Uploading %s to %s', files_to_upload, bucket_path) |
273 _UploadToBucket(bucket_path, files_to_upload, args.dry_run) | 274 _UploadToBucket(bucket_path, files_to_upload, args.dry_run) |
274 | 275 |
275 new_lib_zip_sha1 = os.path.join(SHA1_DIRECTORY, | 276 new_lib_zip_sha1 = os.path.join(SHA1_DIRECTORY, |
276 LIBRARY_FILE_NAME + '.sha1') | 277 LIBRARY_FILE_NAME + '.sha1') |
277 new_license_sha1 = os.path.join(SHA1_DIRECTORY, | 278 new_license_sha1 = os.path.join(SHA1_DIRECTORY, |
278 LICENSE_FILE_NAME + '.sha1') | 279 LICENSE_FILE_NAME + '.sha1') |
279 shutil.copy(new_lib_zip + '.sha1', new_lib_zip_sha1) | 280 shutil.copy(new_lib_zip + '.sha1', new_lib_zip_sha1) |
280 shutil.copy(new_license + '.sha1', new_license_sha1) | 281 shutil.copy(new_license + '.sha1', new_license_sha1) |
281 finally: | 282 finally: |
282 shutil.rmtree(tmp_root) | 283 shutil.rmtree(tmp_root) |
283 | 284 |
284 utils.UpdateVersionNumber(args.config, new_version_number) | 285 config.UpdateVersionNumber(new_version_number) |
285 | 286 |
286 if not args.skip_git: | 287 if not args.skip_git: |
287 commit_message = ('Update the Google Play services dependency to %s\n' | 288 commit_message = ('Update the Google Play services dependency to %s\n' |
288 '\n') % new_version_number | 289 '\n') % new_version_number |
289 utils.MakeLocalCommit(constants.DIR_SOURCE_ROOT, | 290 utils.MakeLocalCommit(constants.DIR_SOURCE_ROOT, |
290 [new_lib_zip_sha1, new_license_sha1, args.config], | 291 [new_lib_zip_sha1, new_license_sha1, config.path], |
291 commit_message) | 292 commit_message) |
292 | 293 |
293 return 0 | 294 return 0 |
294 | 295 |
295 | 296 |
296 def _InitPaths(sdk_root): | 297 def _InitPaths(sdk_root): |
297 ''' | 298 ''' |
298 Initializes the different paths to be used in the update process. | 299 Initializes the different paths to be used in the update process. |
299 ''' | 300 ''' |
300 | 301 |
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
447 logging.debug('Calling command "%s"', str(args)) | 448 logging.debug('Calling command "%s"', str(args)) |
448 return cmd_helper.GetCmdStatusOutputAndError(args) | 449 return cmd_helper.GetCmdStatusOutputAndError(args) |
449 | 450 |
450 def check_call(self, *args): | 451 def check_call(self, *args): |
451 logging.debug('Calling command "%s"', str(args)) | 452 logging.debug('Calling command "%s"', str(args)) |
452 return cmd_helper.GetCmdStatusOutputAndError(args) | 453 return cmd_helper.GetCmdStatusOutputAndError(args) |
453 | 454 |
454 | 455 |
455 if __name__ == '__main__': | 456 if __name__ == '__main__': |
456 sys.exit(Main()) | 457 sys.exit(Main()) |
OLD | NEW |