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

Richard Hughes hughsient at kemper.freedesktop.org
Sun Oct 21 15:15:33 PDT 2007


 backends/BACKENDS                      |    8 -
 backends/Makefile.am                   |    4 
 backends/dummy/pk-backend-dummy.c      |   20 ++++
 backends/smart/.gitignore              |    5 +
 backends/smart/Makefile.am             |    7 +
 backends/smart/helpers/.gitignore      |    1 
 backends/smart/helpers/Makefile.am     |   16 +++
 backends/smart/helpers/packagekit      |    1 
 backends/smart/helpers/remove.py       |   20 ++++
 backends/smart/helpers/resolve.py      |   19 ++++
 backends/smart/helpers/smartBackend.py |   70 ++++++++++++++++
 backends/smart/pk-backend-smart.c      |   83 +++++++++++++++++++
 client/pk-console.c                    |  144 ++++++++++++++++++++++++++++++++-
 configure.ac                           |    7 +
 data/tests/Makefile.am                 |    1 
 data/tests/pk-spawn-test-sigquit.sh    |   42 +++++++++
 data/tests/pk-spawn-test.sh            |    7 +
 html/pk-download.html                  |    1 
 html/upload.sh                         |   10 ++
 src/pk-backend.c                       |   10 +-
 src/pk-spawn.c                         |   67 +++++++++++----
 21 files changed, 512 insertions(+), 31 deletions(-)

New commits:
commit 3e44e7076feb2fbc4d1a19c07c287d52622e410d
Author: Richard Hughes <richard at hughsie.com>
Date:   Sun Oct 21 23:10:48 2007 +0100

    add a test for the SIGQUIT stuff

diff --git a/data/tests/Makefile.am b/data/tests/Makefile.am
index 22aaf57..a6bc194 100644
--- a/data/tests/Makefile.am
+++ b/data/tests/Makefile.am
@@ -5,6 +5,7 @@ NULL =
 
 TEST_FILES =						\
 	pk-spawn-test.sh				\
+	pk-spawn-test-sigquit.sh			\
 	$(NULL)
 
 EXTRA_DIST =						\
diff --git a/data/tests/pk-spawn-test-sigquit.sh b/data/tests/pk-spawn-test-sigquit.sh
new file mode 100755
index 0000000..c593d6d
--- /dev/null
+++ b/data/tests/pk-spawn-test-sigquit.sh
@@ -0,0 +1,42 @@
+#!/bin/bash
+# Copyright (C) 2007 Richard Hughes <richard at hughsie.com>
+# Licensed under the GNU General Public License Version 2
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+
+trap trap_quit QUIT
+
+trap_quit ()
+{
+	echo "Unlocking!"
+	exit;
+}
+
+time=0.30
+
+echo "Locking!"
+echo -e "percentage\t0" > /dev/stderr
+sleep ${time}
+echo -e "percentage\t10" > /dev/stderr
+sleep ${time}
+echo -e "percentage\t20" > /dev/stderr
+sleep ${time}
+echo -e "percentage\t30" > /dev/stderr
+sleep ${time}
+echo -e "percentage\t40" > /dev/stderr
+sleep ${time}
+echo -e "percentage\t50" > /dev/stderr
+sleep ${time}
+echo -e "percentage\t60" > /dev/stderr
+sleep ${time}
+echo -e "percentage\t70" > /dev/stderr
+sleep ${time}
+echo -e "percentage\t80" > /dev/stderr
+sleep ${time}
+echo -e "percentage\t90" > /dev/stderr
+sleep ${time}
+echo -e "percentage\t100" > /dev/stderr
+echo "Unlocking!"
+
diff --git a/data/tests/pk-spawn-test.sh b/data/tests/pk-spawn-test.sh
index 1c8fc4f..29561be 100755
--- a/data/tests/pk-spawn-test.sh
+++ b/data/tests/pk-spawn-test.sh
@@ -1,3 +1,10 @@
+#!/bin/bash
+# Copyright (C) 2007 Richard Hughes <richard at hughsie.com>
+# Licensed under the GNU General Public License Version 2
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
 
 time=0.30
 
diff --git a/src/pk-spawn.c b/src/pk-spawn.c
index 29c3206..bf559ab 100644
--- a/src/pk-spawn.c
+++ b/src/pk-spawn.c
@@ -494,10 +494,25 @@ cancel_cb (gpointer data)
 	return FALSE;
 }
 
+static void
+new_spawn_object (LibSelfTest *test, PkSpawn **pspawn)
+{
+	if (*pspawn != NULL) {
+		g_object_unref (*pspawn);
+	}
+	*pspawn = pk_spawn_new ();
+	g_signal_connect (*pspawn, "finished",
+			  G_CALLBACK (pk_test_finished_cb), test);
+	g_signal_connect (*pspawn, "stdout",
+			  G_CALLBACK (pk_test_stdout_cb), test);
+	g_signal_connect (*pspawn, "stderr",
+			  G_CALLBACK (pk_test_stderr_cb), test);
+}
+
 void
 libst_spawn (LibSelfTest *test)
 {
-	PkSpawn *spawn;
+	PkSpawn *spawn = NULL;
 	gboolean ret;
 	gchar *path;
 
@@ -505,19 +520,13 @@ libst_spawn (LibSelfTest *test)
 		return;
 	}
 
-	spawn = pk_spawn_new ();
-	g_signal_connect (spawn, "finished",
-			  G_CALLBACK (pk_test_finished_cb), test);
-	g_signal_connect (spawn, "stdout",
-			  G_CALLBACK (pk_test_stdout_cb), test);
-	g_signal_connect (spawn, "stderr",
-			  G_CALLBACK (pk_test_stderr_cb), test);
-
-	path = pk_test_get_data ("pk-spawn-test.sh");
+	/* get new object */
+	new_spawn_object (test, &spawn);
 
 	/************************************************************/
 	libst_title (test, "make sure return error for missing file");
 	mexit = BAD_EXIT;
+	path = pk_test_get_data ("pk-spawn-test.sh");
 	ret = pk_spawn_command (spawn, "pk-spawn-test-xxx.sh");
 	if (ret == FALSE) {
 		libst_success (test, "failed to run invalid file");
@@ -579,14 +588,8 @@ libst_spawn (LibSelfTest *test)
 		libst_failed (test, "wrong stderr count %i", stderr_count);
 	}
 
-	g_object_unref (spawn);
-	spawn = pk_spawn_new ();
-	g_signal_connect (spawn, "finished",
-			  G_CALLBACK (pk_test_finished_cb), test);
-	g_signal_connect (spawn, "stdout",
-			  G_CALLBACK (pk_test_stdout_cb), test);
-	g_signal_connect (spawn, "stderr",
-			  G_CALLBACK (pk_test_stderr_cb), test);
+	/* get new object */
+	new_spawn_object (test, &spawn);
 
 	/************************************************************/
 	libst_title (test, "make sure run correct helper, and kill it");
@@ -611,6 +614,34 @@ libst_spawn (LibSelfTest *test)
 		libst_failed (test, "finish %i!", mexit);
 	}
 
+	/* get new object */
+	new_spawn_object (test, &spawn);
+	g_free (path);
+
+	/************************************************************/
+	libst_title (test, "make sure run correct helper, and quit it");
+	mexit = BAD_EXIT;
+	path = pk_test_get_data ("pk-spawn-test-sigquit.sh");
+	ret = pk_spawn_command (spawn, path);
+	if (ret == TRUE) {
+		libst_success (test, NULL);
+	} else {
+		libst_failed (test, "did not run helper");
+	}
+
+	g_timeout_add_seconds (1, cancel_cb, spawn);
+	/* spin for a bit, todo add timer to break out if we fail */
+	loop = g_main_loop_new (NULL, FALSE);
+	g_main_loop_run (loop);
+
+	/************************************************************/
+	libst_title (test, "make sure finished in SIGQUIT");
+	if (mexit == PK_SPAWN_EXIT_QUIT) {
+		libst_success (test, NULL);
+	} else {
+		libst_failed (test, "finish %i!", mexit);
+	}
+
 	g_object_unref (spawn);
 	g_free (path);
 
commit 816a512be97e52696371d51938484bb7d99143d1
Author: Richard Hughes <richard at hughsie.com>
Date:   Sun Oct 21 22:55:46 2007 +0100

    add the upload script I use

diff --git a/html/upload.sh b/html/upload.sh
new file mode 100755
index 0000000..33efe23
--- /dev/null
+++ b/html/upload.sh
@@ -0,0 +1,10 @@
+USER="hughsie"
+SERVER="packagekit.org"
+LOCATION="/srv/www/html"
+
+scp img/*.png $USER@$SERVER:/$LOCATION/img/
+scp *.html $USER@$SERVER:/$LOCATION/
+scp *.css $USER@$SERVER:/$LOCATION/
+scp ../docs/pk-reference.html $USER@$SERVER:/$LOCATION/
+scp ../docs/pk-*.png $USER@$SERVER:/$LOCATION/
+
commit b1dff2756771a0a4cd89d0e7d81d45f67ea664a4
Merge: 1fa4d6f... 549a996...
Author: Richard Hughes <richard at hughsie.com>
Date:   Sun Oct 21 22:53:02 2007 +0100

    Merge branch 'master' of git+ssh://hughsie@git.packagekit.org/srv/git/PackageKit

commit 1fa4d6f51c2aceb383d67e8777c2213074e9da29
Author: Richard Hughes <richard at hughsie.com>
Date:   Sun Oct 21 22:52:46 2007 +0100

    more fixes to the progress bar code

diff --git a/backends/dummy/pk-backend-dummy.c b/backends/dummy/pk-backend-dummy.c
index 4d23f73..b85f650 100644
--- a/backends/dummy/pk-backend-dummy.c
+++ b/backends/dummy/pk-backend-dummy.c
@@ -166,6 +166,7 @@ backend_get_updates (PkBackend *backend)
 		return;
 	}
 
+	pk_backend_no_percentage_updates (backend);
 	pk_backend_package (backend, PK_INFO_ENUM_NORMAL,
 			    "powertop;1.8-1.fc8;i386;fedora",
 			    "Power consumption monitor");
@@ -239,13 +240,30 @@ backend_install_file (PkBackend *backend, const gchar *full_path)
 }
 
 /**
+ * backend_refresh_cache_timeout:
+ */
+static gboolean
+backend_refresh_cache_timeout (gpointer data)
+{
+	PkBackend *backend = (PkBackend *) data;
+	if (progress_percentage == 100) {
+		pk_backend_finished (backend);
+		return FALSE;
+	}
+	progress_percentage += 10;
+	pk_backend_change_percentage (backend, progress_percentage);
+	return TRUE;
+}
+
+/**
  * backend_refresh_cache:
  */
 static void
 backend_refresh_cache (PkBackend *backend, gboolean force)
 {
 	g_return_if_fail (backend != NULL);
-	pk_backend_finished (backend);
+	progress_percentage = 0;
+	g_timeout_add (500, backend_refresh_cache_timeout, backend);
 }
 
 /**
diff --git a/client/pk-console.c b/client/pk-console.c
index a3c378b..7aa7924 100644
--- a/client/pk-console.c
+++ b/client/pk-console.c
@@ -37,7 +37,10 @@
 #define PROGRESS_BAR_SIZE 60
 
 static GMainLoop *loop = NULL;
-static gboolean is_console;
+static gboolean is_console = FALSE;
+static gboolean has_output = FALSE;
+static gboolean printed_bar = FALSE;
+static guint timer_id = 0;
 
 typedef struct {
 	gint position;
@@ -88,6 +91,11 @@ pk_console_package_cb (PkClient *client, PkInfoEnum info, const gchar *package_i
 	gchar *info_text;
 	guint extra = 0;
 
+	/* if on console, clear the progress bar line */
+	if (is_console == TRUE && printed_bar == TRUE && has_output == FALSE) {
+		g_print ("\r");
+	}
+
 	/* pass this out */
 	info_text = pk_console_pad_string (pk_info_enum_to_text (info), 12, NULL);
 
@@ -109,6 +117,9 @@ pk_console_package_cb (PkClient *client, PkInfoEnum info, const gchar *package_i
 	g_free (info_text);
 	pk_package_id_free (ident);
 	pk_package_id_free (spacing);
+
+	/* don't do the percentage bar from now on */
+	has_output = TRUE;
 }
 
 /**
@@ -164,10 +175,13 @@ pk_console_repo_detail_cb (PkClient *client, const gchar *repo_id,
 static void
 pk_console_draw_progress_bar (guint percentage)
 {
-	int i;
-	guint progress = (int) (PROGRESS_BAR_SIZE * (float) (percentage) / 100 );
+	guint i;
+	guint progress = (gint) (PROGRESS_BAR_SIZE * (gfloat) (percentage) / 100);
 	guint remaining = PROGRESS_BAR_SIZE - progress;
 
+	/* we need to do an extra line */
+	printed_bar = TRUE;
+
 	g_print ("\r    [");
 	for (i = 0; i < progress; i++) {
 		g_print ("=");
@@ -194,11 +208,23 @@ pk_console_percentage_changed_cb (PkClient *client, guint percentage, gpointer d
 	}
 }
 
+/**
+ * pk_console_pulse_bar:
+ **/
 static gboolean
 pk_console_pulse_bar (PulseState *pulse_state)
 {
-	int i;
+	guint i;
 
+	/* don't spin if we have had output */
+	if (has_output == TRUE) {
+		return FALSE;
+	}
+
+	/* we need to do an extra line */
+	printed_bar = TRUE;
+
+	/* the clever pulse code */
 	printf("\r    [");
 	for (i = 0; i < pulse_state->position - 1; i++) {
 		g_print (".");
@@ -235,10 +261,11 @@ static void
 pk_console_no_percentage_updates_cb (PkClient *client, gpointer data)
 {
 	static PulseState pulse_state;
+	has_output = FALSE;
 	if (is_console == TRUE) {
 		pulse_state.position = 1;
 		pulse_state.move_forward = TRUE;
-		g_timeout_add (40, (GSourceFunc) pk_console_pulse_bar, &pulse_state);
+		timer_id = g_timeout_add (40, (GSourceFunc) pk_console_pulse_bar, &pulse_state);
 	}
 }
 
@@ -289,9 +316,14 @@ pk_console_finished_cb (PkClient *client, PkStatusEnum status, guint runtime, gp
 	PkRoleEnum role;
 	const gchar *role_text;
 
-	/* if on console, get off the progress bar line */
-	if (is_console == TRUE) {
-		g_print ("\n");
+	/* cancel the spinning */
+	if (timer_id != 0) {
+		g_source_remove (timer_id);
+	}
+
+	/* if on console, clear the progress bar line */
+	if (is_console == TRUE && printed_bar == TRUE && has_output == FALSE) {
+		g_print ("\r\r");
 	}
 
 	pk_client_get_role (client, &role, NULL);
@@ -563,8 +595,8 @@ pk_console_process_commands (PkClient *client, int argc, char *argv[], gboolean
 static void
 pk_console_error_code_cb (PkClient *client, PkErrorCodeEnum error_code, const gchar *details, gpointer data)
 {
-	/* if on console, get off the progress bar line */
-	if (is_console == TRUE) {
+	/* if on console, clear the progress bar line */
+	if (is_console == TRUE && printed_bar == TRUE) {
 		g_print ("\n");
 	}
 	g_print ("Error: %s : %s\n", pk_error_enum_to_text (error_code), details);
@@ -641,7 +673,6 @@ main (int argc, char *argv[])
 	g_type_init ();
 
 	/* check if we are on console */
-	is_console = FALSE;
 	if (isatty (fileno (stdout)) == 1) {
 		is_console = TRUE;
 	}
commit 549a996326624cd6178d5a8ed6f3da9d21056437
Author: James Bowes <jbowes at dangerouslyinc.com>
Date:   Sun Oct 21 17:35:38 2007 -0400

    Mention smart in the html pages

diff --git a/html/pk-download.html b/html/pk-download.html
index a1c8115..62006e4 100644
--- a/html/pk-download.html
+++ b/html/pk-download.html
@@ -96,6 +96,7 @@ For instance:
 <li>box (50% complete)</li>
 <li>apt (40% complete)</li>
 <li>pacman/alpm (10% complete)</li>
+<li>smart (10% complete)</li>
 </ul>
 
 <p>
commit 730c70b90b2a33497be8c689552bf6be015442b4
Author: James Bowes <jbowes at dangerouslyinc.com>
Date:   Sun Oct 21 17:28:57 2007 -0400

    Add smart status to backend checklist

diff --git a/backends/BACKENDS b/backends/BACKENDS
index 3e2b80a..43aba80 100644
--- a/backends/BACKENDS
+++ b/backends/BACKENDS
@@ -1,8 +1,8 @@
 Current status of the backends
 
-                  | conary | yum | apt | box | alpm |
------------------------------------------------------
-resolve           |        |  X  |     |  X  |      |
+                  | conary | yum | apt | box | alpm | smart |
+-------------------------------------------------------------
+resolve           |        |  X  |     |  X  |      |   X
 refresh-cache     |   X    |  X  |  X  |  X  |      |
 get-updates       |   X    |  X  |     |  X  |      |
 update-system     |   X    |  X  |     |  X  |      |
@@ -12,7 +12,7 @@ search-file       |        |  X  |     |  X  |      |
 search-group      |        |     |     |     |      |
 install-package   |   X    |  X  |     |  X  |  X   |
 install-file      |        |     |     |  X  |      |
-remove-package    |   X    |  X  |     |  X  |  X   |
+remove-package    |   X    |  X  |     |  X  |  X   |   X
 update-package    |        |     |     |  X  |      |
 get-depends       |        |  X  |     |  X  |      |
 get-requires      |   X    |     |     |  X  |      |
commit c31da0c3e58aede726c867ebe101ab741af17575
Author: James Bowes <jbowes at dangerouslyinc.com>
Date:   Sat Oct 20 23:24:14 2007 -0400

    Add initial layout for smart backend.

diff --git a/backends/Makefile.am b/backends/Makefile.am
index a5ff919..9420821 100644
--- a/backends/Makefile.am
+++ b/backends/Makefile.am
@@ -16,6 +16,10 @@ if BACKEND_TYPE_CONARY
 SUBDIRS += conary
 endif
 
+if BACKEND_TYPE_SMART
+SUBDIRS += smart
+endif
+
 if BACKEND_TYPE_YUM
 SUBDIRS += yum
 endif
diff --git a/backends/smart/.gitignore b/backends/smart/.gitignore
new file mode 100644
index 0000000..0c620eb
--- /dev/null
+++ b/backends/smart/.gitignore
@@ -0,0 +1,5 @@
+.deps
+.libs
+*.la
+*.lo
+*.o
diff --git a/backends/smart/Makefile.am b/backends/smart/Makefile.am
new file mode 100644
index 0000000..6fae321
--- /dev/null
+++ b/backends/smart/Makefile.am
@@ -0,0 +1,7 @@
+SUBDIRS = helpers
+plugindir = @PK_PLUGIN_DIR@
+plugin_LTLIBRARIES = libpk_backend_smart.la
+libpk_backend_smart_la_SOURCES = pk-backend-smart.c
+libpk_backend_smart_la_LIBADD = @PK_PLUGIN_LIBS@
+libpk_backend_smart_la_LDFLAGS = -module -avoid-version
+libpk_backend_smart_la_CFLAGS = @PK_PLUGIN_CFLAGS@
diff --git a/backends/smart/helpers/.gitignore b/backends/smart/helpers/.gitignore
new file mode 100644
index 0000000..0d20b64
--- /dev/null
+++ b/backends/smart/helpers/.gitignore
@@ -0,0 +1 @@
+*.pyc
diff --git a/backends/smart/helpers/Makefile.am b/backends/smart/helpers/Makefile.am
new file mode 100644
index 0000000..fceff8a
--- /dev/null
+++ b/backends/smart/helpers/Makefile.am
@@ -0,0 +1,16 @@
+
+helperdir = $(datadir)/PackageKit/helpers/smart
+
+NULL =
+
+dist_helper_DATA = 			\
+	remove.py			\
+	resolve.py			\
+	smartBackend.py			\
+	$(NULL)
+
+install-data-hook:
+	chmod a+rx $(DESTDIR)$(helperdir)/*.py
+
+clean-local :
+	rm -f *~
diff --git a/backends/smart/helpers/packagekit b/backends/smart/helpers/packagekit
new file mode 120000
index 0000000..8d22531
--- /dev/null
+++ b/backends/smart/helpers/packagekit
@@ -0,0 +1 @@
+../../../python/packagekit
\ No newline at end of file
diff --git a/backends/smart/helpers/remove.py b/backends/smart/helpers/remove.py
new file mode 100755
index 0000000..d212f47
--- /dev/null
+++ b/backends/smart/helpers/remove.py
@@ -0,0 +1,20 @@
+#!/usr/bin/python
+#
+# Copyright (C) 2007 Richard Hughes <richard at hughsie.com>
+# Copyright (C) 2007 James Bowes <jbowes at redhat.com>
+#
+# Licensed under the GNU General Public License Version 2
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+
+import sys
+import smartBackend
+
+
+backend = smartBackend.PackageKitSmartBackend(sys.argv[2:])
+backend.remove(sys.argv[1], sys.argv[2])
+
+sys.exit()
diff --git a/backends/smart/helpers/resolve.py b/backends/smart/helpers/resolve.py
new file mode 100755
index 0000000..fe2fff0
--- /dev/null
+++ b/backends/smart/helpers/resolve.py
@@ -0,0 +1,19 @@
+#!/usr/bin/python
+#
+# Copyright (C) 2007 Richard Hughes <richard at hughsie.com>
+# Copyright (C) 2007 James Bowes <jbowes at redhat.com>
+#
+# Licensed under the GNU General Public License Version 2
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+
+import sys
+import smartBackend
+
+backend = smartBackend.PackageKitSmartBackend(sys.argv[2:])
+backend.resolve(sys.argv[1], sys.argv[2])
+
+sys.exit()
diff --git a/backends/smart/helpers/smartBackend.py b/backends/smart/helpers/smartBackend.py
new file mode 100644
index 0000000..e3231c9
--- /dev/null
+++ b/backends/smart/helpers/smartBackend.py
@@ -0,0 +1,70 @@
+# Licensed under the GNU General Public License Version 2
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+# Copyright (C) 2007 James Bowes <jbowes at dangerouslyinc.com>
+
+import smart
+from packagekit.backend import PackageKitBaseBackend, INFO_INSTALLED, \
+        INFO_AVAILABLE
+
+class PackageKitSmartBackend(PackageKitBaseBackend):
+
+    def __init__(self, args):
+        PackageKitBaseBackend.__init__(self, args)
+
+        self.ctrl = smart.init()
+        self.ctrl.reloadChannels()
+        self.ctrl.getCache()
+
+    def remove(self, allowdeps, packageid):
+
+        idparts = packageid.split(';')
+        packagestring = "%s-%s@%s" % (idparts[0], idparts[1], idparts[2])
+        ratio, results, suggestions = self.ctrl.search(packagestring)
+
+        packages = []
+        for obj in results:
+            if isinstance(obj, smart.cache.Package):
+                packages.append(obj)
+
+        if not packages:
+            for obj in results:
+                for pkg in obj.packages:
+                    packages.append(pkg)
+
+        if len(packages) != 1:
+            return
+        package = packages[0]
+        trans = smart.transaction.Transaction(self.ctrl.getCache(),
+                smart.transaction.PolicyRemove)
+        trans.getPolicy()
+        trans.enqueue(package, smart.transaction.REMOVE)
+        trans.run()
+        self.ctrl.commitTransaction(trans, confirm=False)
+
+    def resolve(self, filters, packagename):
+        ratio, results, suggestions = self.ctrl.search(packagename)
+        for result in results:
+            self._show_package(result)
+
+    def _show_package(self, package):
+        if package.installed:
+            status = INFO_INSTALLED
+        else:
+            status = INFO_AVAILABLE
+        version, arch = package.version.split('@')
+        self.package(self.get_package_id(package.name, version, arch,
+            "installed"), status, None)
diff --git a/backends/smart/pk-backend-smart.c b/backends/smart/pk-backend-smart.c
new file mode 100644
index 0000000..7a97e0d
--- /dev/null
+++ b/backends/smart/pk-backend-smart.c
@@ -0,0 +1,83 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
+ *
+ * Copyright (C) 2007 Richard Hughes <richard at hughsie.com>
+ * Copyright (C) 2007 James Bowes <jbowes at redhat.com>
+ *
+ * Licensed under the GNU General Public License Version 2
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ */
+
+#include <gmodule.h>
+#include <glib.h>
+#include <string.h>
+#include <pk-backend.h>
+
+/**
+ * backend_remove_package:
+ */
+static void
+backend_remove_package (PkBackend *backend, const gchar *package_id, gboolean allow_deps)
+{
+	g_return_if_fail (backend != NULL);
+	const gchar *deps;
+	if (allow_deps == TRUE) {
+		deps = "yes";
+	} else {
+		deps = "no";
+	}
+	pk_backend_spawn_helper (backend, "remove.py", deps, package_id, NULL);
+}
+
+/**
+ * backend_resolve:
+ */
+static void
+backend_resolve (PkBackend *backend, const gchar *filter, const gchar *package_id)
+{
+	g_return_if_fail (backend != NULL);
+	pk_backend_spawn_helper (backend, "resolve.py", filter, package_id, NULL);
+}
+
+PK_BACKEND_OPTIONS (
+	"SMART",					/* description */
+	"0.0.1",					/* version */
+	"James Bowes <jbowes at dangerouslyinc.com>",	/* author */
+	NULL,						/* initalize */
+	NULL,						/* destroy */
+	NULL,						/* get_groups */
+	NULL,						/* get_filters */
+	NULL,						/* cancel */
+	NULL,						/* get_depends */
+	NULL,						/* get_description */
+	NULL,						/* get_requires */
+	NULL,						/* get_update_detail */
+	NULL,						/* get_updates */
+	NULL,						/* install_package */
+	NULL,						/* install_file */
+	NULL,						/* refresh_cache */
+	backend_remove_package,				/* remove_package */
+	backend_resolve,				/* resolve */
+	NULL,						/* rollback */
+	NULL,						/* search_details */
+	NULL,						/* search_file */
+	NULL,						/* search_group */
+	NULL,						/* search_name */
+	NULL,						/* update_package */
+	NULL,						/* update_system */
+	NULL,						/* get_repo_list */
+	NULL,						/* repo_enable */
+	NULL						/* repo_set_data */
+);
diff --git a/configure.ac b/configure.ac
index 8578cb7..6af5641 100644
--- a/configure.ac
+++ b/configure.ac
@@ -228,7 +228,7 @@ dnl - Compile time default choice of backend
 dnl ---------------------------------------------------------------------------
 AC_ARG_WITH([default_backend],
 	    AS_HELP_STRING([--with-default-backend=<option>],
-			   [Default backend to use alpm,apt,box,conary,dummy,yum (dummy)]))
+			   [Default backend to use alpm,apt,box,conary,dummy,smart,yum (dummy)]))
 # default to a sane option for the installed tool
 if test x$with_default_backend = x; then
 	if test -f /usr/bin/yum ; then
@@ -241,6 +241,8 @@ if test x$with_default_backend = x; then
 		with_default_backend=conary
 	elif test -f /usr/bin/box-repos ; then
 		with_default_backend=box
+	elif test -f /usr/bin/smart ; then
+		with_default_backend=smart
 	else
 		with_default_backend=dummy
 	fi
@@ -384,6 +386,7 @@ AM_CONDITIONAL(BACKEND_TYPE_YUM, [test x$with_default_backend = xyum], [using YU
 AM_CONDITIONAL(BACKEND_TYPE_CONARY, [test x$with_default_backend = xconary], [using CONARY backend])
 AM_CONDITIONAL(BACKEND_TYPE_BOX, [test x$with_default_backend = xbox], [using BOX backend])
 AM_CONDITIONAL(BACKEND_TYPE_ALPM, [test x$with_default_backend = xalpm], [using ALPM backend])
+AM_CONDITIONAL(BACKEND_TYPE_SMART, [test x$with_default_backend = xsmart], [using SMART backend])
 
 
 dnl ---------------------------------------------------------------------------
@@ -406,6 +409,8 @@ backends/box/helpers/Makefile
 backends/conary/Makefile
 backends/conary/helpers/Makefile
 backends/dummy/Makefile
+backends/smart/Makefile
+backends/smart/helpers/Makefile
 backends/test/Makefile
 backends/test/helpers/Makefile
 backends/yum/Makefile
commit 943b099e1e605bdd210e02ad3a460104a76b6f85
Author: Richard Hughes <richard at hughsie.com>
Date:   Sun Oct 21 21:56:41 2007 +0100

    stylistic changes to james' patch

diff --git a/client/pk-console.c b/client/pk-console.c
index cfb1d74..a3c378b 100644
--- a/client/pk-console.c
+++ b/client/pk-console.c
@@ -37,6 +37,12 @@
 #define PROGRESS_BAR_SIZE 60
 
 static GMainLoop *loop = NULL;
+static gboolean is_console;
+
+typedef struct {
+	gint position;
+	gboolean move_forward;
+} PulseState;
 
 /**
  * pk_console_pad_string:
@@ -181,21 +187,16 @@ pk_console_draw_progress_bar (guint percentage)
 static void
 pk_console_percentage_changed_cb (PkClient *client, guint percentage, gpointer data)
 {
-	if (isatty(fileno(stdout))) {
+	if (is_console == TRUE) {
 		pk_console_draw_progress_bar (percentage);
 	} else {
 		g_print ("%i%%\n", percentage);
 	}
 }
 
-typedef struct
-{
-	int position;
-	gboolean move_forward;
-} PulseState;
-
 static gboolean
-pk_console_pulse_bar (PulseState *pulse_state) {
+pk_console_pulse_bar (PulseState *pulse_state)
+{
 	int i;
 
 	printf("\r    [");
@@ -215,8 +216,7 @@ pk_console_pulse_bar (PulseState *pulse_state) {
 		} else {
 			pulse_state->position++;
 		}
-	}
-	else if (pulse_state->move_forward == FALSE) {
+	} else if (pulse_state->move_forward == FALSE) {
 		if (pulse_state->position == 1) {
 			pulse_state->move_forward = TRUE;
 			pulse_state->position++;
@@ -234,15 +234,11 @@ pk_console_pulse_bar (PulseState *pulse_state) {
 static void
 pk_console_no_percentage_updates_cb (PkClient *client, gpointer data)
 {
-	if (isatty(fileno(stdout))) {
-		PulseState *pulse_state;
-
-		/* FIXME: Free this. */
-		pulse_state = g_malloc (sizeof(PulseState));
-		pulse_state->position = 0;
-		pulse_state->move_forward = TRUE;
-
-		g_timeout_add(50, (GSourceFunc) pk_console_pulse_bar, pulse_state);
+	static PulseState pulse_state;
+	if (is_console == TRUE) {
+		pulse_state.position = 1;
+		pulse_state.move_forward = TRUE;
+		g_timeout_add (40, (GSourceFunc) pk_console_pulse_bar, &pulse_state);
 	}
 }
 
@@ -292,6 +288,12 @@ pk_console_finished_cb (PkClient *client, PkStatusEnum status, guint runtime, gp
 {
 	PkRoleEnum role;
 	const gchar *role_text;
+
+	/* if on console, get off the progress bar line */
+	if (is_console == TRUE) {
+		g_print ("\n");
+	}
+
 	pk_client_get_role (client, &role, NULL);
 	role_text = pk_role_enum_to_text (role);
 	g_print ("%s runtime was %i seconds\n", role_text, runtime);
@@ -561,8 +563,8 @@ pk_console_process_commands (PkClient *client, int argc, char *argv[], gboolean
 static void
 pk_console_error_code_cb (PkClient *client, PkErrorCodeEnum error_code, const gchar *details, gpointer data)
 {
-	/* We need to get off the progress bar line if this is a tty. */
-	if (isatty(fileno(stdout))) {
+	/* if on console, get off the progress bar line */
+	if (is_console == TRUE) {
 		g_print ("\n");
 	}
 	g_print ("Error: %s : %s\n", pk_error_enum_to_text (error_code), details);
@@ -638,6 +640,12 @@ main (int argc, char *argv[])
 	dbus_g_thread_init ();
 	g_type_init ();
 
+	/* check if we are on console */
+	is_console = FALSE;
+	if (isatty (fileno (stdout)) == 1) {
+		is_console = TRUE;
+	}
+
 	/* check dbus connections, exit if not valid */
 	system_connection = dbus_g_bus_get (DBUS_BUS_SYSTEM, &error);
 	if (error) {
commit e548c26461a930c28314abdf8f7b52792cca3ac2
Author: James Bowes <jbowes at dangerouslyinc.com>
Date:   Thu Oct 18 21:00:20 2007 -0400

    pkcon: Display a pulsing progress bar for no-progress-updates, too.

diff --git a/client/pk-console.c b/client/pk-console.c
index 91df860..cfb1d74 100644
--- a/client/pk-console.c
+++ b/client/pk-console.c
@@ -34,6 +34,8 @@
 #include <pk-package-id.h>
 #include <pk-enum-list.h>
 
+#define PROGRESS_BAR_SIZE 60
+
 static GMainLoop *loop = NULL;
 
 /**
@@ -157,9 +159,8 @@ static void
 pk_console_draw_progress_bar (guint percentage)
 {
 	int i;
-	guint bar_size = 60;
-	guint progress = (int) (bar_size * (float) (percentage) / 100 );
-	guint remaining = bar_size - progress;
+	guint progress = (int) (PROGRESS_BAR_SIZE * (float) (percentage) / 100 );
+	guint remaining = PROGRESS_BAR_SIZE - progress;
 
 	g_print ("\r    [");
 	for (i = 0; i < progress; i++) {
@@ -187,6 +188,64 @@ pk_console_percentage_changed_cb (PkClient *client, guint percentage, gpointer d
 	}
 }
 
+typedef struct
+{
+	int position;
+	gboolean move_forward;
+} PulseState;
+
+static gboolean
+pk_console_pulse_bar (PulseState *pulse_state) {
+	int i;
+
+	printf("\r    [");
+	for (i = 0; i < pulse_state->position - 1; i++) {
+		g_print (".");
+	}
+	printf("===");
+	for (i = pulse_state->position; i < PROGRESS_BAR_SIZE - 1; i++) {
+		g_print (".");
+	}
+	g_print ("]");
+
+	if (pulse_state->move_forward == TRUE) {
+		if (pulse_state->position == PROGRESS_BAR_SIZE - 1) {
+			pulse_state->move_forward = FALSE;
+			pulse_state->position--;
+		} else {
+			pulse_state->position++;
+		}
+	}
+	else if (pulse_state->move_forward == FALSE) {
+		if (pulse_state->position == 1) {
+			pulse_state->move_forward = TRUE;
+			pulse_state->position++;
+		} else {
+			pulse_state->position--;
+		}
+	}
+
+	return TRUE;
+}
+
+/**
+ * pk_console_no_percentage_updates_cb:
+ **/
+static void
+pk_console_no_percentage_updates_cb (PkClient *client, gpointer data)
+{
+	if (isatty(fileno(stdout))) {
+		PulseState *pulse_state;
+
+		/* FIXME: Free this. */
+		pulse_state = g_malloc (sizeof(PulseState));
+		pulse_state->position = 0;
+		pulse_state->move_forward = TRUE;
+
+		g_timeout_add(50, (GSourceFunc) pk_console_pulse_bar, pulse_state);
+	}
+}
+
 const gchar *summary =
 	"PackageKit Console Interface\n"
 	"\n"
@@ -623,6 +682,8 @@ main (int argc, char *argv[])
 			  G_CALLBACK (pk_console_repo_detail_cb), NULL);
 	g_signal_connect (client, "percentage-changed",
 			  G_CALLBACK (pk_console_percentage_changed_cb), NULL);
+	g_signal_connect (client, "no-percentage-updates",
+			  G_CALLBACK (pk_console_no_percentage_updates_cb), NULL);
 	g_signal_connect (client, "finished",
 			  G_CALLBACK (pk_console_finished_cb), NULL);
 	g_signal_connect (client, "error-code",
commit a4174a2e4dc5d48bae7e8ade8b64c07c4c780fc6
Author: James Bowes <jbowes at dangerouslyinc.com>
Date:   Tue Oct 16 19:08:29 2007 -0400

    pkcon: Add a fancy progress bar when we're on a tty,

diff --git a/client/pk-console.c b/client/pk-console.c
index 78d7281..91df860 100644
--- a/client/pk-console.c
+++ b/client/pk-console.c
@@ -24,6 +24,7 @@
 #include <string.h>
 #include <unistd.h>
 #include <stdlib.h>
+#include <stdio.h>
 #include <glib.h>
 #include <glib/gi18n.h>
 #include <dbus/dbus-glib.h>
@@ -150,12 +151,40 @@ pk_console_repo_detail_cb (PkClient *client, const gchar *repo_id,
 }
 
 /**
+ * pk_console_draw_progress_bar:
+ **/
+static void
+pk_console_draw_progress_bar (guint percentage)
+{
+	int i;
+	guint bar_size = 60;
+	guint progress = (int) (bar_size * (float) (percentage) / 100 );
+	guint remaining = bar_size - progress;
+
+	g_print ("\r    [");
+	for (i = 0; i < progress; i++) {
+		g_print ("=");
+	}
+	for (i = 0; i < remaining; i++) {
+		g_print (".");
+	}
+	g_print ("]  %3i%%", percentage);
+	if (percentage == 100) {
+		g_print ("\n");
+	}
+}
+
+/**
  * pk_console_percentage_changed_cb:
  **/
 static void
 pk_console_percentage_changed_cb (PkClient *client, guint percentage, gpointer data)
 {
-	g_print ("Percentage changed: %i%%\n", percentage);
+	if (isatty(fileno(stdout))) {
+		pk_console_draw_progress_bar (percentage);
+	} else {
+		g_print ("%i%%\n", percentage);
+	}
 }
 
 const gchar *summary =
@@ -473,6 +502,10 @@ pk_console_process_commands (PkClient *client, int argc, char *argv[], gboolean
 static void
 pk_console_error_code_cb (PkClient *client, PkErrorCodeEnum error_code, const gchar *details, gpointer data)
 {
+	/* We need to get off the progress bar line if this is a tty. */
+	if (isatty(fileno(stdout))) {
+		g_print ("\n");
+	}
 	g_print ("Error: %s : %s\n", pk_error_enum_to_text (error_code), details);
 }
 
commit f6da576a4d7c1b8df7f69382651a3c387bea7512
Author: James Bowes <jbowes at dangerouslyinc.com>
Date:   Tue Oct 16 19:35:13 2007 -0400

    pkcon: Add a --nowait option.

diff --git a/client/pk-console.c b/client/pk-console.c
index 0ad6739..78d7281 100644
--- a/client/pk-console.c
+++ b/client/pk-console.c
@@ -304,7 +304,7 @@ pk_console_remove_package (PkClient *client, const gchar *package)
  * pk_console_process_commands:
  **/
 static gboolean
-pk_console_process_commands (PkClient *client, int argc, char *argv[], GError **error)
+pk_console_process_commands (PkClient *client, int argc, char *argv[], gboolean wait_override, GError **error)
 {
 	const gchar *mode;
 	const gchar *value = NULL;
@@ -461,7 +461,7 @@ pk_console_process_commands (PkClient *client, int argc, char *argv[], GError **
 	}
 
 	/* only wait if success */
-	if (wait == TRUE) {
+	if (wait == TRUE && wait_override == TRUE) {
 		pk_client_wait ();
 	}
 	return TRUE;
@@ -526,6 +526,7 @@ main (int argc, char *argv[])
 	PkClient *client;
 	gboolean verbose = FALSE;
 	gboolean program_version = FALSE;
+	gboolean nowait = FALSE;
 	GOptionContext *context;
 	gchar *options_help;
 
@@ -534,6 +535,8 @@ main (int argc, char *argv[])
 			"Show extra debugging information", NULL },
 		{ "version", '\0', 0, G_OPTION_ARG_NONE, &program_version,
 			"Show the program version and exit", NULL},
+		{ "nowait", 'n', 0, G_OPTION_ARG_NONE, &nowait,
+			"Exit without waiting for actions to complete", NULL},
 		{ NULL}
 	};
 
@@ -593,7 +596,7 @@ main (int argc, char *argv[])
 			  G_CALLBACK (pk_console_error_code_cb), NULL);
 
 	/* run the commands */
-	pk_console_process_commands (client, argc, argv, &error);
+	pk_console_process_commands (client, argc, argv, !nowait, &error);
 	if (error != NULL) {
 		g_print ("Error:\n  %s\n\n", error->message);
 		g_error_free (error);
commit 8ba63bf2b4643cebee598676c288ea259a20e3cc
Author: Richard Hughes <richard at hughsie.com>
Date:   Sun Oct 21 18:34:07 2007 +0100

    if we have no package_id then try the search also for the feedback UI

diff --git a/src/pk-backend.c b/src/pk-backend.c
index 030ad93..171879e 100644
--- a/src/pk-backend.c
+++ b/src/pk-backend.c
@@ -893,7 +893,7 @@ pk_backend_get_status (PkBackend *backend, PkStatusEnum *status)
  * pk_backend_get_role:
  **/
 gboolean
-pk_backend_get_role (PkBackend *backend, PkRoleEnum *role, const gchar **package_id)
+pk_backend_get_role (PkBackend *backend, PkRoleEnum *role, const gchar **data)
 {
 	g_return_val_if_fail (backend != NULL, FALSE);
 	g_return_val_if_fail (PK_IS_BACKEND (backend), FALSE);
@@ -906,8 +906,12 @@ pk_backend_get_role (PkBackend *backend, PkRoleEnum *role, const gchar **package
 	if (role != NULL) {
 		*role = backend->priv->role;
 	}
-	if (package_id != NULL) {
-		*package_id = g_strdup (backend->priv->xcached_package_id);
+	if (data != NULL) {
+		if (backend->priv->xcached_package_id != NULL) {
+			*data = g_strdup (backend->priv->xcached_package_id);
+		} else if (backend->priv->xcached_search != NULL) {
+			*data = g_strdup (backend->priv->xcached_search);
+		}
 	}
 	return TRUE;
 }



More information about the PackageKit mailing list