parameters: (args)
return_statement: return 0
docstring: Downloads the Google Play services library from a Google Cloud Storage bucket
    and installs it to
    //third_party/android_tools/sdk/extras/google/google_play_services.
  
    A license check will be made, and the user might have to accept the license
    if that has not been done before.
docstring_summary: Downloads the Google Play services library from a Google Cloud Storage bucket
    and installs it to
    //third_party/android_tools/sdk/extras/google/google_play_services.
docstring_tokens: Downloads the Google Play services library from a Google Cloud Storage bucket and installs it to // third_party / android_tools / sdk / extras / google / google_play_services .
function: def Download(args):
    '''
    Downloads the Google Play services library from a Google Cloud Storage bucket
    and installs it to
    //third_party/android_tools/sdk/extras/google/google_play_services.
  
    A license check will be made, and the user might have to accept the license
    if that has not been done before.
    '''
  
    if not os.path.isdir(args.sdk_root):
      logging.debug('Did not find the Android SDK root directory at "%s".',
                    args.sdk_root)
      if not args.force:
        logging.info('Skipping, not on an android checkout.')
        return 0
  
    config = utils.ConfigParser(args.config)
    paths = PlayServicesPaths(args.sdk_root, config.version_xml_path)
  
    if os.path.isdir(paths.package) and not os.access(paths.package, os.W_OK):
      logging.error('Failed updating the Google Play Services library. '
                    'The location is not writable. Please remove the '
                    'directory (%s) and try again.', paths.package)
      return -2
  
    new_lib_zip_sha1 = os.path.join(SHA1_DIRECTORY, ZIP_FILE_NAME + '.sha1')
  
    logging.debug('Comparing zip hashes: %s and %s', new_lib_zip_sha1,
                  paths.lib_zip_sha1)
    if utils.FileEquals(new_lib_zip_sha1, paths.lib_zip_sha1) and not args.force:
      logging.info('Skipping, the Google Play services library is up to date.')
      return 0
  
    bucket_path = _VerifyBucketPathFormat(args.bucket,
                                          config.version_number,
                                          args.dry_run)
  
    tmp_root = tempfile.mkdtemp()
    try:
      # setup the destination directory
      if not os.path.isdir(paths.package):
        os.makedirs(paths.package)
  
      # download license file from bucket/{version_number}/license.sha1
      new_license = os.path.join(tmp_root, LICENSE_FILE_NAME)
  
      license_sha1 = os.path.join(SHA1_DIRECTORY, LICENSE_FILE_NAME + '.sha1')
      _DownloadFromBucket(bucket_path, license_sha1, new_license,
                          args.verbose, args.dry_run)
  
      if (not _IsBotEnvironment() and
          not _CheckLicenseAgreement(new_license, paths.license,
                                     config.version_number)):
          logging.warning('Your version of the Google Play services library is '
                          'not up to date. You might run into issues building '
                          'or running the app. Please run `%s download` to '
                          'retry downloading it.', __file__)
          return 0
  
      new_lib_zip = os.path.join(tmp_root, ZIP_FILE_NAME)
      _DownloadFromBucket(bucket_path, new_lib_zip_sha1, new_lib_zip,
                          args.verbose, args.dry_run)
  
      try:
        # We remove the current version of the Google Play services SDK.
        if os.path.exists(paths.package):
          shutil.rmtree(paths.package)
        os.makedirs(paths.package)
  
        logging.debug('Extracting the library to %s', paths.lib)
        with zipfile.ZipFile(new_lib_zip, "r") as new_lib_zip_file:
          new_lib_zip_file.extractall(paths.lib)
  
        logging.debug('Copying %s to %s', new_license, paths.license)
        shutil.copy(new_license, paths.license)
  
        logging.debug('Copying %s to %s', new_lib_zip_sha1, paths.lib_zip_sha1)
        shutil.copy(new_lib_zip_sha1, paths.lib_zip_sha1)
  
        logging.info('Update complete.')
  
      except Exception as e:  # pylint: disable=broad-except
        logging.error('Failed updating the Google Play Services library. '
                      'An error occurred while installing the new version in '
                      'the SDK directory: %s ', e)
        return -3
    finally:
      shutil.rmtree(tmp_root)
  
    return 0
function_tokens: def Download ( args ) : if not os . path . isdir ( args . sdk_root ) : logging . debug ( 'Did not find the Android SDK root directory at "%s".' , args . sdk_root ) if not args . force : logging . info ( 'Skipping, not on an android checkout.' ) return 0 config = utils . ConfigParser ( args . config ) paths = PlayServicesPaths ( args . sdk_root , config . version_xml_path ) if os . path . isdir ( paths . package ) and not os . access ( paths . package , os . W_OK ) : logging . error ( 'Failed updating the Google Play Services library. ' 'The location is not writable. Please remove the ' 'directory (%s) and try again.' , paths . package ) return - 2 new_lib_zip_sha1 = os . path . join ( SHA1_DIRECTORY , ZIP_FILE_NAME + '.sha1' ) logging . debug ( 'Comparing zip hashes: %s and %s' , new_lib_zip_sha1 , paths . lib_zip_sha1 ) if utils . FileEquals ( new_lib_zip_sha1 , paths . lib_zip_sha1 ) and not args . force : logging . info ( 'Skipping, the Google Play services library is up to date.' ) return 0 bucket_path = _VerifyBucketPathFormat ( args . bucket , config . version_number , args . dry_run ) tmp_root = tempfile . mkdtemp ( ) try : # setup the destination directory if not os . path . isdir ( paths . package ) : os . makedirs ( paths . package ) # download license file from bucket/{version_number}/license.sha1 new_license = os . path . join ( tmp_root , LICENSE_FILE_NAME ) license_sha1 = os . path . join ( SHA1_DIRECTORY , LICENSE_FILE_NAME + '.sha1' ) _DownloadFromBucket ( bucket_path , license_sha1 , new_license , args . verbose , args . dry_run ) if ( not _IsBotEnvironment ( ) and not _CheckLicenseAgreement ( new_license , paths . license , config . version_number ) ) : logging . warning ( 'Your version of the Google Play services library is ' 'not up to date. You might run into issues building ' 'or running the app. Please run `%s download` to ' 'retry downloading it.' , __file__ ) return 0 new_lib_zip = os . path . join ( tmp_root , ZIP_FILE_NAME ) _DownloadFromBucket ( bucket_path , new_lib_zip_sha1 , new_lib_zip , args . verbose , args . dry_run ) try : # We remove the current version of the Google Play services SDK. if os . path . exists ( paths . package ) : shutil . rmtree ( paths . package ) os . makedirs ( paths . package ) logging . debug ( 'Extracting the library to %s' , paths . lib ) with zipfile . ZipFile ( new_lib_zip , "r" ) as new_lib_zip_file : new_lib_zip_file . extractall ( paths . lib ) logging . debug ( 'Copying %s to %s' , new_license , paths . license ) shutil . copy ( new_license , paths . license ) logging . debug ( 'Copying %s to %s' , new_lib_zip_sha1 , paths . lib_zip_sha1 ) shutil . copy ( new_lib_zip_sha1 , paths . lib_zip_sha1 ) logging . info ( 'Update complete.' ) except Exception as e : # pylint: disable=broad-except logging . error ( 'Failed updating the Google Play Services library. ' 'An error occurred while installing the new version in ' 'the SDK directory: %s ' , e ) return - 3 finally : shutil . rmtree ( tmp_root ) return 0