Exemplo n.º 1
0
    def __init__(self,
                 sdk_root=None,
                 url=None,
                 platform_filter=None,
                 warn=True):
        """Creates a new UpdateManager.

    Args:
      sdk_root: str, The path to the root directory of the Cloud SDK is
        installation.  If None, the updater will search for the install
        directory based on the current directory.
      url: str, The URL to get the latest component snapshot from.  If None,
        the default will be used.
      platform_filter: platforms.Platform, A platform that components must match
        in order to be considered for any operations.  If None, only components
        without OS or architecture filters will match.
      warn: bool, True to warn about overridden configuration like an alternate
        snapshot file, fixed SDK version, or additional repo.  Should be set
        to False when using this class for background operations like checking
        for updates so the user only sees the warnings when they are actually
        dealing directly with the component manager.

    Raises:
      local_state.InvalidSDKRootError: If the Cloud SDK root cannot be found.
      MissingUpdateURLError: If we don't know what manifest to download.
    """

        if not url:
            url = properties.VALUES.component_manager.snapshot_url.Get()
        if url:
            if warn:
                log.warning('You are using an overridden snapshot URL: [%s]',
                            url)
        else:
            url = config.INSTALLATION_CONFIG.snapshot_url
        if not url:
            raise MissingUpdateURLError()

        # Change the snapshot URL to point to a fixed SDK version if specified.
        fixed_version = properties.VALUES.component_manager.fixed_sdk_version.Get(
        )
        if fixed_version:
            urls = url.split(',')
            urls[0] = (
                os.path.dirname(urls[0]) + '/' +
                UpdateManager.VERSIONED_SNAPSHOT_FORMAT.format(fixed_version))
            if warn:
                log.warning(
                    'You have configured your Cloud SDK installation to be '
                    'fixed to version [{0}].'.format(fixed_version))
            url = ','.join(urls)

        # Add in any additional repositories that have been registered.
        repos = properties.VALUES.component_manager.additional_repositories.Get(
        )
        if repos:
            if warn:
                for repo in repos.split(','):
                    log.warning(
                        'You are using additional component repository: [%s]',
                        repo)
            url = ','.join([url, repos])

        self.__sdk_root = sdk_root
        if not self.__sdk_root:
            self.__sdk_root = config.Paths().sdk_root
        if not self.__sdk_root:
            raise local_state.InvalidSDKRootError()
        self.__sdk_root = os.path.realpath(self.__sdk_root)
        self.__url = url
        self.__platform_filter = platform_filter
        self.__text_wrapper = textwrap.TextWrapper(replace_whitespace=False,
                                                   drop_whitespace=False)
        self.__warn = warn
Exemplo n.º 2
0
    def testCheckBinaryComponentInstalledLocalError(self):
        self.mock_updater.side_effect = local_state.InvalidSDKRootError()

        self.assertIsNone(
            binary_operations.CheckBinaryComponentInstalled('foo'))
        self.AssertErrContains('Could not verify SDK install path.')