def installed_packages(self, pkg_names=None, repo_filter=None): """ Return all installed packages in the system except packages in REPO_URL_EXCLUDE :type pkg_names list|set :type repo_filter str|None :return formatted list of packages """ packages = [] available_packages = self._available_packages_dict( pkg_names, repo_filter) with shell.process_executor( self.properties.installed_packages_cmd, error_callback=self._executor_error_handler) as output: for package, version in AptParser.packages_installed_reader( output): if package in available_packages: packages.append(available_packages[package]) if package not in available_packages: packages.append([ package, version, "installed" ]) # case, when some package not belongs to any known repo return packages
def _check_existence(self, name): """ For regexp names: If only part of packages were installed during early canceling. Let's say: 1. install hbase-2-3-.* 2. Only hbase-2-3-1234 is installed, but is not hbase-2-3-1234-regionserver yet. 3. We cancel the apt-get In that case this is bug of packages we require. And hbase-2-3-*-regionserver should be added to metainfo.xml. Checking existence should never fail in such a case for hbase-2-3-.*, otherwise it gonna break things like removing packages and some other things. Note: this method SHOULD NOT use apt-get (apt.cache is using dpkg not apt). Because a lot of issues we have, when customer have apt-get in inconsistant state (locked, used, having invalid repo). Once packages are installed we should not rely on that. """ # this method is more optimised than #installed_packages, as here we do not call available packages(as we do not # interested in repository, from where package come) cmd = self.properties.installed_packages_cmd + [name] with shell.process_executor( cmd, strategy=shell.ReaderStrategy.BufferedChunks, silent=True) as output: for package, version in AptParser.packages_installed_reader( output): return package == name return False
def all_available_packages(self, result_type=list, group_by_index=-1): """ Return all available packages in the system except packages in REPO_URL_EXCLUDE :arg result_type Could be list or dict, defines type of returning value :arg group_by_index index of element in the __packages_reader result, which would be used as key :return result_type formatted list of packages, including installed and available in repos :type result_type type :type group_by_index int :rtype list|dict """ if result_type is not list and result_type is not dict: raise TypeError("result_type argument must be list or dict only") packages = result_type() with process_executor(ALL_AVAILABLE_PACKAGES_DUMP_CMD, error_callback=self._executor_error_handler) as output: for pkg_item in self.__packages_reader(output): if REPO_URL_EXCLUDE not in pkg_item[2]: if result_type is list: packages.append(pkg_item) elif result_type is dict: packages[pkg_item[group_by_index]] = pkg_item return packages
def all_installed_packages(self, from_unknown_repo=False): """ Return all installed packages in the system except packages in REPO_URL_EXCLUDE :arg from_unknown_repo return packages from unknown repos :type from_unknown_repo bool :return result_type formatted list of packages """ packages = [] available_packages = self.all_available_packages(result_type=dict, group_by_index=0) with process_executor( ALL_INSTALLED_PACKAGES_CMD, error_callback=self._executor_error_handler) as output: for package, version in self.__packages_installed_reader(output): if not from_unknown_repo and package in available_packages: packages.append(available_packages[package]) if package not in available_packages: packages.append([ package, version, "installed" ]) # case, when some package not belongs to any known repo return packages
def package_manager_configuration(self): """ Reading apt configuration :return dict with apt properties """ with process_executor(CONFIGURATION_DUMP_CMD, error_callback=self._executor_error_handler) as output: configuration = list(self.__config_reader(output)) return dict(configuration)
def package_manager_configuration(self): """ Reading apt configuration :return dict with apt properties """ with shell.process_executor( self.properties.configuration_dump_cmd, error_callback=self._executor_error_handler) as output: configuration = list(AptParser.config_reader(output)) return dict(configuration)
def get_active_base_repos(self): enabled_repos = [] with shell.process_executor(self.properties.list_active_repos_cmd, error_callback=self._executor_error_handler) as output: for _, repo_name, repo_enabled, _ in ZypperParser.repo_list_reader(output): if repo_enabled and repo_name.startswith("SUSE-"): enabled_repos.append(repo_name) if repo_enabled and ("OSS" in repo_name) or ("OpenSuse" in repo_name): enabled_repos.append(repo_name) return enabled_repos
def _available_packages(self, pkg_names=None, repo_filter=None): """ Returning list of the installed packages with possibility to filter them by name :type pkg_names list|set :type repo_filter str|None """ with shell.process_executor( self.properties.available_packages_cmd, error_callback=self._executor_error_handler) as output: for pkg_item in AptParser.packages_reader(output): if repo_filter and repo_filter not in pkg_item[2]: continue if self.properties.repo_url_exclude in pkg_item[2]: continue if pkg_names and pkg_item[0] not in pkg_names: continue yield pkg_item
def installed_packages(self, pkg_names=None, repo_filter=None): """ Returning list of the installed packages with possibility to filter them by name :type pkg_names list|set :type repo_filter str|None :rtype list[list,] """ packages = [] cmd = list(self.properties.installed_packages_cmd) if repo_filter: cmd.extend(["--repo=" + repo_filter]) with shell.process_executor(cmd, error_callback=self._executor_error_handler) as output: for pkg in ZypperParser.packages_reader(output): if pkg_names and not pkg[0] in pkg_names: continue packages.append(pkg) return packages
def all_packages(self, pkg_names=None, repo_filter=None): """ Returning list of the installed packages with possibility to filter them by name :type pkg_names list|set :type repo_filter str|None :rtype list[list,] """ packages = [] cmd = self.properties.all_packages_cmd with shell.process_executor( cmd, error_callback=self._executor_error_handler) as output: for pkg in YumParser.packages_reader(output): if pkg_names and not pkg[0] in pkg_names: continue if repo_filter and repo_filter.lower() != pkg[2].lower(): continue packages.append(pkg) return packages