def _get_pkgs_details_from_apt_cache_show(self, pkg_dicts): # Convert package names to name:arch=version format queries = ["%(name)s:%(architecture)s=%(version)s" % p for p in pkg_dicts] # Call "apt-cache show" in batches exec_gen = execute_command_batch(self._session, ['apt-cache', 'show'], queries) # Parse and accumulate "apt-cache show" results results = (parse_apt_cache_show_pkgs_output(out) for (out, _, _) in exec_gen) # Combine sequence of lists results = itertools.chain.from_iterable(results) # Turn apt-cache show results into a lookup table by package name results = self.create_lookup_from_apt_cache_show(results) # Loop through each package and find the respective apt-cache results for p in pkg_dicts: r = results.get("%(name)s:%(architecture)s" % p) if not r: lgr.warning("Was unable to run apt-cache show for %s" % p["name"]) continue # Update the dictionary with found results (if present) for f in ("source_name", "source_version", "size", "md5", "sha1", "sha256"): if f in r: p[f] = r[f]
def _get_pkgs_arch_and_version(self, pkg_dicts): # Convert package names to name:arch format # Use "dpkg -s pkg" to get the installed version and arch # Note: "architecture" is in the dict, but may be null queries = [(p["name"] if not p["architecture"] else "%(name)s:%(architecture)s" % p) for p in pkg_dicts] # Call "dpkg -s" in batches exec_gen = execute_command_batch(self._session, ['dpkg', '-s'], queries) # Parse and accumulate "dpkg -s" results # dpkg -s uses the same output as apt-cache show pkg results = (parse_apt_cache_show_pkgs_output(out) for (out, _, _) in exec_gen) # Combine sequence of lists results = itertools.chain.from_iterable(results) # Turn dpkg -s results into a lookup table by package name results = self.create_lookup_from_apt_cache_show(results) # Loop through each package and find the respective dpkg results for p in pkg_dicts: r = results.get(p["name"] if not p["architecture"] else "%(name)s:%(architecture)s" % p) if not r: lgr.warning("Was unable to run dpkg -s for %s" % p["name"]) continue # Update the dictionary with found results p["architecture"] = r["architecture"] p["version"] = r["version"]