Blob Blame History Raw
From 524950fb6c647194ad9e0d3b7b2195d671424d1c Mon Sep 17 00:00:00 2001
From: Jaroslav Mracek <jmracek@redhat.com>
Date: Tue, 9 Apr 2019 20:54:12 +0200
Subject: [PATCH] Accept multiple specs in repoquery options (RhBug:1667898,1656801)

It allows with repoquery command to use --what* options multiple times
(append option) or add multiple arguments separated by comma.

https://bugzilla.redhat.com/show_bug.cgi?id=1667898
https://bugzilla.redhat.com/show_bug.cgi?id=1656801
---
 dnf.spec                      |  2 +-
 dnf/cli/commands/repoquery.py | 39 +++++++++++++++++++++++++--------------
 tests/test_repoquery.py       |  4 ++--
 3 files changed, 28 insertions(+), 17 deletions(-)

diff --git a/dnf.spec b/dnf.spec
index bbbe954..e3002db 100644
--- a/dnf.spec
+++ b/dnf.spec
@@ -1,5 +1,5 @@
 # default dependencies
-%global hawkey_version 0.35.1
+%global hawkey_version 0.35.2
 %global libcomps_version 0.1.8
 %global libmodulemd_version 1.4.0
 %global rpm_version 4.14.0
diff --git a/dnf/cli/commands/repoquery.py b/dnf/cli/commands/repoquery.py
index 0e5073f..c31501f 100644
--- a/dnf/cli/commands/repoquery.py
+++ b/dnf/cli/commands/repoquery.py
@@ -126,24 +126,33 @@ class RepoQueryCommand(commands.Command):
                             help=_('show only results from this ARCH'))
         parser.add_argument('-f', '--file', metavar='FILE', nargs='+',
                             help=_('show only results that owns FILE'))
-        parser.add_argument('--whatconflicts', metavar='REQ',
+        parser.add_argument('--whatconflicts', default=[], action=OptionParser._SplitCallback,
+                            metavar='REQ',
                             help=_('show only results that conflict REQ'))
-        parser.add_argument('--whatdepends', metavar='REQ',
+        parser.add_argument('--whatdepends', default=[], action=OptionParser._SplitCallback,
+                            metavar='REQ',
                             help=_('shows results that requires, suggests, supplements, enhances,'
                                    'or recommends package provides and files REQ'))
-        parser.add_argument('--whatobsoletes', metavar='REQ',
+        parser.add_argument('--whatobsoletes', default=[], action=OptionParser._SplitCallback,
+                            metavar='REQ',
                             help=_('show only results that obsolete REQ'))
-        parser.add_argument('--whatprovides', metavar='REQ',
+        parser.add_argument('--whatprovides', default=[], action=OptionParser._SplitCallback,
+                            metavar='REQ',
                             help=_('show only results that provide REQ'))
-        parser.add_argument('--whatrequires', metavar='REQ',
+        parser.add_argument('--whatrequires', default=[], action=OptionParser._SplitCallback,
+                            metavar='REQ',
                             help=_('shows results that requires package provides and files REQ'))
-        parser.add_argument('--whatrecommends', metavar='REQ',
+        parser.add_argument('--whatrecommends', default=[], action=OptionParser._SplitCallback,
+                            metavar='REQ',
                             help=_('show only results that recommend REQ'))
-        parser.add_argument('--whatenhances', metavar='REQ',
+        parser.add_argument('--whatenhances', default=[], action=OptionParser._SplitCallback,
+                            metavar='REQ',
                             help=_('show only results that enhance REQ'))
-        parser.add_argument('--whatsuggests', metavar='REQ',
+        parser.add_argument('--whatsuggests', default=[], action=OptionParser._SplitCallback,
+                            metavar='REQ',
                             help=_('show only results that suggest REQ'))
-        parser.add_argument('--whatsupplements', metavar='REQ',
+        parser.add_argument('--whatsupplements', default=[], action=OptionParser._SplitCallback,
+                            metavar='REQ',
                             help=_('show only results that supplement REQ'))
         whatrequiresform = parser.add_mutually_exclusive_group()
         whatrequiresform.add_argument("--alldeps", action="store_true",
@@ -354,10 +363,12 @@ class RepoQueryCommand(commands.Command):
         return t.union(done)
 
     def by_all_deps(self, requires_name, depends_name, query):
-        name = requires_name or depends_name
-        defaultquery = query.intersection(dnf.subject.Subject(name).get_best_query(
-            self.base.sack, with_provides=False, with_filenames=False))
-        requiresquery = query.filter(requires__glob=name)
+        names = requires_name or depends_name
+        defaultquery = self.base.sack.query().filter(empty=True)
+        for name in names:
+            defaultquery.union(query.intersection(dnf.subject.Subject(name).get_best_query(
+                self.base.sack, with_provides=False, with_filenames=False)))
+        requiresquery = query.filter(requires__glob=names)
         if depends_name:
             requiresquery = requiresquery.union(query.filter(recommends__glob=depends_name))
             requiresquery = requiresquery.union(query.filter(enhances__glob=depends_name))
@@ -446,7 +457,7 @@ class RepoQueryCommand(commands.Command):
         if self.opts.whatobsoletes:
             q.filterm(obsoletes=self.opts.whatobsoletes)
         if self.opts.whatprovides:
-            query_for_provide = q.filter(provides__glob=[self.opts.whatprovides])
+            query_for_provide = q.filter(provides__glob=self.opts.whatprovides)
             if query_for_provide:
                 q = query_for_provide
             else:
diff --git a/tests/test_repoquery.py b/tests/test_repoquery.py
index 9e6cc7d..9182537 100644
--- a/tests/test_repoquery.py
+++ b/tests/test_repoquery.py
@@ -78,8 +78,8 @@ class ArgParseTest(tests.support.TestCase):
 
     def test_parse(self):
         tests.support.command_configure(self.cmd, ['--whatrequires', 'prudence'])
-        self.assertIsNone(self.cmd.opts.whatprovides)
-        self.assertEqual(self.cmd.opts.whatrequires, 'prudence')
+        self.assertEqual(self.cmd.opts.whatprovides, [])
+        self.assertEqual(self.cmd.opts.whatrequires, ['prudence'])
         self.assertEqual(self.cmd.opts.queryformat,
                          dnf.cli.commands.repoquery.QFORMAT_DEFAULT)
 
--
libgit2 0.28.2