| 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 library to | 7 Script to help uploading and downloading the Google Play services library to | 
| 8 and from a Google Cloud storage. | 8 and from a Google Cloud storage. | 
| 9 ''' | 9 ''' | 
| 10 | 10 | 
| (...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 144   if that has not been done before. | 144   if that has not been done before. | 
| 145   ''' | 145   ''' | 
| 146 | 146 | 
| 147   if not os.path.isdir(args.sdk_root): | 147   if not os.path.isdir(args.sdk_root): | 
| 148     logging.debug('Did not find the Android SDK root directory at "%s".', | 148     logging.debug('Did not find the Android SDK root directory at "%s".', | 
| 149                   args.sdk_root) | 149                   args.sdk_root) | 
| 150     if not args.force: | 150     if not args.force: | 
| 151       logging.info('Skipping, not on an android checkout.') | 151       logging.info('Skipping, not on an android checkout.') | 
| 152       return 0 | 152       return 0 | 
| 153 | 153 | 
| 154   paths = PlayServicesPaths(args.sdk_root) | 154   config = utils.ConfigParser(args.config) | 
|  | 155   paths = PlayServicesPaths(args.sdk_root, config.version_xml_path) | 
| 155 | 156 | 
| 156   if os.path.isdir(paths.package) and not os.access(paths.package, os.W_OK): | 157   if os.path.isdir(paths.package) and not os.access(paths.package, os.W_OK): | 
| 157     logging.error('Failed updating the Google Play Services library. ' | 158     logging.error('Failed updating the Google Play Services library. ' | 
| 158                   'The location is not writable. Please remove the ' | 159                   'The location is not writable. Please remove the ' | 
| 159                   'directory (%s) and try again.', paths.package) | 160                   'directory (%s) and try again.', paths.package) | 
| 160     return -2 | 161     return -2 | 
| 161 | 162 | 
| 162   new_lib_zip_sha1 = os.path.join(SHA1_DIRECTORY, ZIP_FILE_NAME + '.sha1') | 163   new_lib_zip_sha1 = os.path.join(SHA1_DIRECTORY, ZIP_FILE_NAME + '.sha1') | 
| 163 | 164 | 
| 164   logging.debug('Comparing zip hashes: %s and %s', new_lib_zip_sha1, | 165   logging.debug('Comparing zip hashes: %s and %s', new_lib_zip_sha1, | 
| 165                 paths.lib_zip_sha1) | 166                 paths.lib_zip_sha1) | 
| 166   if utils.FileEquals(new_lib_zip_sha1, paths.lib_zip_sha1) and not args.force: | 167   if utils.FileEquals(new_lib_zip_sha1, paths.lib_zip_sha1) and not args.force: | 
| 167     logging.info('Skipping, the Google Play services library is up to date.') | 168     logging.info('Skipping, the Google Play services library is up to date.') | 
| 168     return 0 | 169     return 0 | 
| 169 | 170 | 
| 170   config = utils.ConfigParser(args.config) |  | 
| 171   bucket_path = _VerifyBucketPathFormat(args.bucket, | 171   bucket_path = _VerifyBucketPathFormat(args.bucket, | 
| 172                                         config.version_number, | 172                                         config.version_number, | 
| 173                                         args.dry_run) | 173                                         args.dry_run) | 
| 174 | 174 | 
| 175   tmp_root = tempfile.mkdtemp() | 175   tmp_root = tempfile.mkdtemp() | 
| 176   try: | 176   try: | 
| 177     # setup the destination directory | 177     # setup the destination directory | 
| 178     if not os.path.isdir(paths.package): | 178     if not os.path.isdir(paths.package): | 
| 179       os.makedirs(paths.package) | 179       os.makedirs(paths.package) | 
| 180 | 180 | 
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 253   storage bucket. | 253   storage bucket. | 
| 254 | 254 | 
| 255   By default, a local commit will be made at the end of the operation. | 255   By default, a local commit will be made at the end of the operation. | 
| 256   ''' | 256   ''' | 
| 257 | 257 | 
| 258   # This should function should not run on bots and could fail for many user | 258   # This should function should not run on bots and could fail for many user | 
| 259   # and setup related reasons. Also, exceptions here are not caught, so we | 259   # and setup related reasons. Also, exceptions here are not caught, so we | 
| 260   # disable breakpad to avoid spamming the logs. | 260   # disable breakpad to avoid spamming the logs. | 
| 261   breakpad.IS_ENABLED = False | 261   breakpad.IS_ENABLED = False | 
| 262 | 262 | 
| 263   paths = PlayServicesPaths(args.sdk_root) | 263   config = utils.ConfigParser(args.config) | 
|  | 264   paths = PlayServicesPaths(args.sdk_root, config.version_xml_path) | 
| 264 | 265 | 
| 265   if not args.skip_git and utils.IsRepoDirty(constants.DIR_SOURCE_ROOT): | 266   if not args.skip_git and utils.IsRepoDirty(constants.DIR_SOURCE_ROOT): | 
| 266     logging.error('The repo is dirty. Please commit or stash your changes.') | 267     logging.error('The repo is dirty. Please commit or stash your changes.') | 
| 267     return -1 | 268     return -1 | 
| 268 | 269 | 
| 269   config = utils.ConfigParser(args.config) |  | 
| 270 |  | 
| 271   new_version_number = utils.GetVersionNumberFromLibraryResources( | 270   new_version_number = utils.GetVersionNumberFromLibraryResources( | 
| 272       paths.version_xml) | 271       paths.version_xml) | 
| 273   logging.debug('comparing versions: new=%d, old=%s', | 272   logging.debug('comparing versions: new=%d, old=%s', | 
| 274                 new_version_number, config.version_number) | 273                 new_version_number, config.version_number) | 
| 275   if new_version_number <= config.version_number and not args.force: | 274   if new_version_number <= config.version_number and not args.force: | 
| 276     logging.info('The checked in version of the library is already the latest ' | 275     logging.info('The checked in version of the library is already the latest ' | 
| 277                  'one. No update is needed. Please rerun with --force to skip ' | 276                  'one. No update is needed. Please rerun with --force to skip ' | 
| 278                  'this check.') | 277                  'this check.') | 
| 279     return 0 | 278     return 0 | 
| 280 | 279 | 
| (...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 466       check if an update is necessary. | 465       check if an update is necessary. | 
| 467    6. lib: Contains the library itself: jar and resources. This is what is | 466    6. lib: Contains the library itself: jar and resources. This is what is | 
| 468       downloaded from the cloud storage. | 467       downloaded from the cloud storage. | 
| 469    7. version_xml: File that contains the exact Google Play services library | 468    7. version_xml: File that contains the exact Google Play services library | 
| 470       version, the one that we track. The version looks like 811500, is used in | 469       version, the one that we track. The version looks like 811500, is used in | 
| 471       the code and the on-device APK, as opposed to the SDK package version | 470       the code and the on-device APK, as opposed to the SDK package version | 
| 472       which looks like 27.0.0 and is used only by the Android SDK manager. | 471       which looks like 27.0.0 and is used only by the Android SDK manager. | 
| 473 | 472 | 
| 474   ''' | 473   ''' | 
| 475 | 474 | 
| 476   def __init__(self, sdk_root): | 475   def __init__(self, sdk_root, version_xml_path): | 
| 477     relative_package = os.path.join('extras', 'google', 'google_play_services') | 476     relative_package = os.path.join('extras', 'google', 'google_play_services') | 
| 478     relative_lib = os.path.join(relative_package, 'libproject', | 477     relative_lib = os.path.join(relative_package, 'libproject', | 
| 479                                 'google-play-services_lib') | 478                                 'google-play-services_lib') | 
| 480     self.sdk_root = sdk_root | 479     self.sdk_root = sdk_root | 
| 481 | 480 | 
| 482     self.package = os.path.join(sdk_root, relative_package) | 481     self.package = os.path.join(sdk_root, relative_package) | 
| 483     self.lib_zip_sha1 = os.path.join(self.package, ZIP_FILE_NAME + '.sha1') | 482     self.lib_zip_sha1 = os.path.join(self.package, ZIP_FILE_NAME + '.sha1') | 
| 484     self.license = os.path.join(self.package, LICENSE_FILE_NAME) | 483     self.license = os.path.join(self.package, LICENSE_FILE_NAME) | 
| 485     self.source_prop = os.path.join(self.package, 'source.properties') | 484     self.source_prop = os.path.join(self.package, 'source.properties') | 
| 486 | 485 | 
| 487     self.lib = os.path.join(sdk_root, relative_lib) | 486     self.lib = os.path.join(sdk_root, relative_lib) | 
| 488     self.version_xml = os.path.join(self.lib, 'res', 'values', 'version.xml') | 487     self.version_xml = os.path.join(self.lib, version_xml_path) | 
| 489 | 488 | 
| 490 | 489 | 
| 491 class DummyGsutil(download_from_google_storage.Gsutil): | 490 class DummyGsutil(download_from_google_storage.Gsutil): | 
| 492   ''' | 491   ''' | 
| 493   Class that replaces Gsutil to use a local directory instead of an online | 492   Class that replaces Gsutil to use a local directory instead of an online | 
| 494   bucket. It relies on the fact that Gsutil commands are very similar to shell | 493   bucket. It relies on the fact that Gsutil commands are very similar to shell | 
| 495   ones, so for the ones used here (ls, cp), it works to just use them with a | 494   ones, so for the ones used here (ls, cp), it works to just use them with a | 
| 496   local directory. | 495   local directory. | 
| 497   ''' | 496   ''' | 
| 498 | 497 | 
| 499   def __init__(self): | 498   def __init__(self): | 
| 500     super(DummyGsutil, self).__init__( | 499     super(DummyGsutil, self).__init__( | 
| 501         download_from_google_storage.GSUTIL_DEFAULT_PATH) | 500         download_from_google_storage.GSUTIL_DEFAULT_PATH) | 
| 502 | 501 | 
| 503   def call(self, *args): | 502   def call(self, *args): | 
| 504     logging.debug('Calling command "%s"', str(args)) | 503     logging.debug('Calling command "%s"', str(args)) | 
| 505     return cmd_helper.GetCmdStatusOutputAndError(args) | 504     return cmd_helper.GetCmdStatusOutputAndError(args) | 
| 506 | 505 | 
| 507   def check_call(self, *args): | 506   def check_call(self, *args): | 
| 508     logging.debug('Calling command "%s"', str(args)) | 507     logging.debug('Calling command "%s"', str(args)) | 
| 509     return cmd_helper.GetCmdStatusOutputAndError(args) | 508     return cmd_helper.GetCmdStatusOutputAndError(args) | 
| 510 | 509 | 
| 511 | 510 | 
| 512 if __name__ == '__main__': | 511 if __name__ == '__main__': | 
| 513   sys.exit(main(sys.argv[1:])) | 512   sys.exit(main(sys.argv[1:])) | 
| OLD | NEW | 
|---|