chantra / rpms / dnf

Forked from rpms/dnf 2 years ago
Clone

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

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