[packagekit] [PATCH] Implement 'download-packages'

Ikey Doherty ikey at solusos.com
Sat Jun 8 09:18:30 PDT 2013


# HG changeset patch
# User Ikey Doherty <ikey at solusos.com>
# Date 1370708058 -3600
# Node ID 09d65a071a3f87af374d01f44804b1c1246c7d3f
# Parent  e879418c1a584364fe9f035dd17633bef4eb4ac6
Implement 'download-packages'

diff -r e879418c1a58 -r 09d65a071a3f backends/pisi/pisiBackend.py
--- a/backends/pisi/pisiBackend.py	Sat Jun 08 13:46:12 2013 +0100
+++ b/backends/pisi/pisiBackend.py	Sat Jun 08 17:14:18 2013 +0100
@@ -245,7 +245,43 @@
             self.update_detail(package_id, updates, obsoletes, vendor_url,
                 bugzilla_url, cve_url, "none", update_message, changelog,
                 state, issued, updated)
-    
+
+    def download_packages(self, directory, package_ids):
+        """ Download the given packages to a directory """
+        self.allow_cancel (False)
+        self.percentage (None)
+        self.status (STATUS_DOWNLOAD)
+        
+        packages = list()
+        
+        def progress_cb (**kw):
+            self.percentage (int(kw['percent']))
+            
+        ui = SimplePisiHandler ()
+        for package_id in package_ids:
+            package = self.get_package_from_id (package_id)[0]
+            packages.append (package)
+            try:
+                pkg = self.packagedb.get_package (package)
+            except:
+                self.error(ERROR_PACKAGE_NOT_FOUND, "Package was not found")
+        try:
+            pisi.api.set_userinterface (ui)
+            ui.the_callback = progress_cb
+            if directory is None:
+                directory = os.path.curdir
+            pisi.api.fetch (packages, directory)
+            # Scan for package
+            for package in packages:
+                package_obj = self.packagedb.get_package (package)
+                uri = package_obj.packageURI.split("/")[-1]
+                location = os.path.join (directory, uri)
+                self.files (package_id, location)
+            pisi.api.set_userinterface (None)
+        except Exception, e:
+            self.error(ERROR_PACKAGE_DOWNLOAD_FAILED, "Could not download package: %s" % e)
+        self.percentage (None)        
+            
     def install_files(self, only_trusted, files):
         """ Installs given package into system"""
 
diff -r e879418c1a58 -r 09d65a071a3f backends/pisi/pk-backend-pisi.c
--- a/backends/pisi/pk-backend-pisi.c	Sat Jun 08 13:46:12 2013 +0100
+++ b/backends/pisi/pk-backend-pisi.c	Sat Jun 08 17:14:18 2013 +0100
@@ -122,6 +122,20 @@
 }
 
 /**
+ * pk_backend_download_packages:
+ */
+void
+pk_backend_download_packages (PkBackend *backend, PkBackendJob *job, gchar **package_ids, const gchar *directory)
+{
+	gchar *package_ids_temp;
+
+	/* send the complete list as stdin */
+	package_ids_temp = pk_package_ids_to_string (package_ids);
+	pk_backend_spawn_helper (spawn, job, "pisiBackend.py", "download-packages", directory, package_ids_temp, NULL);
+	g_free (package_ids_temp);
+}
+
+/**
  * pk_backend_get_depends:
  */
 void


More information about the PackageKit mailing list