def pinch_system(self, manager: PackageManagerBase = None, force: bool = False) -> None: """ Delete packages marked for deletion in the XML description. If force param is set to False uninstalls packages marked with `type="uninstall"` if any; if force is set to True deletes packages marked with `type="delete"` if any. :param object manager: instance of :class:`PackageManager` subclass :param bool force: Forced deletion True|False :raises KiwiPackagesDeletePhaseFailed: if the deletion packages process fails """ to_become_deleted_packages = \ self.xml_state.get_to_become_deleted_packages(force) if to_become_deleted_packages: log.info('{0} system packages (chroot)'.format( 'Force deleting' if force else 'Uninstalling')) try: if manager is None: package_manager = self.xml_state.get_package_manager() manager = PackageManager.new( Repository.new(self.root_bind, package_manager), package_manager) self.delete_packages(manager, to_become_deleted_packages, force) except Exception as issue: raise KiwiPackagesDeletePhaseFailed( self.issue_message.format( headline='System package deletion failed', reason=issue))
def clean_package_manager_leftovers(self) -> None: """ This methods cleans some package manager artifacts created at run time such as macros """ package_manager = self.xml_state.get_package_manager() manager = PackageManager.new( Repository.new(self.root_bind, package_manager), package_manager) manager.clean_leftovers()
def import_repositories_marked_as_imageinclude(self) -> None: """ Those <repository> sections which are marked with the imageinclude attribute should be permanently added to the image repository configuration """ repository_sections = \ self.xml_state.get_repository_sections_used_in_image() root = RootInit( root_dir=self.root_dir, allow_existing=True ) repo = Repository.new( RootBind(root), self.xml_state.get_package_manager() ) repo.use_default_location() for xml_repo in repository_sections: repo_type = xml_repo.get_type() repo_source = xml_repo.get_source().get_path() repo_user = xml_repo.get_username() repo_secret = xml_repo.get_password() repo_alias = xml_repo.get_alias() repo_priority = xml_repo.get_priority() repo_dist = xml_repo.get_distribution() repo_components = xml_repo.get_components() repo_repository_gpgcheck = xml_repo.get_repository_gpgcheck() repo_package_gpgcheck = xml_repo.get_package_gpgcheck() repo_customization_script = self._get_repo_customization_script( xml_repo ) repo_sourcetype = xml_repo.get_sourcetype() repo_use_for_bootstrap = False uri = Uri(repo_source, repo_type) repo_source_translated = uri.translate( check_build_environment=False ) if not repo_alias: repo_alias = uri.alias() log.info('Setting up image repository {0}'.format(repo_source)) log.info('--> Type: {0}'.format(repo_type)) log.info('--> Translated: {0}'.format(repo_source_translated)) log.info('--> Alias: {0}'.format(repo_alias)) repo.add_repo( repo_alias, repo_source_translated, repo_type, repo_priority, repo_dist, repo_components, repo_user, repo_secret, uri.credentials_file_name(), repo_repository_gpgcheck, repo_package_gpgcheck, repo_sourcetype, repo_use_for_bootstrap, repo_customization_script )
def setup_repositories(self, clear_cache=False, signing_keys=None): """ Set up repositories for software installation and return a package manager for performing software installation tasks :param bool clear_cache: flag the clear cache before configure anything :param list signing_keys: keys imported to the package manager :return: instance of :class:`PackageManager` :rtype: PackageManager """ repository_options = [] repository_sections = \ self.xml_state.get_repository_sections_used_for_build() package_manager = self.xml_state.get_package_manager() rpm_locale_list = self.xml_state.get_rpm_locale() if self.xml_state.get_rpm_check_signatures(): repository_options.append('check_signatures') if self.xml_state.get_rpm_excludedocs(): repository_options.append('exclude_docs') if rpm_locale_list: repository_options.append( '_install_langs%{0}'.format(':'.join(rpm_locale_list)) ) repo = Repository.new( self.root_bind, package_manager, repository_options ) repo.setup_package_database_configuration() if signing_keys: repo.import_trusted_keys(signing_keys) for xml_repo in repository_sections: repo_type = xml_repo.get_type() repo_source = xml_repo.get_source().get_path() repo_user = xml_repo.get_username() repo_secret = xml_repo.get_password() repo_alias = xml_repo.get_alias() repo_priority = xml_repo.get_priority() repo_dist = xml_repo.get_distribution() repo_components = xml_repo.get_components() repo_repository_gpgcheck = xml_repo.get_repository_gpgcheck() repo_package_gpgcheck = xml_repo.get_package_gpgcheck() repo_sourcetype = xml_repo.get_sourcetype() repo_use_for_bootstrap = \ True if xml_repo.get_use_for_bootstrap() else False log.info('Setting up repository %s', repo_source) log.info('--> Type: {0}'.format(repo_type)) if repo_sourcetype: log.info('--> SourceType: {0}'.format(repo_sourcetype)) if repo_priority: log.info('--> Priority: {0}'.format(repo_priority)) uri = Uri(repo_source, repo_type) repo_source_translated = uri.translate() log.info('--> Translated: {0}'.format(repo_source_translated)) if not repo_alias: repo_alias = uri.alias() log.info('--> Alias: {0}'.format(repo_alias)) if not uri.is_remote() and not os.path.exists( repo_source_translated ): log.warning( 'repository %s does not exist and will be skipped', repo_source ) continue if not uri.is_remote(): self.root_bind.mount_shared_directory(repo_source_translated) repo.add_repo( repo_alias, repo_source_translated, repo_type, repo_priority, repo_dist, repo_components, repo_user, repo_secret, uri.credentials_file_name(), repo_repository_gpgcheck, repo_package_gpgcheck, repo_sourcetype, repo_use_for_bootstrap ) if clear_cache: repo.delete_repo_cache(repo_alias) self.uri_list.append(uri) repo.cleanup_unused_repos() return PackageManager.new( repo, package_manager )
def test_repository_manager_not_implemented(self): with raises(KiwiRepositorySetupError): Repository.new('root_bind', 'ms-manager')
def test_repository_pacman(self, mock_manager): root_bind = mock.Mock() Repository.new(root_bind, 'pacman') mock_manager.assert_called_once_with(root_bind, None)
def test_repository_microdnf(self, mock_manager): root_bind = mock.Mock() Repository.new(root_bind, 'microdnf') mock_manager.assert_called_once_with(root_bind, None)