| 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 |
| 11 import argparse | 11 import argparse |
| 12 import logging | 12 import logging |
| 13 import os | 13 import os |
| 14 import re | 14 import re |
| 15 import shutil | 15 import shutil |
| 16 import sys | 16 import sys |
| 17 import tempfile | 17 import tempfile |
| 18 import zipfile | 18 import zipfile |
| 19 | 19 |
| 20 sys.path.append(os.path.join(os.path.dirname(__file__), os.pardir)) | 20 sys.path.append(os.path.join(os.path.dirname(__file__), os.pardir)) |
| 21 import devil_chromium |
| 21 from devil.utils import cmd_helper | 22 from devil.utils import cmd_helper |
| 22 from play_services import utils | 23 from play_services import utils |
| 23 from pylib import constants | 24 from pylib import constants |
| 25 from pylib.constants import host_paths |
| 24 from pylib.utils import logging_utils | 26 from pylib.utils import logging_utils |
| 25 | 27 |
| 26 sys.path.append(os.path.join(constants.DIR_SOURCE_ROOT, 'build')) | 28 sys.path.append(os.path.join(host_paths.DIR_SOURCE_ROOT, 'build')) |
| 27 import find_depot_tools # pylint: disable=import-error,unused-import | 29 import find_depot_tools # pylint: disable=import-error,unused-import |
| 28 import breakpad | 30 import breakpad |
| 29 import download_from_google_storage | 31 import download_from_google_storage |
| 30 import upload_to_google_storage | 32 import upload_to_google_storage |
| 31 | 33 |
| 32 | 34 |
| 33 # Directory where the SHA1 files for the zip and the license are stored | 35 # Directory where the SHA1 files for the zip and the license are stored |
| 34 # It should be managed by git to provided information about new versions. | 36 # It should be managed by git to provided information about new versions. |
| 35 SHA1_DIRECTORY = os.path.join(constants.DIR_SOURCE_ROOT, 'build', 'android', | 37 SHA1_DIRECTORY = os.path.join(host_paths.DIR_SOURCE_ROOT, 'build', 'android', |
| 36 'play_services') | 38 'play_services') |
| 37 | 39 |
| 38 # Default bucket used for storing the files. | 40 # Default bucket used for storing the files. |
| 39 GMS_CLOUD_STORAGE = 'chromium-android-tools/play-services' | 41 GMS_CLOUD_STORAGE = 'chromium-android-tools/play-services' |
| 40 | 42 |
| 41 # Path to the default configuration file. It exposes the currently installed | 43 # Path to the default configuration file. It exposes the currently installed |
| 42 # version of the library in a human readable way. | 44 # version of the library in a human readable way. |
| 43 CONFIG_DEFAULT_PATH = os.path.join(constants.DIR_SOURCE_ROOT, 'build', | 45 CONFIG_DEFAULT_PATH = os.path.join(host_paths.DIR_SOURCE_ROOT, 'build', |
| 44 'android', 'play_services', 'config.json') | 46 'android', 'play_services', 'config.json') |
| 45 | 47 |
| 46 LICENSE_FILE_NAME = 'LICENSE' | 48 LICENSE_FILE_NAME = 'LICENSE' |
| 47 ZIP_FILE_NAME = 'google_play_services_library.zip' | 49 ZIP_FILE_NAME = 'google_play_services_library.zip' |
| 48 GMS_PACKAGE_ID = 'extra-google-google_play_services' # used by sdk manager | 50 GMS_PACKAGE_ID = 'extra-google-google_play_services' # used by sdk manager |
| 49 | 51 |
| 50 LICENSE_PATTERN = re.compile(r'^Pkg\.License=(?P<text>.*)$', re.MULTILINE) | 52 LICENSE_PATTERN = re.compile(r'^Pkg\.License=(?P<text>.*)$', re.MULTILINE) |
| 51 | 53 |
| 52 | 54 |
| 53 def main(raw_args): | 55 def main(raw_args): |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 86 action='store_true', | 88 action='store_true', |
| 87 help="don't commit the changes at the end") | 89 help="don't commit the changes at the end") |
| 88 parser_upload.set_defaults(func=Upload) | 90 parser_upload.set_defaults(func=Upload) |
| 89 AddBasicArguments(parser_upload) | 91 AddBasicArguments(parser_upload) |
| 90 AddBucketArguments(parser_upload) | 92 AddBucketArguments(parser_upload) |
| 91 | 93 |
| 92 args = parser.parse_args(raw_args) | 94 args = parser.parse_args(raw_args) |
| 93 if args.verbose: | 95 if args.verbose: |
| 94 logging.basicConfig(level=logging.DEBUG) | 96 logging.basicConfig(level=logging.DEBUG) |
| 95 logging_utils.ColorStreamHandler.MakeDefault(not _IsBotEnvironment()) | 97 logging_utils.ColorStreamHandler.MakeDefault(not _IsBotEnvironment()) |
| 98 devil_chromium.Initialize() |
| 96 return args.func(args) | 99 return args.func(args) |
| 97 | 100 |
| 98 | 101 |
| 99 def AddBasicArguments(parser): | 102 def AddBasicArguments(parser): |
| 100 ''' | 103 ''' |
| 101 Defines the common arguments on subparser rather than the main one. This | 104 Defines the common arguments on subparser rather than the main one. This |
| 102 allows to put arguments after the command: `foo.py upload --debug --force` | 105 allows to put arguments after the command: `foo.py upload --debug --force` |
| 103 instead of `foo.py --debug upload --force` | 106 instead of `foo.py --debug upload --force` |
| 104 ''' | 107 ''' |
| 105 | 108 |
| (...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 256 ''' | 259 ''' |
| 257 | 260 |
| 258 # This should function should not run on bots and could fail for many user | 261 # 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 | 262 # and setup related reasons. Also, exceptions here are not caught, so we |
| 260 # disable breakpad to avoid spamming the logs. | 263 # disable breakpad to avoid spamming the logs. |
| 261 breakpad.IS_ENABLED = False | 264 breakpad.IS_ENABLED = False |
| 262 | 265 |
| 263 config = utils.ConfigParser(args.config) | 266 config = utils.ConfigParser(args.config) |
| 264 paths = PlayServicesPaths(args.sdk_root, config.version_xml_path) | 267 paths = PlayServicesPaths(args.sdk_root, config.version_xml_path) |
| 265 | 268 |
| 266 if not args.skip_git and utils.IsRepoDirty(constants.DIR_SOURCE_ROOT): | 269 if not args.skip_git and utils.IsRepoDirty(host_paths.DIR_SOURCE_ROOT): |
| 267 logging.error('The repo is dirty. Please commit or stash your changes.') | 270 logging.error('The repo is dirty. Please commit or stash your changes.') |
| 268 return -1 | 271 return -1 |
| 269 | 272 |
| 270 new_version_number = utils.GetVersionNumberFromLibraryResources( | 273 new_version_number = utils.GetVersionNumberFromLibraryResources( |
| 271 paths.version_xml) | 274 paths.version_xml) |
| 272 logging.debug('comparing versions: new=%d, old=%s', | 275 logging.debug('comparing versions: new=%d, old=%s', |
| 273 new_version_number, config.version_number) | 276 new_version_number, config.version_number) |
| 274 if new_version_number <= config.version_number and not args.force: | 277 if new_version_number <= config.version_number and not args.force: |
| 275 logging.info('The checked in version of the library is already the latest ' | 278 logging.info('The checked in version of the library is already the latest ' |
| 276 'one. No update is needed. Please rerun with --force to skip ' | 279 'one. No update is needed. Please rerun with --force to skip ' |
| (...skipping 22 matching lines...) Expand all Loading... |
| 299 shutil.copy(new_lib_zip + '.sha1', new_lib_zip_sha1) | 302 shutil.copy(new_lib_zip + '.sha1', new_lib_zip_sha1) |
| 300 shutil.copy(new_license + '.sha1', new_license_sha1) | 303 shutil.copy(new_license + '.sha1', new_license_sha1) |
| 301 finally: | 304 finally: |
| 302 shutil.rmtree(tmp_root) | 305 shutil.rmtree(tmp_root) |
| 303 | 306 |
| 304 config.UpdateVersionNumber(new_version_number) | 307 config.UpdateVersionNumber(new_version_number) |
| 305 | 308 |
| 306 if not args.skip_git: | 309 if not args.skip_git: |
| 307 commit_message = ('Update the Google Play services dependency to %s\n' | 310 commit_message = ('Update the Google Play services dependency to %s\n' |
| 308 '\n') % new_version_number | 311 '\n') % new_version_number |
| 309 utils.MakeLocalCommit(constants.DIR_SOURCE_ROOT, | 312 utils.MakeLocalCommit(host_paths.DIR_SOURCE_ROOT, |
| 310 [new_lib_zip_sha1, new_license_sha1, config.path], | 313 [new_lib_zip_sha1, new_license_sha1, config.path], |
| 311 commit_message) | 314 commit_message) |
| 312 | 315 |
| 313 return 0 | 316 return 0 |
| 314 | 317 |
| 315 | 318 |
| 316 def _DownloadFromBucket(bucket_path, sha1_file, destination, verbose, | 319 def _DownloadFromBucket(bucket_path, sha1_file, destination, verbose, |
| 317 is_dry_run): | 320 is_dry_run): |
| 318 '''Downloads the file designated by the provided sha1 from a cloud bucket.''' | 321 '''Downloads the file designated by the provided sha1 from a cloud bucket.''' |
| 319 | 322 |
| (...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 503 logging.debug('Calling command "%s"', str(args)) | 506 logging.debug('Calling command "%s"', str(args)) |
| 504 return cmd_helper.GetCmdStatusOutputAndError(args) | 507 return cmd_helper.GetCmdStatusOutputAndError(args) |
| 505 | 508 |
| 506 def check_call(self, *args): | 509 def check_call(self, *args): |
| 507 logging.debug('Calling command "%s"', str(args)) | 510 logging.debug('Calling command "%s"', str(args)) |
| 508 return cmd_helper.GetCmdStatusOutputAndError(args) | 511 return cmd_helper.GetCmdStatusOutputAndError(args) |
| 509 | 512 |
| 510 | 513 |
| 511 if __name__ == '__main__': | 514 if __name__ == '__main__': |
| 512 sys.exit(main(sys.argv[1:])) | 515 sys.exit(main(sys.argv[1:])) |
| OLD | NEW |