richardphibel / rpms / dnf

Forked from rpms/dnf 2 years ago
Clone

Blame SOURCES/0011-Add-new-attribute-for-Package--from-repo.patch

4f4af9
From eb2aa8c14208da7a567a0d79a8baa9f5201640cd Mon Sep 17 00:00:00 2001
4f4af9
From: Jaroslav Mracek <jmracek@redhat.com>
4f4af9
Date: Tue, 24 Nov 2020 09:17:41 +0100
4f4af9
Subject: [PATCH 1/3] Add `from_repo` attribute for Package class
4f4af9
 (RhBug:1898968,1879168)
4f4af9
4f4af9
It as an alias for private attribute _from_repo.
4f4af9
4f4af9
https://bugzilla.redhat.com/show_bug.cgi?id=1898968
4f4af9
https://bugzilla.redhat.com/show_bug.cgi?id=1879168
4f4af9
---
4f4af9
 dnf/cli/commands/repoquery.py | 2 +-
4f4af9
 dnf/package.py                | 7 +++++--
4f4af9
 doc/api_package.rst           | 6 ++++++
4f4af9
 3 files changed, 12 insertions(+), 3 deletions(-)
4f4af9
4f4af9
diff --git a/dnf/cli/commands/repoquery.py b/dnf/cli/commands/repoquery.py
4f4af9
index 099a9312d9..a11b440525 100644
4f4af9
--- a/dnf/cli/commands/repoquery.py
4f4af9
+++ b/dnf/cli/commands/repoquery.py
4f4af9
@@ -44,7 +44,7 @@
4f4af9
 QFORMAT_MATCH = re.compile(r'%(-?\d*?){([:.\w]+?)}')
4f4af9
 
4f4af9
 QUERY_TAGS = """\
4f4af9
-name, arch, epoch, version, release, reponame (repoid), evr,
4f4af9
+name, arch, epoch, version, release, reponame (repoid), from_repo, evr,
4f4af9
 debug_name, source_name, source_debug_name,
4f4af9
 installtime, buildtime, size, downloadsize, installsize,
4f4af9
 provides, requires, obsoletes, conflicts, sourcerpm,
4f4af9
diff --git a/dnf/package.py b/dnf/package.py
4f4af9
index d44ce6706c..f647df6bff 100644
4f4af9
--- a/dnf/package.py
4f4af9
+++ b/dnf/package.py
4f4af9
@@ -76,12 +76,15 @@ def _from_repo(self):
4f4af9
         pkgrepo = None
4f4af9
         if self._from_system:
4f4af9
             pkgrepo = self.base.history.repo(self)
4f4af9
-        else:
4f4af9
-            pkgrepo = {}
4f4af9
         if pkgrepo:
4f4af9
             return '@' + pkgrepo
4f4af9
         return self.reponame
4f4af9
 
4f4af9
+    @property
4f4af9
+    def from_repo(self):
4f4af9
+        # :api
4f4af9
+        return self._from_repo
4f4af9
+
4f4af9
     @property
4f4af9
     def _header(self):
4f4af9
         return dnf.rpm._header(self.localPkg())
4f4af9
diff --git a/doc/api_package.rst b/doc/api_package.rst
4f4af9
index 95df5d4b23..48ef8f1d22 100644
4f4af9
--- a/doc/api_package.rst
4f4af9
+++ b/doc/api_package.rst
4f4af9
@@ -74,6 +74,12 @@
4f4af9
 
4f4af9
     Files the package provides (list of strings).
4f4af9
 
4f4af9
+  .. attribute:: from_repo
4f4af9
+
4f4af9
+    For installed packages returns id of repository from which the package was installed prefixed
4f4af9
+    with '@' (if such information is available in the history database). Otherwise returns id of
4f4af9
+    repository the package belongs to (@System for installed packages of unknown origin) (string).
4f4af9
+
4f4af9
   .. attribute:: group
4f4af9
 
4f4af9
     Group of the package (string).
4f4af9
4f4af9
From 1a933f8e036cd704fa6e7f77a8448263e93e540f Mon Sep 17 00:00:00 2001
4f4af9
From: Jaroslav Mracek <jmracek@redhat.com>
4f4af9
Date: Tue, 24 Nov 2020 09:19:42 +0100
4f4af9
Subject: [PATCH 2/3] Correct description of Package().reponane attribute
4f4af9
4f4af9
---
4f4af9
 doc/api_package.rst | 2 +-
4f4af9
 1 file changed, 1 insertion(+), 1 deletion(-)
4f4af9
4f4af9
diff --git a/doc/api_package.rst b/doc/api_package.rst
4f4af9
index 48ef8f1d22..a78897babe 100644
4f4af9
--- a/doc/api_package.rst
4f4af9
+++ b/doc/api_package.rst
4f4af9
@@ -138,7 +138,7 @@
4f4af9
 
4f4af9
   .. attribute:: reponame
4f4af9
 
4f4af9
-    Id of repository the package was installed from (string).
4f4af9
+    Id of repository the package belongs to (@System for installed packages) (string).
4f4af9
 
4f4af9
   .. attribute:: requires
4f4af9
 
4f4af9
4f4af9
From 24cdb68776507fdae25bed0e82d80df3018aecfc Mon Sep 17 00:00:00 2001
4f4af9
From: Jaroslav Mracek <jmracek@redhat.com>
4f4af9
Date: Tue, 24 Nov 2020 09:22:07 +0100
4f4af9
Subject: [PATCH 3/3] Add unittest for new API
4f4af9
4f4af9
---
4f4af9
 tests/api/test_dnf_package.py | 5 +++++
4f4af9
 1 file changed, 5 insertions(+)
4f4af9
4f4af9
diff --git a/tests/api/test_dnf_package.py b/tests/api/test_dnf_package.py
4f4af9
index 04cddc7ecc..5952352bb5 100644
4f4af9
--- a/tests/api/test_dnf_package.py
4f4af9
+++ b/tests/api/test_dnf_package.py
4f4af9
@@ -163,6 +163,11 @@ def test_reponame(self):
4f4af9
         self.assertHasAttr(self.package, "reponame")
4f4af9
         self.assertHasType(self.package.reponame, str)
4f4af9
 
4f4af9
+    def test_from_repo(self):
4f4af9
+        # Package.reponame
4f4af9
+        self.assertHasAttr(self.package, "from_repo")
4f4af9
+        self.assertHasType(self.package.from_repo, str)
4f4af9
+
4f4af9
     def test_requires(self):
4f4af9
         # Package.requires
4f4af9
         self.assertHasAttr(self.package, "requires")