Blob Blame History Raw
From eb2aa8c14208da7a567a0d79a8baa9f5201640cd Mon Sep 17 00:00:00 2001
From: Jaroslav Mracek <jmracek@redhat.com>
Date: Tue, 24 Nov 2020 09:17:41 +0100
Subject: [PATCH 1/3] Add `from_repo` attribute for Package class
 (RhBug:1898968,1879168)

It as an alias for private attribute _from_repo.

https://bugzilla.redhat.com/show_bug.cgi?id=1898968
https://bugzilla.redhat.com/show_bug.cgi?id=1879168
---
 dnf/cli/commands/repoquery.py | 2 +-
 dnf/package.py                | 7 +++++--
 doc/api_package.rst           | 6 ++++++
 3 files changed, 12 insertions(+), 3 deletions(-)

diff --git a/dnf/cli/commands/repoquery.py b/dnf/cli/commands/repoquery.py
index 099a9312d9..a11b440525 100644
--- a/dnf/cli/commands/repoquery.py
+++ b/dnf/cli/commands/repoquery.py
@@ -44,7 +44,7 @@
 QFORMAT_MATCH = re.compile(r'%(-?\d*?){([:.\w]+?)}')
 
 QUERY_TAGS = """\
-name, arch, epoch, version, release, reponame (repoid), evr,
+name, arch, epoch, version, release, reponame (repoid), from_repo, evr,
 debug_name, source_name, source_debug_name,
 installtime, buildtime, size, downloadsize, installsize,
 provides, requires, obsoletes, conflicts, sourcerpm,
diff --git a/dnf/package.py b/dnf/package.py
index d44ce6706c..f647df6bff 100644
--- a/dnf/package.py
+++ b/dnf/package.py
@@ -76,12 +76,15 @@ def _from_repo(self):
         pkgrepo = None
         if self._from_system:
             pkgrepo = self.base.history.repo(self)
-        else:
-            pkgrepo = {}
         if pkgrepo:
             return '@' + pkgrepo
         return self.reponame
 
+    @property
+    def from_repo(self):
+        # :api
+        return self._from_repo
+
     @property
     def _header(self):
         return dnf.rpm._header(self.localPkg())
diff --git a/doc/api_package.rst b/doc/api_package.rst
index 95df5d4b23..48ef8f1d22 100644
--- a/doc/api_package.rst
+++ b/doc/api_package.rst
@@ -74,6 +74,12 @@
 
     Files the package provides (list of strings).
 
+  .. attribute:: from_repo
+
+    For installed packages returns id of repository from which the package was installed prefixed
+    with '@' (if such information is available in the history database). Otherwise returns id of
+    repository the package belongs to (@System for installed packages of unknown origin) (string).
+
   .. attribute:: group
 
     Group of the package (string).

From 1a933f8e036cd704fa6e7f77a8448263e93e540f Mon Sep 17 00:00:00 2001
From: Jaroslav Mracek <jmracek@redhat.com>
Date: Tue, 24 Nov 2020 09:19:42 +0100
Subject: [PATCH 2/3] Correct description of Package().reponane attribute

---
 doc/api_package.rst | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/doc/api_package.rst b/doc/api_package.rst
index 48ef8f1d22..a78897babe 100644
--- a/doc/api_package.rst
+++ b/doc/api_package.rst
@@ -138,7 +138,7 @@
 
   .. attribute:: reponame
 
-    Id of repository the package was installed from (string).
+    Id of repository the package belongs to (@System for installed packages) (string).
 
   .. attribute:: requires
 

From 24cdb68776507fdae25bed0e82d80df3018aecfc Mon Sep 17 00:00:00 2001
From: Jaroslav Mracek <jmracek@redhat.com>
Date: Tue, 24 Nov 2020 09:22:07 +0100
Subject: [PATCH 3/3] Add unittest for new API

---
 tests/api/test_dnf_package.py | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/tests/api/test_dnf_package.py b/tests/api/test_dnf_package.py
index 04cddc7ecc..5952352bb5 100644
--- a/tests/api/test_dnf_package.py
+++ b/tests/api/test_dnf_package.py
@@ -163,6 +163,11 @@ def test_reponame(self):
         self.assertHasAttr(self.package, "reponame")
         self.assertHasType(self.package.reponame, str)
 
+    def test_from_repo(self):
+        # Package.reponame
+        self.assertHasAttr(self.package, "from_repo")
+        self.assertHasType(self.package.from_repo, str)
+
     def test_requires(self):
         # Package.requires
         self.assertHasAttr(self.package, "requires")