Exemplo n.º 1
0
def GetLatestAvailableVersionURI(version_num):
    """Get the latest available google cloud storage URI for given version.

  If the URI for the given version number is not available, it will decrement
  the version number and try to find the latest available one.

  Args:
    version_num(string): String representing the latest version number.

  Returns:
    string: The URI for the latest version of Chrome for a given milestone.

  Raises:
    CloudDownloadFailed: this would be risen if we cannot find the apk within
    5 patches
  """

    chrome_version = ChromeVersion(version_num)
    # Monochrome is introduced at M53, we will use normal chrome for earlier
    # milestones
    chrome_type = 'Monochrome' if chrome_version.milestone >= 53 else 'Chrome'
    # check whether the latest patch is in the Google Cloud storage as
    # sometimes it is not, so we need to decrement patch and get the
    # previous one
    for i in range(20):
        # above number has been tested, and it works from milestone 45 to 68
        download_uri = (
            'gs://chrome-signed/android-*/%s/%s/%s'
            'Stable.apk') % (chrome_version.GetDecrementedVersionNum(i),
                             PROCESSOR_ARCHITECTURE, chrome_type)
        # check exit code to confirm the existence of the package
        if subprocess.call(['gsutil', 'ls', download_uri]) == 0:
            return download_uri

    raise utils.CloudDownloadFailed(version_num)
Exemplo n.º 2
0
    def GetLatestVersionURI(self, milestone_num):
        """Get the latest google cloud storage uri for given milestone.

    Args:
      milestone_num(int): Number representing the milestone.

    Returns:
      string: The URI for the latest version of Chrome for a given milestone.

    Raises:
      CloudDownloadFailed: this would be risen if we cannot find the apk within
      5 patches
    """
        version_num = self.GetVersionNumberFromMilestone(milestone_num)
        # check whether the latest patch is in the Google Cloud storage as
        # sometimes it is not, so we need to decrement patch and get the
        # previous one
        for i in range(5):
            # above number has been tested, and it works from milestone 45 to 68
            download_uri = ('gs://chrome-signed/android-*/%s/%s/Chrome'
                            'Stable.apk') % (DecrementPatchNumber(
                                version_num, i), PROCESSOR_ARCHITECTURE)
            # check exit code to confirm the existence of the package
            if subprocess.call(['gsutil', 'ls', download_uri]) == 0:
                return download_uri

        raise utils.CloudDownloadFailed(milestone_num)
Exemplo n.º 3
0
def DownloadAPKFromURI(uri, output_dir):
    """Used to download the APKs from google cloud into the out folder.

  Args:
    uri(string): Gsutil URI
    output_dir(string): The path that the APKs will be stored

  Returns:
    string: the path of the downloaded APK
  """
    def GetAPKName(gs_uri):
        # example `gs_uri`: gs://chrome-signed/android-B0urB0N/56.0.2924.3/arm/
        # ChromeStable.apk
        return '_'.join(gs_uri.split('/')[-3:])

    path_to_apk = os.path.join(output_dir, GetAPKName(uri))

    try:
        subprocess.check_call(['gsutil', 'cp', uri, path_to_apk])
    except subprocess.CalledProcessError:
        raise utils.CloudDownloadFailed(uri)

    return path_to_apk