Blob Blame History Raw
From a15ce85d03ba9babc2cbe100204c12f08500134c Mon Sep 17 00:00:00 2001
From: Richard Hughes <richard@hughsie.com>
Date: Wed, 5 Aug 2015 17:24:03 +0100
Subject: [PATCH] yum: Add support for GetDetailsLocal

Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1249998
---
 backends/yum/pk-backend-yum.c    | 15 +++++++++++++++
 backends/yum/yumBackend.py       | 29 +++++++++++++++++++++++++++--
 client/pk-console.c              | 10 ++++++++++
 lib/python/packagekit/backend.py | 11 +++++++++++
 4 files changed, 63 insertions(+), 2 deletions(-)

diff --git a/backends/yum/pk-backend-yum.c b/backends/yum/pk-backend-yum.c
index 5e9da25..c4b714f 100644
--- a/backends/yum/pk-backend-yum.c
+++ b/backends/yum/pk-backend-yum.c
@@ -355,6 +355,7 @@ pk_backend_get_roles (PkBackend *backend)
 		PK_ROLE_ENUM_CANCEL,
 		PK_ROLE_ENUM_DEPENDS_ON,
 		PK_ROLE_ENUM_GET_DETAILS,
+		PK_ROLE_ENUM_GET_DETAILS_LOCAL,
 		PK_ROLE_ENUM_GET_FILES,
 		PK_ROLE_ENUM_REQUIRED_BY,
 		PK_ROLE_ENUM_GET_PACKAGES,
@@ -450,6 +451,20 @@ pk_backend_get_details (PkBackend *backend, PkBackendJob *job, gchar **package_i
 }
 
 /**
+ * pk_backend_get_details_local:
+ */
+void
+pk_backend_get_details_local (PkBackend *backend, PkBackendJob *job, gchar **filenames)
+{
+	_cleanup_free_ gchar *tmp = NULL;
+	tmp = pk_package_ids_to_string (filenames);
+	pk_backend_spawn_helper (priv->spawn, job,
+				 "yumBackend.py",
+				 "get-details-local",
+				 tmp, NULL);
+}
+
+/**
  * pk_backend_get_distro_upgrades:
  */
 void
diff --git a/backends/yum/yumBackend.py b/backends/yum/yumBackend.py
index f097034..a0b2132 100755
--- a/backends/yum/yumBackend.py
+++ b/backends/yum/yumBackend.py
@@ -2476,7 +2476,32 @@ class PackageKitYumBackend(PackageKitBaseBackend, PackagekitPackage):
                     self.message('COULD_NOT_FIND_PACKAGE', 'Package %s was not found' % _format_package_id(package_id))
                     continue
 
-    def _show_details_pkg(self, pkg):
+    def get_details_local(self, files):
+        '''
+        Print a detailed details for a given file
+        '''
+        try:
+            self._check_init(lazy_cache=True)
+        except PkError, e:
+            self.error(e.code, e.details, exit=False)
+            return
+        self.yumbase.conf.cache = 0 # Allow new files
+        self.allow_cancel(True)
+        self.percentage(None)
+        self.status(STATUS_INFO)
+        for f in files:
+            try:
+                pkg = YumLocalPackage(ts=self.yumbase.rpmdb.readOnlyTS(), filename=f)
+            except PkError, e:
+                if e.code == ERROR_PACKAGE_NOT_FOUND:
+                    self.message('COULD_NOT_FIND_PACKAGE', e.details)
+                    continue
+                self.error(e.code, e.details, exit=True)
+                return
+            if pkg:
+                self._show_details_pkg(pkg, False)
+
+    def _show_details_pkg(self, pkg, verify_local=True):
 
         pkgver = _get_package_ver(pkg)
         package_id = self.get_package_id(pkg.name, pkgver, pkg.arch, pkg.repo)
@@ -2494,7 +2519,7 @@ class PackageKitYumBackend(PackageKitBaseBackend, PackagekitPackage):
 
         # if we are remote and in the cache, our size is zero
         size = pkg.size
-        if not pkg.repo.id.startswith('installed') and pkg.verifyLocalPkg():
+        if verify_local and not pkg.repo.id.startswith('installed') and pkg.verifyLocalPkg():
             size = 0
 
         group = self.comps.get_group(pkg.name)
diff --git a/client/pk-console.c b/client/pk-console.c
index 203458e..52bbb65 100644
--- a/client/pk-console.c
+++ b/client/pk-console.c
@@ -1282,6 +1282,16 @@ pk_console_get_details (PkConsoleCtx *ctx, gchar **packages, GError **error)
 	_cleanup_error_free_ GError *error_local = NULL;
 	_cleanup_strv_free_ gchar **package_ids = NULL;
 
+	/* local file */
+	if (g_file_test (packages[0], G_FILE_TEST_EXISTS)) {
+		pk_client_get_details_local_async (PK_CLIENT (ctx->task),
+						   packages,
+						   ctx->cancellable,
+						   pk_console_progress_cb, ctx,
+						   pk_console_finished_cb, ctx);
+		return TRUE;
+	}
+
 	package_ids = pk_console_resolve_packages (ctx, packages, &error_local);
 	if (package_ids == NULL) {
 		g_set_error (error,
diff --git a/lib/python/packagekit/backend.py b/lib/python/packagekit/backend.py
index 4b9eedc..9ff693d 100644
--- a/lib/python/packagekit/backend.py
+++ b/lib/python/packagekit/backend.py
@@ -467,6 +467,13 @@ class PackageKitBaseBackend:
         '''
         self.error(ERROR_NOT_SUPPORTED, "This function is not implemented in this backend", exit=False)
 
+    def get_details_local(self, files):
+        '''
+        Implement the {backend}-get-details-local functionality
+        Needed to be implemented in a sub class
+        '''
+        self.error(ERROR_NOT_SUPPORTED, "This function is not implemented in this backend", exit=False)
+
     def get_files(self, package_ids):
         '''
         Implement the {backend}-get-files functionality
@@ -581,6 +588,10 @@ class PackageKitBaseBackend:
             package_ids = args[0].split(PACKAGE_IDS_DELIM)
             self.get_details(package_ids)
             self.finished()
+        elif cmd == 'get-details-local':
+            files = args[0].split(PACKAGE_IDS_DELIM)
+            self.get_details_local(files)
+            self.finished()
         elif cmd == 'get-files':
             package_ids = args[0].split(PACKAGE_IDS_DELIM)
             self.get_files(package_ids)
-- 
2.4.3