[packagekit] [PATCH 3 of 4] Add progress reporting to pisi backend

Ikey Doherty ikey at solusos.com
Sat Jun 8 05:56:01 PDT 2013


# HG changeset patch
# User Ikey Doherty <ikey at solusos.com>
# Date 1370690735 -3600
# Node ID 6924c435d4774792912d965c8690597614805f03
# Parent  fc4a918536a57ef67bc8cd756a09261157a1b291
Add progress reporting to pisi backend

diff --git a/backends/pisi/pisiBackend.py b/backends/pisi/pisiBackend.py
--- a/backends/pisi/pisiBackend.py
+++ b/backends/pisi/pisiBackend.py
@@ -20,11 +20,20 @@
 # Copyright (C) 2007 S.Çağlar Onur <caglar at pardus.org.tr>
 
 import pisi
+import pisi.ui
 from packagekit.backend import *
 from packagekit.package import PackagekitPackage
 from packagekit import enums
 import os.path
 
+class SimplePisiHandler(pisi.ui.UI):
+    
+    def __init(self):
+        pisi.ui.UI.__init__(self, False, False)
+        
+    def display_progress (self, **ka):
+        self.the_callback (**ka)
+
 class PackageKitPisiBackend(PackageKitBaseBackend, PackagekitPackage):
         
     MAPPING_FILE = "/etc/PackageKit/pisi.conf"
@@ -218,13 +227,21 @@
         # FIXME: use only_trusted
 
         package = self.get_package_from_id(package_ids[0])[0]
+        
+        def progress_cb (**kw):			
+            self.percentage (int(kw['percent']))
+            
+        ui = SimplePisiHandler ()
 
         if self.packagedb.has_package(package):
             self.status(STATUS_INSTALL)
+            pisi.api.set_userinterface (ui)
+            ui.the_callback = progress_cb
             try:
                 pisi.api.install([package])
             except pisi.Error,e:
                 self.error(ERROR_UNKNOWN, e)
+            pisi.api.set_userinterface (None)
         else:
             self.error(ERROR_PACKAGE_NOT_INSTALLED, "Package is already installed")
 
@@ -251,15 +268,23 @@
         self.percentage(None)
         # TODO: use autoremove
 
+        def progress_cb (**kw):			
+            self.percentage (int(kw['percent']))
+            
+        ui = SimplePisiHandler ()
+        
         package = self.get_package_from_id(package_ids[0])[0]
 
         if self.installdb.has_package(package):
             self.status(STATUS_REMOVE)
+            pisi.api.set_userinterface (ui)
+            ui.the_callback = progress_cb
             try:
                 pisi.api.remove([package])
             except pisi.Error,e:
                 # system.base packages cannot be removed from system
                 self.error(ERROR_CANNOT_REMOVE_SYSTEM_PACKAGE, e)
+            pisi.api.set_userinterface (None)
         else:
             self.error(ERROR_PACKAGE_NOT_INSTALLED, "Package is not installed")
 


More information about the PackageKit mailing list