示例#1
0
    def LocalPath(self, dependency, platform):
        """Get a path to a locally stored executable for |dependency|.

    A path to a default executable may be returned if a platform specific
    version is not specified in the config(s).
    Will not download the executable.

    Args:
        dependency: Name of the desired dependency, as given in the config(s)
            used in this DependencyManager.
        platform: Name of the platform the dependency will run on. Often of the
            form 'os_architecture'. Must match those specified in the config(s)
            used in this DependencyManager.
    Returns:
        A path to an executable for |dependency| that will run on |platform|.

    Raises:
        NoPathFoundError: If a local copy of the executable cannot be found.
    """
        dependency_info = self._GetDependencyInfo(dependency, platform)
        if not dependency_info:
            raise exceptions.NoPathFoundError(dependency, platform)
        local_path = dependency_info.GetLocalPath()
        if not local_path or not os.path.exists(local_path):
            raise exceptions.NoPathFoundError(dependency, platform)
        return local_path
示例#2
0
    def FetchPathWithVersion(self, dependency, platform):
        """Get a path to an executable for |dependency|, downloading as needed.

    A path to a default executable may be returned if a platform specific
    version is not specified in the config(s).

    Args:
        dependency: Name of the desired dependency, as given in the config(s)
            used in this DependencyManager.
        platform: Name of the platform the dependency will run on. Often of the
            form 'os_architecture'. Must match those specified in the config(s)
            used in this DependencyManager.
    Returns:
        <path>, <version> where:
            <path> is the path to an executable of |dependency| that will run
            on |platform|, downloading from cloud storage if needed.
            <version> is the version of the executable at <path> or None.

    Raises:
        NoPathFoundError: If a local copy of the executable cannot be found and
            a remote path could not be downloaded from cloud_storage.
        CredentialsError: If cloud_storage credentials aren't configured.
        PermissionError: If cloud_storage credentials are configured, but not
            with an account that has permission to download the remote file.
        NotFoundError: If the remote file does not exist where expected in
            cloud_storage.
        ServerError: If an internal server error is hit while downloading the
            remote file.
        CloudStorageError: If another error occured while downloading the remote
            path.
        FileNotFoundError: If an attempted download was otherwise unessful.

    """
        dependency_info = self._GetDependencyInfo(dependency, platform)
        if not dependency_info:
            raise exceptions.NoPathFoundError(dependency, platform)
        path = dependency_info.GetLocalPath()
        version = None
        if not path or not os.path.exists(path):
            path = dependency_info.GetRemotePath()
            if not path or not os.path.exists(path):
                raise exceptions.NoPathFoundError(dependency, platform)
            version = dependency_info.GetRemotePathVersion()
        return path, version
示例#3
0
    def PrefetchPaths(self,
                      platform,
                      dependencies=None,
                      cloud_storage_retries=3):
        if not dependencies:
            dependencies = self._lookup_dict.keys()

        skipped_deps = []
        found_deps = []
        missing_deps = []
        for dependency in dependencies:
            dependency_info = self._GetDependencyInfo(dependency, platform)
            if not dependency_info:
                # The dependency is only configured for other platforms.
                skipped_deps.append(dependency)
                logging.warning(
                    'Dependency %s not configured for platform %s. Skipping prefetch.',
                    dependency, platform)
                continue
            local_path = dependency_info.GetLocalPath()
            if local_path:
                found_deps.append(dependency)
                continue
            fetched_path = None
            for _ in range(0, cloud_storage_retries + 1):
                try:
                    fetched_path = dependency_info.GetRemotePath()
                except exceptions.CloudStorageError:
                    continue
                break
            if fetched_path:
                found_deps.append(dependency)
            else:
                missing_deps.append(dependency)
                logging.error(
                    'Dependency %s could not be found or fetched from cloud storage for'
                    ' platform %s.', dependency, platform)
        if missing_deps:
            raise exceptions.NoPathFoundError(', '.join(missing_deps),
                                              platform)
        return (found_deps, skipped_deps)