[packagekit] packagekit: Branch 'master' - 4 commits

Richard Hughes hughsient at kemper.freedesktop.org
Tue Oct 23 14:11:34 PDT 2007


 backends/box/pk-backend-box.c        |    5 ++--
 backends/pisi/helpers/pisiBackend.py |   41 +++++++++++++++++++++++++----------
 libpackagekit/pk-enum.h              |    2 -
 src/pk-backend.c                     |    6 +++++
 src/pk-time.c                        |   13 ++++++-----
 5 files changed, 48 insertions(+), 19 deletions(-)

New commits:
commit 0a6535d05cf09d575f21befebdb1ba0e28065284
Author: S.Çağlar Onur <caglar at pardus.org.tr>
Date:   Tue Oct 23 23:50:48 2007 +0300

    Refactor a bit,
    Provide package update type,
    Use newly introduced ERROR_CANNOT_REMOVE_SYSTEM_PACKAGE instead of ERROR_INTERNAL_ERROR

diff --git a/backends/pisi/helpers/pisiBackend.py b/backends/pisi/helpers/pisiBackend.py
index 8c8f5ad..d5ebea1 100644
--- a/backends/pisi/helpers/pisiBackend.py
+++ b/backends/pisi/helpers/pisiBackend.py
@@ -22,6 +22,10 @@ import pisi
 from packagekit.backend import *
 
 class PackageKitPisiBackend(PackageKitBaseBackend):
+   
+    # Currently we only support i686
+    arch = "i686"
+
     def __init__(self, args):
         PackageKitBaseBackend.__init__(self, args)
 
@@ -30,6 +34,13 @@ class PackageKitPisiBackend(PackageKitBaseBackend):
         self.packagedb = pisi.db.packagedb.PackageDB()
         self.repodb = pisi.db.repodb.RepoDB()
 
+    def get_package_version(self, pkg):
+        if pkg.build is not None:
+            version = "%s-%s-%s" % (pkg.version, pkg.release, pkg.build)
+        else:
+            version = "%s-%s" % (pkg.version, pkg.release)
+        return version
+
     def resolve(self, filter, package_id):
         """ turns a single package name into a package_id suitable for the other methods. """
 
@@ -45,14 +56,9 @@ class PackageKitPisiBackend(PackageKitBaseBackend):
         else:
             self.error(ERROR_INTERNAL_ERROR, "Package was not found")
 
-        if pkg.build is not None:
-            version = "%s-%s-%s" % (pkg.version, pkg.release, pkg.build)
-        else:
-            version = "%s-%s" % (pkg.version, pkg.release)
+        version = self.get_package_version(pkg)
 
-        # Currently we only support i686
-        arch = "i686"
-        id = self.get_package_id(pkg.name, version, arch, "")
+        id = self.get_package_id(pkg.name, version, self.arch, "")
         self.package(id, status, pkg.summary)
 
     def remove(self, deps, package_id):
@@ -67,7 +73,7 @@ class PackageKitPisiBackend(PackageKitBaseBackend):
             try:
                 pisi.api.remove([package])
             except pisi.Error,e:
-                self.error(ERROR_INTERNAL_ERROR, e)
+                self.error(ERROR_CANNOT_REMOVE_SYSTEM_PACKAGE, e)
         else:
             self.error(ERROR_PACKAGE_NOT_INSTALLED, "Package is not installed")
 
@@ -103,17 +109,30 @@ class PackageKitPisiBackend(PackageKitBaseBackend):
             self.error(ERROR_PACKAGE_NOT_INSTALLED, "Package is already installed")
 
     def get_repo_list(self):
+        self.allow_interrupt(True);
+        self.percentage(None)
+
         for repo in pisi.api.list_repos():
             self.repo_detail(repo, self.repodb.get_repo(repo).indexuri.get_uri(), "true")
 
     def get_updates(self):
         for package in pisi.api.list_upgradable():
+
             pkg = self.installdb.get_package(package)
-            id = self.get_package_id(pkg.name, pkg.version, "", "")
-            # FIXME: type INFO_SECURITY or INFO_NORMAL
-            self.package(id, INFO_NORMAL, pkg.summary)
+
+            version = self.get_package_version(pkg)
+            id = self.get_package_id(pkg.name, version, self.arch, "")
+            
+            # Internal FIXME: PiSi must provide this information as a single API call :(
+            updates = [i for i in self.packagedb.get_package(package).history if pisi.version.Version(i.release) > pisi.version.Version(pkg.release)]
+            if pisi.util.any(lambda i:i.type == "security", updates):
+                self.package(id, INFO_SECURITY, pkg.summary)
+            else:
+                self.package(id, INFO_NORMAL, pkg.summary)
 
     def refresh_cache(self):
+        self.allow_interrupt(False);
+
         self.percentage(0)
 
         slice = (100/len(pisi.api.list_repos()))/2
commit 0ad01dfa95ab796c79341e10c34753c831a34bc4
Author: Grzegorz Dabrowski <gdx at o2.pl>
Date:   Tue Oct 23 19:26:24 2007 +0000

    fixed some build issues

diff --git a/backends/box/pk-backend-box.c b/backends/box/pk-backend-box.c
index 53e1d44..438ebe9 100644
--- a/backends/box/pk-backend-box.c
+++ b/backends/box/pk-backend-box.c
@@ -318,7 +318,7 @@ static gboolean
 backend_get_depends_requires_thread (PkBackend *backend, gpointer data)
 {
 	PkPackageId *pi;
-	GList *list;
+	GList *list = NULL;
 	ThreadData *d = (ThreadData*) data;
 	sqlite3 *db;
 
@@ -505,8 +505,9 @@ backend_refresh_cache (PkBackend *backend, gboolean force)
 static void
 backend_remove_package (PkBackend *backend, const gchar *package_id, gboolean allow_deps)
 {
-	g_return_if_fail (backend != NULL);
 	const gchar *deps;
+
+	g_return_if_fail (backend != NULL);
 	if (allow_deps == TRUE) {
 		deps = "yes";
 	} else {
diff --git a/libpackagekit/pk-enum.h b/libpackagekit/pk-enum.h
index d5273af..deb3289 100644
--- a/libpackagekit/pk-enum.h
+++ b/libpackagekit/pk-enum.h
@@ -138,7 +138,7 @@ typedef enum {
 	PK_UPDATE_ENUM_ALL,
 	PK_UPDATE_ENUM_SECURITY,
 	PK_UPDATE_ENUM_NONE,
-	PK_UPDATE_ENUM_UNKNOWN,
+	PK_UPDATE_ENUM_UNKNOWN
 } PkUpdateEnum;
 
 typedef enum {
commit a5cb81ec4e0fd06374b0259361373becb3660c6b
Author: Richard Hughes <richard at hughsie.com>
Date:   Tue Oct 23 15:28:08 2007 +0100

    try to guess the remaining time

diff --git a/src/pk-backend.c b/src/pk-backend.c
index 250aba2..bc49cb5 100644
--- a/src/pk-backend.c
+++ b/src/pk-backend.c
@@ -619,6 +619,8 @@ pk_backend_not_implemented_yet (PkBackend *backend, const gchar *method)
 gboolean
 pk_backend_change_percentage (PkBackend *backend, guint percentage)
 {
+	guint remaining;
+
 	g_return_val_if_fail (backend != NULL, FALSE);
 	g_return_val_if_fail (PK_IS_BACKEND (backend), FALSE);
 
@@ -628,6 +630,10 @@ pk_backend_change_percentage (PkBackend *backend, guint percentage)
 	/* needed for time remaining calculation */
 	pk_time_add_data (backend->priv->time, percentage);
 
+	/* TODO: lets try this */
+	remaining = pk_time_get_remaining (backend->priv->time);
+	pk_debug ("this will take ~%i seconds", remaining);
+
 	pk_debug ("emit percentage-changed %i", percentage);
 	g_signal_emit (backend, signals [PK_BACKEND_PERCENTAGE_CHANGED], 0, percentage);
 	return TRUE;
diff --git a/src/pk-time.c b/src/pk-time.c
index 615b356..0773754 100644
--- a/src/pk-time.c
+++ b/src/pk-time.c
@@ -50,7 +50,7 @@ static void     pk_time_finalize	(GObject     *object);
 #define PK_TIME_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), PK_TYPE_TIME, PkTimePrivate))
 #define PK_TIME_AVERAGE_MIN		2
 #define PK_TIME_AVERAGE_MAX		5
-#define PK_TIME_VALUE_MIN		5
+#define PK_TIME_VALUE_MIN		2
 #define PK_TIME_VALUE_MAX		60*60
 
 struct PkTimePrivate
commit 6b223451df21c10a412ea0468761dee65139aeca
Author: Richard Hughes <richard at hughsie.com>
Date:   Tue Oct 23 15:25:44 2007 +0100

    pk_time_get_remaining needs to return seconds, not ms

diff --git a/src/pk-time.c b/src/pk-time.c
index 2b525cf..615b356 100644
--- a/src/pk-time.c
+++ b/src/pk-time.c
@@ -50,8 +50,8 @@ static void     pk_time_finalize	(GObject     *object);
 #define PK_TIME_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), PK_TYPE_TIME, PkTimePrivate))
 #define PK_TIME_AVERAGE_MIN		2
 #define PK_TIME_AVERAGE_MAX		5
-#define PK_TIME_VALUE_MIN		5*1000
-#define PK_TIME_VALUE_MAX		60*60*1000
+#define PK_TIME_VALUE_MIN		5
+#define PK_TIME_VALUE_MAX		60*60
 
 struct PkTimePrivate
 {
@@ -86,7 +86,7 @@ pk_time_get_elapsed (PkTime *time)
 }
 
 /**
- * pk_time_get_remaining:
+ * pk_time_get_gradient:
  **/
 static gfloat
 pk_time_get_gradient (PkTimeItem *item1, PkTimeItem *item2)
@@ -100,6 +100,8 @@ pk_time_get_gradient (PkTimeItem *item1, PkTimeItem *item2)
 
 /**
  * pk_time_get_remaining:
+ *
+ * Returns time in seconds
  **/
 guint
 pk_time_get_remaining (PkTime *time)
@@ -162,7 +164,8 @@ pk_time_get_remaining (PkTime *time)
 	estimated = (gfloat) percentage_left / grad_ave;
 
 	/* turn to ms */
-	pk_debug ("estimated=%f", estimated);
+	estimated /= 1000;
+	pk_debug ("estimated=%f seconds", estimated);
 
 	if (estimated < PK_TIME_VALUE_MIN) {
 		estimated = 0;
@@ -338,7 +341,7 @@ libst_time (LibSelfTest *test)
 		value += 10;
 	}
 	value = pk_time_get_remaining (time);
-	if (value > 9500 && value < 10500) {
+	if (value > 9 && value < 11) {
 		libst_success (test, NULL);
 	} else {
 		libst_failed (test, "got %i, not ~10000ms", value);


More information about the PackageKit mailing list