help=_("Print some information about the given package(s)"))
info.add_argument("--filelist", action="store_true",
help=_("Show filelist"))
- info.add_argument("package", help=_("Give at least the name of one package."))
+ info.add_argument("package", nargs="+",
+ help=_("Give at least the name of one package."))
info.set_defaults(func=self._info)
# provides
# requires
requires = subparsers.add_parser("requires",
help=_("Get a list of packages that require a given file or feature"))
- requires.add_argument("pattern", help=_("File or feature to search for"))
+ requires.add_argument("pattern", nargs="+",
+ help=_("File or feature to search for"))
requires.set_defaults(func=self._requires)
# repolist
for pkg in pkgs:
p.dist(pkg, resultdir)
+ # Some common functions
+
+ def _print_packages(self, packages, unique=True, long=True, **kwargs):
+ """
+ This is a helper function that prints the result of a search
+ """
+ # Make all packages only appear once in the result
+ if unique:
+ packages = set(packages)
+
+ # Walk through all packages in order
+ for package in sorted(packages):
+ # Dump all metadata
+ s = package.dump(long=long, **kwargs)
+
+ # Print the result
+ print(s)
+
+ def _search_packages(self, func, *args, **kwargs):
+ """
+ This is a helper function that performs a search for packages
+ """
+ packages = []
+
+ # Search and store the results
+ for arg in args:
+ packages += func(arg, **kwargs)
+
+ return packages
+
def _info(self, ns):
"""
Shows information about a certain package
"""
p = self.pakfire(ns)
- pkgs = []
+ archives = []
+ patterns = []
- # Try to open a file at this name
- try:
- archive = p.open(ns.package)
+ # Find all archives
+ for package in ns.package:
+ print(package)
+ try:
+ archive = p.open(package)
+ archives.append(archive)
- pkgs.append(archive.get_package())
+ # If we could not open the file, we will search for the pattern later
+ except FileNotFoundError:
+ patterns.append(package)
- # If there is no file, or it could not be opened,
- # search for a package with a matching name...
- except FileNotFoundError:
- pkgs += p.search(ns.package, name_only=True)
+ packages = []
- for pkg in sorted(pkgs):
- s = pkg.dump(long=True, filelist=ns.filelist)
- print(s)
+ # Perform the pattern search
+ if patterns:
+ packages += self._search_packages(p.search, *patterns, name_only=True)
+
+ # Append all packages found in the archives
+ if archives:
+ packages += (a.get_package() for a in archives)
+
+ # Print the result
+ self._print_packages(packages)
def _requires(self, ns):
- for pkg in self.pakfire(ns).whatrequires(ns.pattern):
- s = pkg.dump(long=True)
- print(s)
+ """
+ Searches for all packages that have a certain requirement
+ """
+ p = self.pakfire(ns)
+
+ # Search for packages
+ packages = self._search_packages(p.whatrequires, *ns.pattern)
+
+ # Print packages
+ self._print_packages(packages)
def _provides(self, ns):
"""
"""
p = self.pakfire(ns)
- packages = set()
+ # Search for packages
+ packages = self._search_packages(p.whatprovides, *ns.pattern)
- # Walk through all patterns and find all packages
- for pattern in ns.pattern:
- packages.update(p.whatprovides(pattern))
-
- # Print all packages
- for package in sorted(packages):
- s = package.dump(long=True)
- print(s)
+ # Print packages
+ self._print_packages(packages)
def _repolist(self, ns):
"""