def GetUpdateManager(group_args): """Construct the UpdateManager to use based on the common args for the group. Args: group_args: An argparse namespace. Returns: update_manager.UpdateManager, The UpdateManager to use for the commands. """ try: os_override = platforms.OperatingSystem.FromId( group_args.operating_system_override) except platforms.InvalidEnumValue as e: raise exceptions.InvalidArgumentException('operating-system-override', e) try: arch_override = platforms.Architecture.FromId( group_args.architecture_override) except platforms.InvalidEnumValue as e: raise exceptions.InvalidArgumentException('architecture-override', e) platform = platforms.Platform.Current(os_override, arch_override) root = (os.path.expanduser(group_args.sdk_root_override) if group_args.sdk_root_override else None) url = (os.path.expanduser(group_args.snapshot_url_override) if group_args.snapshot_url_override else None) return update_manager.UpdateManager(sdk_root=root, url=url, platform_filter=platform)
def UpdateCheck(): try: update_manager.UpdateManager(warn=False).PerformUpdateCheck() # pylint:disable=broad-except, We never want this to escape, ever. Only # messages printed should reach the user. except Exception: pass
def SetUp(self): self.platform = platforms.Platform(platforms.OperatingSystem.WINDOWS, platforms.Architecture.x86) self.real_manager = update_manager.UpdateManager( self.sdk_root_path, self.URLFromFile(self.Resource('parsetest.json')), platform_filter=self.platform) # This is because disable_updater is true for linux distributions which # causes packaging tests fo fail. config.INSTALLATION_CONFIG.disable_updater = False # This is for testListOnlyLocalState but needs to be done in SetUp because # once the updater patcher starts, calls to Update start throwing errors. self.real_manager.Update(['c1']) patcher = mock.patch( 'googlecloudsdk.core.updater.update_manager.UpdateManager', autospec=True) self.addCleanup(patcher.stop) self.updater_mock = patcher.start() patcher = mock.patch('googlecloudsdk.core.util.platforms.Platform', autospec=True) self.addCleanup(patcher.stop) self.platform_mock = patcher.start() self.platform_mock.Current.side_effect = lambda *args: args
def __init__(self): self.sdk_root = config.Paths().sdk_root self.release_channel = config.INSTALLATION_CONFIG.release_channel self.repo_url = config.INSTALLATION_CONFIG.snapshot_url repos = properties.VALUES.component_manager.additional_repositories.Get( validate=False) self.additional_repos = repos.split(',') if repos else [] # Keep it as array for structured output. self.path = encoding.GetEncodedValue(os.environ, 'PATH', '').split(os.pathsep) self.python_path = [ encoding.Decode(path_elem) for path_elem in sys.path ] if self.sdk_root: manager = update_manager.UpdateManager() self.components = manager.GetCurrentVersionsInformation() self.old_tool_paths = manager.FindAllOldToolsOnPath() self.duplicate_tool_paths = manager.FindAllDuplicateToolsOnPath() paths = [os.path.realpath(p) for p in self.path] this_path = os.path.realpath( os.path.join(self.sdk_root, update_manager.UpdateManager.BIN_DIR_NAME)) # TODO(b/36055867): Validate symlinks in /usr/local/bin when we start # creating them. self.on_path = this_path in paths else: self.components = {} self.old_tool_paths = [] self.duplicate_tool_paths = [] self.on_path = False self.kubectl = file_utils.SearchForExecutableOnPath('kubectl') if self.kubectl: self.kubectl = self.kubectl[0]
def Filter(self, unused_tool_context, args): if config.INSTALLATION_CONFIG.IsAlternateReleaseChannel(): log.warning('You are using alternate release channel: [%s]', config.INSTALLATION_CONFIG.release_channel) # Always show the URL if using a non standard release channel. log.warning('Snapshot URL for this release channel is: [%s]', config.INSTALLATION_CONFIG.snapshot_url) os_override = platforms.OperatingSystem.FromId( args.operating_system_override) arch_override = platforms.Architecture.FromId( args.architecture_override) platform = platforms.Platform.Current(os_override, arch_override) root = (os.path.expanduser(args.sdk_root_override) if args.sdk_root_override else None) url = (os.path.expanduser(args.snapshot_url_override) if args.snapshot_url_override else None) self.update_manager = update_manager.UpdateManager( sdk_root=root, url=url, platform_filter=platform, out_stream=log.out)
def CheckKubectlInstalled(): if config.Paths().sdk_root is not None: platform = platforms.Platform.Current() manager = update_manager.UpdateManager(platform_filter=platform, warn=False) installed_components = manager.GetCurrentVersionsInformation() if 'kubectl' not in installed_components: log.warn(MISSING_KUBECTL_MSG)
def SetUp(self): """Configure test binary(ies).""" if test_case.Filters.IsOnWindows(): suffix = 'windows_go' elif test_case.Filters.IsOnMac(): suffix = 'darwin_go' else: suffix = 'linux_go' self.basic_binary = 'structured_out_' + suffix self.sdk_root_path = self.CreateTempDir('cloudsdk') self.StartObjectPatch(config.Paths, 'sdk_root', self.sdk_root_path) self.scripts_dir = self.Resource('tests', 'unit', 'command_lib', 'test_data', 'util', 'anthos') self.StartObjectPatch(config.Paths, 'sdk_bin_path', self.scripts_dir) installed = {self.basic_binary: 1} mock_updater = self.StartObjectPatch(update_manager, 'UpdateManager', autospec=True) mock_updater.return_value = update_manager.UpdateManager( sdk_root=self.sdk_root_path, url='file://some/path/components.json', warn=False) (mock_updater.return_value.GetCurrentVersionsInformation.return_value ) = installed
def _KubectlInstalledAsComponent(): if config.Paths().sdk_root is not None: platform = platforms.Platform.Current() manager = update_manager.UpdateManager(platform_filter=platform, warn=False) installed_components = manager.GetCurrentVersionsInformation() return _KUBECTL_COMPONENT_NAME in installed_components
def Run(self, args): if config.Paths().sdk_root: # Components are only valid if this is a built Cloud SDK. manager = update_manager.UpdateManager() versions = dict(manager.GetCurrentVersionsInformation()) else: versions = {} versions['Google Cloud SDK'] = config.CLOUD_SDK_VERSION return versions
def CheckBinaryComponentInstalled(component_name, check_hidden=False): platform = platforms.Platform.Current() if config.Paths().sdk_root else None try: manager = update_manager.UpdateManager(platform_filter=platform, warn=False) return component_name in manager.GetCurrentVersionsInformation( include_hidden=check_hidden) except local_state.Error: log.warning('Component check failed. Could not verify SDK install path.') return None
def Epilog(self, resources_were_displayed): if config.Paths().sdk_root: # Components are only valid if this is a built Cloud SDK. manager = update_manager.UpdateManager() if manager.UpdatesAvailable(): log.status.write("""\ Updates are available for some Cloud SDK components. To install them, please run: $ gcloud components update""")
def CheckUpdates(): """Check for updates and inform the user. """ try: update_manager.UpdateManager().PerformUpdateCheck() # pylint:disable=broad-except, We never want this to escape, ever. Only # messages printed should reach the user. except Exception: pass
def SetUp(self): self.sdk_root_path = self.CreateTempDir('cloudsdk') self.StartObjectPatch(config.Paths, 'sdk_root', self.sdk_root_path) self.bin_path = os.path.join(self.sdk_root_path, 'bin') self.StartObjectPatch(config.Paths, 'sdk_bin_path', self.bin_path) installed = {'foo': 1, 'bar': 1} self.mock_updater = self.StartObjectPatch(update_manager, 'UpdateManager', autospec=True) self.mock_updater.return_value = update_manager.UpdateManager( sdk_root=self.sdk_root_path, url='file://some/path/components.json', warn=False) (self.mock_updater.return_value.GetCurrentVersionsInformation. return_value) = installed
def GetUpdateManager(group_args): """Construct the UpdateManager to use based on the common args for the group. Args: group_args: An argparse namespace. Returns: update_manager.UpdateManager, The UpdateManager to use for the commands. """ try: os_override = platforms.OperatingSystem.FromId( group_args.operating_system_override) except platforms.InvalidEnumValue as e: raise exceptions.InvalidArgumentException('operating-system-override', e) try: arch_override = platforms.Architecture.FromId( group_args.architecture_override) except platforms.InvalidEnumValue as e: raise exceptions.InvalidArgumentException('architecture-override', e) platform = platforms.Platform.Current(os_override, arch_override) # darwin-arm machines thats are running a darwin_x86_64 python binary will # report arch as darwin_x86_64 because Architecture.Current() uses # platform.machine() as the source of truth. Here in the UpdateManager we want # to know the "real" truth so we call IsActuallyM1ArmArchitecture as the # source of truth which breaks out of the python env to see the underlying # arch. if not os_override and not arch_override: if (platform.operating_system == platforms.OperatingSystem.MACOSX and platform.architecture == platforms.Architecture.x86_64): if platforms.Platform.IsActuallyM1ArmArchitecture(): platform.architecture = platforms.Architecture.arm root = (files.ExpandHomeDir(group_args.sdk_root_override) if group_args.sdk_root_override else None) url = (files.ExpandHomeDir(group_args.snapshot_url_override) if group_args.snapshot_url_override else None) compile_python = True if hasattr(group_args, 'compile_python'): compile_python = group_args.compile_python return update_manager.UpdateManager( sdk_root=root, url=url, platform_filter=platform, skip_compile_python=(not compile_python))
def InstallBinaryNoOverrides(binary_name, prompt): """Helper method for installing binary dependencies within command execs.""" console_io.PromptContinue( message='Pausing command execution:', prompt_string=prompt, cancel_on_no=True, cancel_string='Aborting component install for {} and command execution.' .format(binary_name)) platform = platforms.Platform.Current() update_manager_client = update_manager.UpdateManager(platform_filter=platform) update_manager_client.Install([binary_name]) path_executable = files.FindExecutableOnPath(binary_name) if path_executable: return path_executable raise MissingExecutableException( binary_name, '{} binary not installed'.format(binary_name))
def _GetDefaultCliCommandVersion(): """Return the default CLI command version.""" if _IsRunningUnderTest(): # test installation - return a constant version for reproducability return TEST_CLI_VERSION_TEST version = config.CLOUD_SDK_VERSION if version != TEST_CLI_VERSION_HEAD: # normal installation return version try: manager = update_manager.UpdateManager() components = manager.GetCurrentVersionsInformation() # personal installation version = components['core'] # YYYY.MM.DD more informative than HEAD except (KeyError, exceptions.Error): # HEAD will have to do pass return version
def __init__(self, anonymizer=None): anonymizer = anonymizer or NoopAnonymizer() self.sdk_root = anonymizer.ProcessPath(config.Paths().sdk_root) self.release_channel = config.INSTALLATION_CONFIG.release_channel self.repo_url = anonymizer.ProcessURL( config.INSTALLATION_CONFIG.snapshot_url) repos = properties.VALUES.component_manager.additional_repositories.Get( validate=False) self.additional_repos = (map(anonymizer.ProcessURL, repos.split(',')) if repos else []) # Keep it as array for structured output. path = encoding.GetEncodedValue(os.environ, 'PATH', '').split(os.pathsep) self.python_path = [ anonymizer.ProcessPath(encoding.Decode(path_elem)) for path_elem in sys.path ] if self.sdk_root: manager = update_manager.UpdateManager() self.components = manager.GetCurrentVersionsInformation() self.other_tool_paths = [ anonymizer.ProcessPath(p) for p in manager.FindAllOtherToolsOnPath() ] self.duplicate_tool_paths = [ anonymizer.ProcessPath(p) for p in manager.FindAllDuplicateToolsOnPath() ] paths = [os.path.realpath(p) for p in path] this_path = os.path.realpath( os.path.join(self.sdk_root, update_manager.UpdateManager.BIN_DIR_NAME)) self.on_path = this_path in paths else: self.components = {} self.other_tool_paths = [] self.duplicate_tool_paths = [] self.on_path = False self.path = [anonymizer.ProcessPath(p) for p in path] self.kubectl = file_utils.SearchForExecutableOnPath('kubectl') if self.kubectl: self.kubectl = anonymizer.ProcessPath(self.kubectl[0])
def GetUpdateManager(group_args): """Construct the UpdateManager to use based on the common args for the group. Args: group_args: An argparse namespace. Returns: update_manager.UpdateManager, The UpdateManager to use for the commands. """ os_override = platforms.OperatingSystem.FromId( group_args.operating_system_override) arch_override = platforms.Architecture.FromId( group_args.architecture_override) platform = platforms.Platform.Current(os_override, arch_override) root = (os.path.expanduser(group_args.sdk_root_override) if group_args.sdk_root_override else None) url = (os.path.expanduser(group_args.snapshot_url_override) if group_args.snapshot_url_override else None) return update_manager.UpdateManager(sdk_root=root, url=url, platform_filter=platform)
def __init__(self): self.sdk_root = config.Paths().sdk_root self.release_channel = config.INSTALLATION_CONFIG.release_channel self.repo_url = config.INSTALLATION_CONFIG.snapshot_url repos = properties.VALUES.component_manager.additional_repositories.Get( validate=False) self.additional_repos = repos.split(',') if repos else [] self.path = os.environ.get('PATH', '') if self.sdk_root: manager = update_manager.UpdateManager() self.components = manager.GetCurrentVersionsInformation() self.old_tool_paths = manager.FindAllOldToolsOnPath() paths = [os.path.realpath(p) for p in self.path.split(os.pathsep)] this_path = os.path.realpath( os.path.join(self.sdk_root, update_manager.UpdateManager.BIN_DIR_NAME)) # TODO(user): Validate symlinks in /usr/local/bin when we start # creating them. self.on_path = this_path in paths else: self.components = {} self.old_tool_paths = [] self.on_path = False
def CheckBinaryComponentInstalled(component_name): platform = platforms.Platform.Current() if config.Paths( ).sdk_root else None manager = update_manager.UpdateManager(platform_filter=platform, warn=False) return component_name in manager.GetCurrentVersionsInformation()
def _IsPythonBundled(): # pylint:disable=g-import-not-at-top, We can't do this import unless we are # in bundled mode. from googlecloudsdk.core.updater import update_manager return update_manager.UpdateManager().IsPythonBundled()
def _GetInstalledComponents(): # pylint:disable=g-import-not-at-top, We can't do this import unless we are # in bundled mode. from googlecloudsdk.core.updater import update_manager return six.iterkeys( update_manager.UpdateManager().GetCurrentVersionsInformation())
def Run(self, args): manager = update_manager.UpdateManager() return manager.GetCurrentVersionsInformation()
def Run(self, args): if config.Paths().sdk_root: # Components are only valid if this is a built Cloud SDK. manager = update_manager.UpdateManager() return manager.GetCurrentVersionsInformation() return []