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

Richard Hughes hughsient at kemper.freedesktop.org
Thu Feb 21 11:13:44 PST 2008


 NEWS                                    |   43 ++++++++
 backends/yum2/helpers/testyum2.py       |   85 ++++++++++-------
 backends/yum2/helpers/yumDBUSBackend.py |   83 ++++++++++++++++
 backends/zypp/pk-backend-zypp.cpp       |  157 ++++++++++++++++++++++++++++++--
 backends/zypp/zypp-utils.cpp            |   68 +++++++++++++
 backends/zypp/zypp-utils.h              |   15 +++
 docs/html/pk-download.html              |    1 
 7 files changed, 409 insertions(+), 43 deletions(-)

New commits:
commit a37a04b735ec95a1d54731afcd26c7213aa19fac
Author: Richard Hughes <richard at hughsie.com>
Date:   Thu Feb 21 19:13:01 2008 +0000

    release version 0.1.8

diff --git a/NEWS b/NEWS
index d26e153..6814a43 100644
--- a/NEWS
+++ b/NEWS
@@ -1,3 +1,46 @@
+Version 0.1.8
+~~~~~~~~~~~~~
+Released: 2008-02-21
+
+* Backends:
+ - apt: some random fixes to get it work again (Sebastian Heinlein)
+ - apt2: initial work on a dbus based backend introduced as apt2 (Sebastian Heinlein)
+ - apt2: implement GetDescription (Sebastian Heinlein)
+ - apt2: fix SearchName (Sebastian Heinlein)
+ - apt2: fix a typo in GetUpdates (Sebastian Heinlein)
+ - yum: check for missing package in GetUpdateDetail call (Robin Norwood)
+ - yum: change throttling policy: at init, change to 90%, throttle to 60% for UpdateSystem call (Robin Norwood)
+ - yum: Refresh the yum cache when it is determined to be invalid (Robin Norwood)
+ - yum: Make _refresh_yum_cache and RefreshCache work similarly (Robin Norwood)
+ - yum2: Added test script to call most of the YumBackend methods (Tim Lauridsen)
+ - yum2: Fixed unicode decode error in SearchDetails (Tim Lauridsen)
+ - yum2: add call to _check_init there check if Init() has been called (Tim Lauridsen)
+ - yum2: added GetPackages(filters) DBus method (Tim Lauridsen)
+ - zypp: libzypp >= 4.2.3 is now needed (Stefan Haas)
+ - zypp: Added SearchFiles (Stefan Haas)
+ - zypp: Added SearchDetails (Stefan Haas)
+ - zypp: Added GetRequires (Stefan Haas)
+ - zypp: added missing stuff of GetDescription (Stefan Haas)
+
+* New features:
+ - Allow pkcon to actually remove dependancies on user prompt (Richard Hughes)
+ - Add some FAQ text on user interaction during the transaction (Richard Hughes)
+ - Add the ServicePack functionality - no backends support it yet (Richard Hughes)
+ - Enforce that finished is sent 500ms after error_code (Richard Hughes)
+ - Add some more self checks to PkBackend (Richard Hughes)
+ - Add the supported filter to search for supported packages (Richard Hughes)
+
+* Bugfixes:
+ - Unload nicely on ctrl-c - including closing down the backends (Richard Hughes)
+ - Fix a tricky crash (use after unref) in pk_client_finished_cb (Richard Hughes)
+ - Use pk_client_set_synchronous() in pkcon to remove loads of code (Richard Hughes)
+ - Use $VAR$ syntax in makefiles, not @VAR@ (Stepan Kasal)
+ - Do not list check_PROGRAMS again in noinst_PROGRAMS (Stepan Kasal)
+ - Remove the dbus at_console rule for the backends (Richard Hughes)
+ - Try harder to get a translation when we have stored a base locale (Richard Hughes)
+ - Add finalizer for libgbus to free some memory on unload (Richard Hughes)
+ - Clear the hash when we reset PkClient, else we fail to show repeat search results (Richard Hughes)
+
 Version 0.1.7
 ~~~~~~~~~~~~~
 Released: 2008-02-14
diff --git a/docs/html/pk-download.html b/docs/html/pk-download.html
index d2e0581..84d87a3 100644
--- a/docs/html/pk-download.html
+++ b/docs/html/pk-download.html
@@ -56,6 +56,7 @@ Released versions are found on
 <tr><td>0.1.5</td><td></td><td>2007-12-21</td></tr>
 <tr><td>0.1.6</td><td></td><td>2008-01-18</td></tr>
 <tr><td>0.1.7</td><td></td><td>2008-02-14</td></tr>
+<tr><td>0.1.8</td><td></td><td>2008-02-21</td></tr>
 </table>
 
 <h2>Dependencies</h2>
commit 912fa246c0a7a8eded7a204a34eafc48ab29660b
Merge: 84d936e... 5ff74cd...
Author: Richard Hughes <richard at hughsie.com>
Date:   Thu Feb 21 17:07:04 2008 +0000

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

commit 5ff74cdd5dd8d32a6f9f95790e894e4a62c9d3c1
Author: Stefan Haas <shaas at suse.de>
Date:   Thu Feb 21 14:28:21 2008 +0100

    added search files

diff --git a/backends/zypp/pk-backend-zypp.cpp b/backends/zypp/pk-backend-zypp.cpp
index 80e5b84..c4d6d11 100644
--- a/backends/zypp/pk-backend-zypp.cpp
+++ b/backends/zypp/pk-backend-zypp.cpp
@@ -1056,6 +1056,9 @@ find_packages_real (PkBackend *backend, const gchar *search, const gchar *filter
                 case SEARCH_TYPE_DETAILS:
                         v = zypp_get_packages_by_details (search, TRUE);
                         break;      
+                case SEARCH_TYPE_FILE:
+                        v = zypp_get_packages_by_file (search);
+                        break;
         };
         
 	zypp_emit_packages_in_list (backend, v);
@@ -1149,6 +1152,16 @@ backend_search_details (PkBackend *backend, const gchar *filter, const gchar *se
 }
 
 /**
+ * backend_search_file:
+ */
+static void
+backend_search_file (PkBackend *backend, const gchar *filter, const gchar *search)
+{
+	g_return_if_fail (backend != NULL);
+	find_packages (backend, search, filter, SEARCH_TYPE_FILE);
+}
+
+/**
  * backend_get_repo_list:
  */
 static void
@@ -1341,24 +1354,12 @@ backend_get_requires_thread (PkBackendThread *thread, gpointer data) {
 	pk_backend_set_status (backend, PK_STATUS_ENUM_QUERY);
 	pk_backend_set_percentage (backend, 0);
         
-        //cleaning the pool
-        zypp::sat::Pool pool = zypp::sat::Pool::instance ();
+        zypp::ResPool pool = zypp_build_local_pool();        
 
-        for (zypp::sat::Pool::RepoIterator it = pool.reposBegin (); it != pool.reposEnd (); it++){
-              if (! pool.reposEmpty ())
-                      pool.reposErase(it->name ());
-        }
-        
-	pk_backend_set_percentage (backend, 20);
-
-        //Add local resolvables
-        zypp::ZYpp::Ptr zypp = get_zypp ();
-        zypp->target ()->load ();
-        
         zypp::PoolItem package;
         gboolean found = FALSE;
-        for (zypp::ResPool::byIdent_iterator it = zypp->pool ().byIdentBegin (zypp::ResKind::package, pi->name);
-                        it != zypp->pool ().byIdentEnd (zypp::ResKind::package, pi->name); it++) {
+        for (zypp::ResPool::byIdent_iterator it = pool.byIdentBegin (zypp::ResKind::package, pi->name);
+                        it != pool.byIdentEnd (zypp::ResKind::package, pi->name); it++) {
                 package = (*it);
                 found = TRUE;
         }
@@ -1378,7 +1379,7 @@ backend_get_requires_thread (PkBackendThread *thread, gpointer data) {
 	pk_backend_set_percentage (backend, 40);
 
         // solver run
-        zypp::Resolver solver(zypp->pool ());
+        zypp::Resolver solver(pool);
         
         // DEBUG https://bugzilla.novell.com/show_bug.cgi?id=363545
         if (solver.forceResolve () == FALSE) {
@@ -1399,8 +1400,8 @@ backend_get_requires_thread (PkBackendThread *thread, gpointer data) {
 	pk_backend_set_percentage (backend, 60);
 
         // look for packages which would be uninstalled
-        for (zypp::ResPool::byIdent_iterator it = zypp->pool ().byIdentBegin (zypp::ResKind::package, pi->name);
-                        it != zypp->pool ().byIdentEnd (zypp::ResKind::package, pi->name); it++) {
+        for (zypp::ResPool::byIdent_iterator it = pool.byIdentBegin (zypp::ResKind::package, pi->name);
+                        it != pool.byIdentEnd (zypp::ResKind::package, pi->name); it++) {
                 if (it->status () == zypp::ResStatus::toBeUninstalled || it->status () == zypp::ResStatus::toBeUninstalledSoft) {
                         gchar *package_id;
                         package_id = pk_package_id_build ( it->resolvable ()->name ().c_str(),
@@ -1461,7 +1462,7 @@ extern "C" PK_BACKEND_OPTIONS (
 	backend_resolve,			/* resolve */
 	NULL,					/* rollback */
 	backend_search_details,			/* search_details */
-	NULL,					/* search_file */
+	backend_search_file,			/* search_file */
 	NULL,					/* search_group */
 	backend_search_name,			/* search_name */
 	NULL,					/* update_package */
diff --git a/backends/zypp/zypp-utils.cpp b/backends/zypp/zypp-utils.cpp
index 0e5d500..179b5ec 100644
--- a/backends/zypp/zypp-utils.cpp
+++ b/backends/zypp/zypp-utils.cpp
@@ -18,6 +18,8 @@
 #include <zypp/Patch.h>
 #include <zypp/Package.h>
 #include <zypp/sat/Pool.h>
+#include <zypp/target/rpm/RpmDb.h>
+#include <zypp/target/rpm/RpmHeader.h>
 
 #include <pk-backend.h>
 
@@ -101,6 +103,24 @@ fprintf (stderr, "TODO: Handle exceptions: %s\n", ex.asUserString ().c_str ());
 	return zypp->pool ();
 }
 
+zypp::ResPool
+zypp_build_local_pool ()
+{
+        zypp::sat::Pool pool = zypp::sat::Pool::instance ();
+
+        for (zypp::sat::Pool::RepoIterator it = pool.reposBegin (); it != pool.reposEnd (); it++){
+                if (! pool.reposEmpty ())
+                        pool.reposErase(it->name ());
+        }
+
+        //Add local resolvables
+        zypp::ZYpp::Ptr zypp = get_zypp ();
+        zypp->target ()->load ();
+
+        return zypp->pool ();
+
+}
+
 std::vector<zypp::PoolItem> *
 zypp_get_packages_by_name (const gchar *package_name, gboolean include_local)
 {
@@ -135,6 +155,37 @@ zypp_get_packages_by_details (const gchar *search_term, gboolean include_local)
         return v;
 }
 
+std::vector<zypp::PoolItem> * 
+zypp_get_packages_by_file (const gchar *search_file)
+{
+        std::vector<zypp::PoolItem> *v = new std::vector<zypp::PoolItem> ();
+
+        zypp::ResPool pool = zypp_build_local_pool ();
+
+        std::string file (search_file);
+
+        zypp::ZYpp::Ptr zypp = get_zypp ();
+        zypp::Target_Ptr target = zypp->target ();
+
+        zypp::target::rpm::RpmDb &rpm = target->rpmDb ();
+        rpm.initDatabase ();
+        zypp::target::rpm::RpmHeader::constPtr rpmHeader;
+
+        for (zypp::ResPool::byKind_iterator it = pool.byKindBegin (zypp::ResKind::package);
+                        it != pool.byKindEnd (zypp::ResKind::package); it++) {
+                rpm.getData ((*it)->name (), (*it)->edition (), rpmHeader);
+                std::list<std::string> files = rpmHeader->tag_filenames ();
+
+                if (std::find(files.begin(), files.end(), file) != files.end()) {
+                        v->push_back (*it);
+                        break;
+                }
+
+        }
+
+        return v;
+}
+
 zypp::Resolvable::constPtr
 zypp_get_package_by_id (const gchar *package_id)
 {
diff --git a/backends/zypp/zypp-utils.h b/backends/zypp/zypp-utils.h
index d13885c..50ccf23 100644
--- a/backends/zypp/zypp-utils.h
+++ b/backends/zypp/zypp-utils.h
@@ -36,6 +36,11 @@ gboolean zypp_is_changeable_media (const zypp::Url &url);
 zypp::ResPool zypp_build_pool (gboolean include_local);
 
 /**
+ * Build and return a ResPool that contains only the local resolvables.
+ */
+zypp::ResPool zypp_build_local_pool ();
+
+/**
  * Returns a list of packages that match the specified package_name.
  */
 std::vector<zypp::PoolItem> * zypp_get_packages_by_name (const gchar *package_name, gboolean include_local);
@@ -46,6 +51,11 @@ std::vector<zypp::PoolItem> * zypp_get_packages_by_name (const gchar *package_na
 std::vector<zypp::PoolItem> * zypp_get_packages_by_details (const gchar *search_term, gboolean include_local);
 
 /**
+ * Returns a list of packages that owns the specified file.
+ */
+std::vector<zypp::PoolItem> * zypp_get_packages_by_file (const gchar *search_file);
+
+/**
  * Returns the Resolvable for the specified package_id.
  */
 zypp::Resolvable::constPtr zypp_get_package_by_id (const gchar *package_id);
commit c41298b7e719687f6eac2616b12a43d0fb2fdd1a
Author: Stefan Haas <shaas at suse.de>
Date:   Thu Feb 21 13:21:27 2008 +0100

    added search details

diff --git a/backends/zypp/pk-backend-zypp.cpp b/backends/zypp/pk-backend-zypp.cpp
index bc13b74..80e5b84 100644
--- a/backends/zypp/pk-backend-zypp.cpp
+++ b/backends/zypp/pk-backend-zypp.cpp
@@ -1046,14 +1046,20 @@ find_packages_real (PkBackend *backend, const gchar *search, const gchar *filter
 
 	pk_backend_no_percentage_updates (backend);
 
+        std::vector<zypp::PoolItem> *v = new std::vector<zypp::PoolItem>;
+
 	switch (mode) {
 		case SEARCH_TYPE_NAME:
-			std::vector<zypp::PoolItem> *v = zypp_get_packages_by_name (search, TRUE);
-			zypp_emit_packages_in_list (backend, v);
-			delete (v);
+			v = zypp_get_packages_by_name (search, TRUE);
 			break;
-	};
-
+	
+                case SEARCH_TYPE_DETAILS:
+                        v = zypp_get_packages_by_details (search, TRUE);
+                        break;      
+        };
+        
+	zypp_emit_packages_in_list (backend, v);
+	delete (v);
 /*
 	if (mode == SEARCH_TYPE_FILE) {
 		if (installed == FALSE && available == FALSE) {
@@ -1133,6 +1139,16 @@ backend_search_name (PkBackend *backend, const gchar *filter, const gchar *searc
 }
 
 /**
+ * backend_search_details:
+ */
+static void
+backend_search_details (PkBackend *backend, const gchar *filter, const gchar *search)
+{
+	g_return_if_fail (backend != NULL);
+	find_packages (backend, search, filter, SEARCH_TYPE_DETAILS);
+}
+
+/**
  * backend_get_repo_list:
  */
 static void
@@ -1444,7 +1460,7 @@ extern "C" PK_BACKEND_OPTIONS (
 	backend_remove_package,			/* remove_package */
 	backend_resolve,			/* resolve */
 	NULL,					/* rollback */
-	NULL,					/* search_details */
+	backend_search_details,			/* search_details */
 	NULL,					/* search_file */
 	NULL,					/* search_group */
 	backend_search_name,			/* search_name */
diff --git a/backends/zypp/zypp-utils.cpp b/backends/zypp/zypp-utils.cpp
index 281b386..0e5d500 100644
--- a/backends/zypp/zypp-utils.cpp
+++ b/backends/zypp/zypp-utils.cpp
@@ -118,6 +118,23 @@ zypp_get_packages_by_name (const gchar *package_name, gboolean include_local)
 	return v;
 }
 
+std::vector<zypp::PoolItem> *
+zypp_get_packages_by_details (const gchar *search_term, gboolean include_local)
+{
+        std::vector<zypp::PoolItem> *v = new std::vector<zypp::PoolItem> ();
+
+        zypp::ResPool pool = zypp_build_pool (include_local);
+
+        std::string term (search_term);
+        for (zypp::ResPool::byKind_iterator it = pool.byKindBegin (zypp::ResKind::package);
+                        it != pool.byKindEnd (zypp::ResKind::package); it++) {
+                if ((*it)->name ().find (term) != std::string::npos || (*it)->description ().find (term) != std::string::npos )
+                    v->push_back (*it);
+        }
+
+        return v;
+}
+
 zypp::Resolvable::constPtr
 zypp_get_package_by_id (const gchar *package_id)
 {
diff --git a/backends/zypp/zypp-utils.h b/backends/zypp/zypp-utils.h
index 7969cf5..d13885c 100644
--- a/backends/zypp/zypp-utils.h
+++ b/backends/zypp/zypp-utils.h
@@ -41,6 +41,11 @@ zypp::ResPool zypp_build_pool (gboolean include_local);
 std::vector<zypp::PoolItem> * zypp_get_packages_by_name (const gchar *package_name, gboolean include_local);
 
 /**
+ * Returns a list of packages that match the specified term in its name or description.
+ */
+std::vector<zypp::PoolItem> * zypp_get_packages_by_details (const gchar *search_term, gboolean include_local);
+
+/**
  * Returns the Resolvable for the specified package_id.
  */
 zypp::Resolvable::constPtr zypp_get_package_by_id (const gchar *package_id);
commit 1cfcd99c6253d3ae89f1aa6fde9a9cbbe0aca6f3
Author: Stefan Haas <shaas at suse.de>
Date:   Thu Feb 21 12:16:39 2008 +0100

    added get requires

diff --git a/backends/zypp/pk-backend-zypp.cpp b/backends/zypp/pk-backend-zypp.cpp
index 48e54d8..bc13b74 100644
--- a/backends/zypp/pk-backend-zypp.cpp
+++ b/backends/zypp/pk-backend-zypp.cpp
@@ -1300,6 +1300,130 @@ backend_get_files(PkBackend *backend, const gchar *package_id)
         }
 }
 
+/**
+  * backend_get_requires_thread:
+  */
+static gboolean
+backend_get_requires_thread (PkBackendThread *thread, gpointer data) {
+        
+        PkPackageId *pi;
+        PkBackend *backend;
+        
+        /* get current backend */
+        backend = pk_backend_thread_get_backend (thread);
+	ThreadData *d = (ThreadData*) data;
+
+	pi = pk_package_id_new_from_string (d->package_id);
+	if (pi == NULL) {
+		pk_backend_error_code (backend, PK_ERROR_ENUM_PACKAGE_ID_INVALID, "invalid package id");
+		pk_package_id_free (pi);
+		g_free (d->package_id);
+		g_free (d);
+		pk_backend_finished (backend);
+		return FALSE;
+	}
+	pk_backend_set_status (backend, PK_STATUS_ENUM_QUERY);
+	pk_backend_set_percentage (backend, 0);
+        
+        //cleaning the pool
+        zypp::sat::Pool pool = zypp::sat::Pool::instance ();
+
+        for (zypp::sat::Pool::RepoIterator it = pool.reposBegin (); it != pool.reposEnd (); it++){
+              if (! pool.reposEmpty ())
+                      pool.reposErase(it->name ());
+        }
+        
+	pk_backend_set_percentage (backend, 20);
+
+        //Add local resolvables
+        zypp::ZYpp::Ptr zypp = get_zypp ();
+        zypp->target ()->load ();
+        
+        zypp::PoolItem package;
+        gboolean found = FALSE;
+        for (zypp::ResPool::byIdent_iterator it = zypp->pool ().byIdentBegin (zypp::ResKind::package, pi->name);
+                        it != zypp->pool ().byIdentEnd (zypp::ResKind::package, pi->name); it++) {
+                package = (*it);
+                found = TRUE;
+        }
+
+	if (found == FALSE) {
+		pk_backend_error_code (backend, PK_ERROR_ENUM_PACKAGE_NOT_INSTALLED, "Package is not installed");
+		pk_package_id_free (pi);
+		g_free (d->package_id);
+		g_free (d);
+		pk_backend_finished (backend);
+		return FALSE;
+	}
+
+        // set Package as to be installed
+        package.status ().setToBeUninstalled (zypp::ResStatus::USER);
+
+	pk_backend_set_percentage (backend, 40);
+
+        // solver run
+        zypp::Resolver solver(zypp->pool ());
+        
+        // DEBUG https://bugzilla.novell.com/show_bug.cgi?id=363545
+        if (solver.forceResolve () == FALSE) {
+                std::list<zypp::ResolverProblem_Ptr> problems = solver.problems ();
+                if(problems.begin() == problems.end())
+                        fprintf(stderr,"\n_____________NO ERRORS AVAILABLE !?!?!_____________________\n");
+                for(std::list<zypp::ResolverProblem_Ptr>::iterator it = problems.begin (); it != problems.end (); it++){
+                    fprintf(stderr,"\n__ERROR: %s_______________________\n", (*it)->description ().c_str ());
+                }
+		pk_backend_error_code (backend, PK_ERROR_ENUM_DEP_RESOLUTION_FAILED, "Resolution failed");
+		pk_package_id_free (pi);
+		g_free (d->package_id);
+		g_free (d);
+		pk_backend_finished (backend);
+		return FALSE;
+	}
+
+	pk_backend_set_percentage (backend, 60);
+
+        // look for packages which would be uninstalled
+        for (zypp::ResPool::byIdent_iterator it = zypp->pool ().byIdentBegin (zypp::ResKind::package, pi->name);
+                        it != zypp->pool ().byIdentEnd (zypp::ResKind::package, pi->name); it++) {
+                if (it->status () == zypp::ResStatus::toBeUninstalled || it->status () == zypp::ResStatus::toBeUninstalledSoft) {
+                        gchar *package_id;
+                        package_id = pk_package_id_build ( it->resolvable ()->name ().c_str(),
+                                                           it->resolvable ()->edition ().asString ().c_str(),
+                                                           it->resolvable ()->arch ().c_str(),
+                                                           "opensuse");
+                        pk_backend_package (backend,
+			                    PK_INFO_ENUM_INSTALLED,
+			                    package_id,
+			                    it->resolvable ()->description ().c_str ());
+                        g_free (package_id);
+                }
+        }
+
+        pk_package_id_free (pi);
+	g_free (d->package_id);
+	g_free (d);
+	pk_backend_finished (backend);
+
+        return TRUE;
+}
+
+/**
+  * backend_get_requires:
+  */
+static void
+backend_get_requires(PkBackend *backend, const gchar *package_id, gboolean recursive) {
+        g_return_if_fail (backend != NULL);
+
+        ThreadData *data = g_new0(ThreadData, 1);
+        if (data == NULL) {
+                pk_backend_error_code(backend, PK_ERROR_ENUM_OOM, "Failed to allocate memory in backend_get_requires");
+                pk_backend_finished (backend);
+        } else {
+                data->package_id = g_strdup(package_id);
+                pk_backend_thread_create (thread, backend_get_requires_thread, data);
+        }
+}
+
 extern "C" PK_BACKEND_OPTIONS (
 	"Zypp",					/* description */
 	"Boyd Timothy <btimothy at gmail.com>, Scott Reeves <sreeves at novell.com>, Stefan Haas <shaas at suse.de>",	/* author */
@@ -1311,7 +1435,7 @@ extern "C" PK_BACKEND_OPTIONS (
 	backend_get_depends,			/* get_depends */
 	backend_get_description,		/* get_description */
 	backend_get_files,			/* get_files */
-	NULL,					/* get_requires */
+	backend_get_requires,			/* get_requires */
 	NULL,					/* get_update_detail */
 	backend_get_updates,			/* get_updates */
 	backend_install_package,		/* install_package */
commit 96ec82e08f52993c87cecd4389e294ded17942d9
Author: Tim Lauridsen <tim at naboo.local>
Date:   Thu Feb 21 11:15:32 2008 +0100

    yum2:
    	Fixed unicode decode error in SearchDetails (temporary fix, until fixed and released in upstream yum)
    	Make testyum2.py test a single or all methods based on argument.
    	  ex.
    	     sudo ./testyum2.py search-details   ( will test only the SearchDetails dbus method)

diff --git a/backends/yum2/helpers/testyum2.py b/backends/yum2/helpers/testyum2.py
index 05d9faa..15ec90a 100755
--- a/backends/yum2/helpers/testyum2.py
+++ b/backends/yum2/helpers/testyum2.py
@@ -37,43 +37,58 @@ except dbus.DBusException, e:
 try:
     proxy = bus.get_object(PACKAGEKIT_DBUS_SERVICE, PACKAGEKIT_DBUS_PATH)
     iface = dbus.Interface(proxy, PACKAGEKIT_DBUS_INTERFACE)
-    print "Testing Init()"
-    iface.Init()
-    print "Testing GetUpdate()"
-    iface.GetUpdates()
-    print "Testing SearchName(FILTER_NONE,'yum')"
-    iface.SearchName(FILTER_NONE,'yum')
-    # print "SearchDetails(FILTER_NONE,'dbus')"
-    # This one is failing because of some  UnicodeDecodeError in yum 
-    #iface.SearchDetails(FILTER_NONE,'DBus')
-    print "Testing SearchGroup(FILTER_NONE,GROUP_GAMES)"
-    iface.SearchGroup(FILTER_NONE,GROUP_GAMES)
-    print "Testing SearchFile(FILTER_NONE,'/usr/bin/yum')"
-    iface.SearchFile(FILTER_NONE,'/usr/bin/yum')
-    print "Testing GetRequires(PKG_ID,False)"
-    iface.GetRequires(PKG_ID,False)
-    print "Testing GetDepends(PKG_ID,False)"
-    iface.GetDepends(PKG_ID,False)
-    print "Testing RefreshCache()"
-    iface.RefreshCache()
-    print "Testing Resolve(FILTER_NONE,'yum')"
-    iface.Resolve(FILTER_NONE,'yum')
-    print "Testing GetDescription(PKG_ID)"
-    iface.GetDescription(PKG_ID)
-    print "Testing GetFiles(PKG_ID)"
-    iface.GetFiles(PKG_ID)
-    print "Testing GetPackages(FILTER_INSTALLED,'no')"
-    iface.GetPackages(FILTER_INSTALLED,'no')
-    print "Testing GetRepoList()"
-    iface.GetRepoList()
-    print "Testing GetUpdateDetail(PKG_ID)"
-    iface.GetUpdateDetail(PKG_ID)
+    cmd = sys.argv[1]
+    if cmd == 'init' or cmd == 'all':
+        print "Testing Init()"
+        iface.Init()
+    if cmd == 'get-updates' or cmd == 'all':
+        print "Testing GetUpdate()"
+        iface.GetUpdates()
+    if cmd == 'search-name' or cmd == 'all':
+        print "Testing SearchName(FILTER_NONE,'yum')"
+        iface.SearchName(FILTER_NONE,'yum')
+    if cmd == 'search-details' or cmd == 'all':
+        print "SearchDetails(FILTER_NONE,'dbus')"
+        # This one is failing because of some  UnicodeDecodeError in yum 
+        iface.SearchDetails(FILTER_NONE,'dbus')
+    if cmd == 'search-group' or cmd == 'all':
+        print "Testing SearchGroup(FILTER_NONE,GROUP_GAMES)"
+        iface.SearchGroup(FILTER_NONE,GROUP_GAMES)
+    if cmd == 'search-file' or cmd == 'all':
+        print "Testing SearchFile(FILTER_NONE,'/usr/bin/yum')"
+        iface.SearchFile(FILTER_NONE,'/usr/bin/yum')
+    if cmd == 'get-requires' or cmd == 'all':
+        print "Testing GetRequires(PKG_ID,False)"
+        iface.GetRequires(PKG_ID,False)
+    if cmd == 'get-depends' or cmd == 'all':
+        print "Testing GetDepends(PKG_ID,False)"
+        iface.GetDepends(PKG_ID,False)
+    if cmd == 'refresh-cache' or cmd == 'all':
+        print "Testing RefreshCache()"
+        iface.RefreshCache()
+    if cmd == 'resolve' or cmd == 'all':
+        print "Testing Resolve(FILTER_NONE,'yum')"
+        iface.Resolve(FILTER_NONE,'yum')
+    if cmd == 'get-description' or cmd == 'all':
+        print "Testing GetDescription(PKG_ID)"
+        iface.GetDescription(PKG_ID)
+    if cmd == 'get-files' or cmd == 'all':
+        print "Testing GetFiles(PKG_ID)"
+        iface.GetFiles(PKG_ID)
+    if cmd == 'get-packages' or cmd == 'all':
+        print "Testing GetPackages(FILTER_INSTALLED,'no')"
+        iface.GetPackages(FILTER_INSTALLED,'no')
+    if cmd == 'get-repolist' or cmd == 'all':
+        print "Testing GetRepoList()"
+        iface.GetRepoList()
+    if cmd == 'get-updatedetail' or cmd == 'all':
+        print "Testing GetUpdateDetail(PKG_ID)"
+        iface.GetUpdateDetail(PKG_ID)
     #print "Testing "
     #iface.
-    print "Testing RefreshCache()"
-    iface.RefreshCache()
-    print "Testing Exit()"
-    iface.Exit()
+    if cmd == 'exit' or cmd == 'all':
+        print "Testing Exit()"
+        iface.Exit()
     
 except dbus.DBusException, e:
     print "Unable to send message on dbus"
diff --git a/backends/yum2/helpers/yumDBUSBackend.py b/backends/yum2/helpers/yumDBUSBackend.py
index 2118011..1e268d0 100755
--- a/backends/yum2/helpers/yumDBUSBackend.py
+++ b/backends/yum2/helpers/yumDBUSBackend.py
@@ -51,6 +51,8 @@ import types
 import signal
 import time
 import os.path
+import operator
+
 
 # Global vars
 yumbase = None
@@ -1694,6 +1696,87 @@ class PackageKitYumBase(yum.YumBase):
         yum.YumBase.__init__(self)
         self.missingGPGKey = None
 
+    # Modified searchGenerator to make sure that
+    # non unicode strings read from rpmdb is converted to unicode
+    # FIXME: Remove this when fixed and released in upstream
+    def searchGenerator(self, fields, criteria, showdups=True):
+        """Generator method to lighten memory load for some searches.
+           This is the preferred search function to use."""
+        sql_fields = []
+        for f in fields:
+            if RPM_TO_SQLITE.has_key(f):
+                sql_fields.append(RPM_TO_SQLITE[f])
+            else:
+                sql_fields.append(f)
+
+        matched_values = {}
+
+        # yield the results in order of most terms matched first
+        sorted_lists = {}
+        tmpres = []
+        real_crit = []
+        for s in criteria:
+            if s.find('%') == -1:
+                real_crit.append(s)
+        real_crit_lower = [] # Take the s.lower()'s out of the loop
+        for s in criteria:
+            if s.find('%') == -1:
+                real_crit_lower.append(s.lower())
+
+        for sack in self.pkgSack.sacks.values():
+            tmpres.extend(sack.searchPrimaryFieldsMultipleStrings(sql_fields, real_crit))
+
+        for (po, count) in tmpres:
+            # check the pkg for sanity
+            # pop it into the sorted lists
+            tmpvalues = []
+            if count not in sorted_lists: sorted_lists[count] = []
+            for s in real_crit_lower:
+                for field in fields:
+                    value = getattr(po, field)
+                    if value and value.lower().find(s) != -1:
+                        tmpvalues.append(value)
+
+            if len(tmpvalues) > 0:
+                sorted_lists[count].append((po, tmpvalues))
+
+            
+        
+        for po in self.rpmdb:
+            tmpvalues = []
+            criteria_matched = 0
+            for s in real_crit_lower:
+                matched_s = False
+                for field in fields:
+                    value = getattr(po, field)
+                    # make sure that string are in unicode
+                    if isinstance(value, str):
+                        value = unicode(value,'unicode-escape')
+                    if value and value.lower().find(s) != -1:
+                        if not matched_s:
+                            criteria_matched += 1
+                            matched_s = True
+                        
+                        tmpvalues.append(value)
+
+
+            if len(tmpvalues) > 0:
+                if criteria_matched not in sorted_lists: sorted_lists[criteria_matched] = []
+                sorted_lists[criteria_matched].append((po, tmpvalues))
+                
+
+        # close our rpmdb connection so we can ctrl-c, kthxbai                    
+        self.closeRpmDB()
+        
+        yielded = {}
+        for val in reversed(sorted(sorted_lists)):
+            for (po, matched) in sorted(sorted_lists[val], key=operator.itemgetter(0)):
+                if (po.name, po.arch) not in yielded:
+                    yield (po, matched)
+                    if not showdups:
+                        yielded[(po.name, po.arch)] = 1
+
+
     def _checkSignatures(self,pkgs,callback):
         ''' The the signatures of the downloaded packages '''
         # This can be overloaded by a subclass.



More information about the PackageKit mailing list