[packagekit] packagekit: Branch 'master' - 22 commits
Richard Hughes
hughsient at kemper.freedesktop.org
Fri Sep 7 07:02:20 PDT 2007
TODO | 2
backends/apt/.gitignore | 10
backends/apt/Makefile.am | 14
backends/apt/pk-backend-apt.cpp | 71 +--
backends/apt/pk-task-apt.cpp.delete.me | 51 ++
backends/box/Makefile.am | 14
backends/box/pk-backend-box.c | 9
backends/conary/Makefile.am | 13
backends/conary/helpers/conaryBackend.py | 2
backends/dummy/Makefile.am | 13
backends/test/Makefile.am | 13
backends/yum/Makefile.am | 13
backends/yum/helpers/packagekit.py | 4
backends/yum/helpers/yumBackend.py | 2
libpackagekit/pk-task-client.c | 2
libpackagekit/pk-task-utils.c | 17
libpackagekit/pk-task-utils.h | 9
src/Makefile.am | 31 -
src/pk-backend-internal.h | 4
src/pk-backend.c | 109 ++++-
src/pk-engine.c | 66 +--
src/pk-task-box.c | 601 -----------------------------
src/pk-task-common.c | 639 -------------------------------
src/pk-task-common.h | 76 ---
src/pk-task-conary.c | 426 --------------------
src/pk-task-dummy.c | 456 ----------------------
src/pk-task-yum.c | 476 -----------------------
src/pk-task.h | 111 -----
tools/add-error-enum.sh | 2
29 files changed, 311 insertions(+), 2945 deletions(-)
New commits:
diff-tree 1a69fa9d9422c89f0767378cb1dedbd3626a85b8 (from efc3d6420184e0e424c89b9be8b8c26af6760732)
Author: Grzegorz Dabrowski <gdx at o2.pl>
Date: Fri Sep 7 08:00:16 2007 +0000
fixed building of box backend
diff --git a/backends/box/pk-backend-box.c b/backends/box/pk-backend-box.c
index c6c6e0d..62367d3 100644
--- a/backends/box/pk-backend-box.c
+++ b/backends/box/pk-backend-box.c
@@ -111,7 +111,7 @@ find_packages (PkBackend *backend, const
gboolean gui;
gboolean text;
- pk_task_set_job_role (task, PK_TASK_ROLE_QUERY, search);
+ pk_backend_change_job_status (backend, PK_TASK_ROLE_QUERY);
parse_filter (filter, &installed, &available, &devel, &nondevel, &gui, &text);
if (devel == TRUE) {
@@ -210,7 +210,7 @@ backend_get_description (PkBackend *back
}
- pk_backend_set_job_role (backend, PK_TASK_ROLE_QUERY, package_id);
+ pk_backend_change_job_status (backend, PK_TASK_ROLE_QUERY);
pk_backend_description (backend, pi->name, PK_TASK_GROUP_OTHER, ps->description, "");
pk_package_id_free (pi);
@@ -231,7 +231,6 @@ backend_get_updates (PkBackend *backend)
g_return_if_fail (backend != NULL);
- pk_backend_set_job_role (backend, PK_TASK_ROLE_QUERY, NULL);
pk_backend_change_job_status (backend, PK_TASK_STATUS_QUERY);
db = box_db_open ("/");
@@ -262,7 +261,7 @@ backend_refresh_cache (PkBackend *backen
pk_backend_finished (backend, PK_TASK_EXIT_FAILED);
return;
}
- pk_backend_set_job_role (backend, PK_TASK_ROLE_REFRESH_CACHE, NULL);
+ pk_backend_change_job_status (backend, PK_TASK_ROLE_REFRESH_CACHE);
pk_backend_spawn_helper (backend, "refresh-cache.sh", NULL);
}
@@ -287,7 +286,7 @@ backend_search_name (PkBackend *backend,
}
PK_BACKEND_OPTIONS (
- "Dummy Backend", /* description */
+ "Box Backend", /* description */
"0.0.1", /* version */
"Grzegorz DÄ
browski <gdx at o2.pl>", /* author */
backend_initalize, /* initalize */
diff-tree efc3d6420184e0e424c89b9be8b8c26af6760732 (from 0cdf9fea04bb1dc379a94a60e47b8366ffc101d8)
Author: Tom Parker <palfrey at tevp.net>
Date: Fri Sep 7 01:31:13 2007 +0200
Fix apt backend for new dlopen system
APT backend needed a few fixes for the new system, including marking the
exported structure as "extern C" in order to avoid the C++ name mangling
issues. There's a few things that still could be updated, but it at least
compiles and runs now.
diff --git a/backends/apt/Makefile.am b/backends/apt/Makefile.am
index 7eee77e..aab967b 100644
--- a/backends/apt/Makefile.am
+++ b/backends/apt/Makefile.am
@@ -4,5 +4,5 @@ libpk_backend_apt_la_INCLUDES = $(APT_CF
libpk_backend_apt_la_SOURCES = pk-backend-apt.cpp
libpk_backend_apt_la_LIBADD = @PK_PLUGIN_LIBS@ $(APT_LIBS)
libpk_backend_apt_la_LDFLAGS = -module -avoid-version
-libpk_backend_apt_la_CFLAGS = @PK_PLUGIN_CFLAGS@
+libpk_backend_apt_la_CXXFLAGS = @PK_PLUGIN_CFLAGS@
diff --git a/backends/apt/pk-backend-apt.cpp b/backends/apt/pk-backend-apt.cpp
index 68f7437..6bbf20d 100644
--- a/backends/apt/pk-backend-apt.cpp
+++ b/backends/apt/pk-backend-apt.cpp
@@ -23,6 +23,9 @@
#include <glib.h>
#include <string.h>
#include <pk-backend.h>
+#include <pk-debug.h>
+#include <pk-package-id.h>
+#include "config.h"
#include <apt-pkg/pkgcachegen.h>
#include <apt-pkg/pkgcache.h>
@@ -64,6 +67,14 @@ struct desc_task {
PkPackageId *pi;
};
+#ifdef APT_PKG_RPM
+typedef pkgCache::VerFile AptCompFile;
+#elif defined(APT_PKG_DEB)
+typedef pkgCache::DescFile AptCompFile;
+#else
+#error Need either rpm or deb defined
+#endif
+
struct ExDescFile {
AptCompFile *Df;
const char *verstr;
@@ -74,14 +85,6 @@ struct ExDescFile {
bool NameMatch;
};
-#ifdef APT_PKG_RPM
-typedef pkgCache::VerFile AptCompFile;
-#elif defined(APT_PKG_DEB)
-typedef pkgCache::DescFile AptCompFile;
-#else
-#error Need either rpm or deb defined
-#endif
-
static pkgCacheFile *getCache()
{
@@ -258,16 +261,16 @@ void *do_update_thread(gpointer data)
}
/**
- * pk_backend_refresh_cache:
+ * backend_refresh_cache:
**/
-gboolean pk_backend_refresh_cache(PkBackend * backend, gboolean force)
+static void backend_refresh_cache(PkBackend * backend, gboolean force)
{
/* check network state */
- if (pk_network_is_online(backend->priv->network) == FALSE)
+ if (pk_backend_network_is_online(backend) == FALSE)
{
pk_backend_error_code(backend, PK_TASK_ERROR_CODE_NO_NETWORK, "Cannot refresh cache whilst offline");
pk_backend_finished(backend, PK_TASK_EXIT_FAILED);
- return TRUE;
+ return;
}
UpdateData *data = g_new(UpdateData, 1);
@@ -285,7 +288,6 @@ gboolean pk_backend_refresh_cache(PkBack
pk_backend_finished(backend, PK_TASK_EXIT_FAILED);
}
}
- return TRUE;
}
// LocalitySort - Sort a version list by package file locality /*{{{*/
@@ -460,14 +462,6 @@ search_task_cleanup:
static gboolean
pk_backend_search(PkBackend * backend, const gchar * filter, const gchar * search, SearchDepth which)
{
-
- if (pk_backend_filter_check(filter) == FALSE)
- {
- pk_backend_error_code(backend, PK_TASK_ERROR_CODE_FILTER_INVALID, "filter '%s' not valid", filter);
- pk_backend_finished(backend, PK_TASK_EXIT_FAILED);
- return TRUE;
- }
-
search_task *data = g_new(struct search_task, 1);
if (data == NULL)
{
@@ -589,13 +583,13 @@ backend_get_description (PkBackend *back
desc_task *data = g_new(struct desc_task, 1);
if (data == NULL)
{
- pk_backend_error_code(backend, PK_TASK_ERROR_CODE_INTERNAL_OOM, "Failed to allocate memory for search task");
+ pk_backend_error_code(backend, PK_TASK_ERROR_CODE_OOM, "Failed to allocate memory for search task");
pk_backend_finished(backend, PK_TASK_EXIT_FAILED);
return;
}
data->backend = backend;
- data->pi = pk_package_id_new_from_string(package);
+ data->pi = pk_package_id_new_from_string(package_id);
if (data->pi == NULL)
{
pk_backend_error_code(backend, PK_TASK_ERROR_CODE_PACKAGE_ID_INVALID, "invalid package id");
@@ -612,15 +606,6 @@ backend_get_description (PkBackend *back
}
/**
- * backend_refresh_cache:
- */
-static void
-backend_refresh_cache (PkBackend *backend, gboolean force)
-{
- g_return_if_fail (backend != NULL);
-}
-
-/**
* backend_search_details:
*/
static void
@@ -637,10 +622,10 @@ static void
backend_search_name (PkBackend *backend, const gchar *filter, const gchar *search)
{
g_return_if_fail (backend != NULL);
- pk_backend_search(backend, filter, search, SEARCH_NAME);s
+ pk_backend_search(backend, filter, search, SEARCH_NAME);
}
-PK_BACKEND_OPTIONS (
+extern "C" PK_BACKEND_OPTIONS (
"APT Backend", /* description */
"0.0.1", /* version */
"Richard Hughes <richard at hughsie.com>", /* author */
diff-tree 0cdf9fea04bb1dc379a94a60e47b8366ffc101d8 (from 477d74ceaf85ec5deea2866ef6d81a2f399bf826)
Author: Tom Parker <palfrey at tevp.net>
Date: Wed Sep 5 13:59:51 2007 +0200
Add partial implementation of search file to apt
This is only a partial implementation of the search
file for apt (which will return an INTERNAL_ERROR when run)
which is being committed now to avoid issues with the imminent
re-arrangement of the backends.
diff --git a/backends/apt/pk-task-apt.cpp.delete.me b/backends/apt/pk-task-apt.cpp.delete.me
index 4a9f5ed..28946d5 100644
--- a/backends/apt/pk-task-apt.cpp.delete.me
+++ b/backends/apt/pk-task-apt.cpp.delete.me
@@ -382,7 +382,7 @@ static void LocalitySort(AptCompFile **b
qsort(begin,Count,Size,LocalityCompare);
}
-typedef enum {SEARCH_NAME=1, SEARCH_DETAILS} SearchDepth;
+typedef enum {SEARCH_NAME=1, SEARCH_DETAILS, SEARCH_FILE} SearchDepth;
struct search_task
{
@@ -600,12 +600,59 @@ gboolean pk_task_search_group(PkTask * t
return TRUE;
}
+void *do_search_file(gpointer data)
+{
+ search_task *st = (search_task*)data;
+ gchar *sdir = g_path_get_dirname(_config->Find("Dir::State::status").c_str());
+ gchar *ldir = g_build_filename(sdir,"info",NULL);
+ g_free(sdir);
+ GError *error = NULL;
+ GDir *list = g_dir_open(ldir,0,&error);
+ if (error!=NULL)
+ {
+ pk_task_error_code(st->task, PK_TASK_ERROR_CODE_INTERNAL_ERROR, "can't open %s",ldir);
+ g_free(ldir);
+ g_error_free(error);
+ pk_task_finished(st->task, PK_TASK_EXIT_FAILED);
+ return NULL;
+ }
+ const gchar * fname = NULL;
+ while ((fname = g_dir_read_name(list))!=NULL)
+ {
+ //pk_task_package(st->task, J->installed, pid, P.ShortDesc().c_str());
+ }
+ pk_task_error_code(st->task, PK_TASK_ERROR_CODE_INTERNAL_ERROR, "search file is incomplete");
+ pk_task_finished(st->task, PK_TASK_EXIT_FAILED);
+ g_dir_close(ldir);
+ g_free(ldir);
+ //pk_task_finished(st->task, PK_TASK_EXIT_SUCCESS);
+ return NULL;
+}
+
/**
* pk_task_search_file:
**/
gboolean pk_task_search_file(PkTask * task, const gchar * filter, const gchar * search)
{
- pk_task_not_implemented_yet(task, "SearchFile");
+ search_task *data = g_new(struct search_task, 1);
+ if (data == NULL)
+ {
+ pk_task_error_code(task, PK_TASK_ERROR_CODE_UNKNOWN, "can't allocate memory for search task");
+ pk_task_finished(task, PK_TASK_EXIT_FAILED);
+ }
+ else
+ {
+ data->task = task;
+ data->search = g_strdup(search);
+ data->filter = g_strdup(filter);
+ data->depth = SEARCH_FILE;
+
+ if (g_thread_create(do_search_file, data, false, NULL) == NULL)
+ {
+ pk_task_error_code(task, PK_TASK_ERROR_CODE_INTERNAL_ERROR, "can't spawn thread");
+ pk_task_finished(task, PK_TASK_EXIT_FAILED);
+ }
+ }
return TRUE;
}
diff-tree 477d74ceaf85ec5deea2866ef6d81a2f399bf826 (from 7db38bce418f35d60a96d733ebf9e009f0377f43)
Author: Richard Hughes <richard at hughsie.com>
Date: Thu Sep 6 23:15:23 2007 +0100
remove some ranomd debug text
diff --git a/src/pk-backend.c b/src/pk-backend.c
index 0fc5bc6..20e0790 100644
--- a/src/pk-backend.c
+++ b/src/pk-backend.c
@@ -472,8 +472,6 @@ pk_backend_set_job_role (PkBackend *back
g_return_val_if_fail (backend != NULL, FALSE);
g_return_val_if_fail (PK_IS_BACKEND (backend), FALSE);
- pk_debug ("TRYING to setting role to %s (string is '%s')", pk_task_role_to_text (role), package_id);
-
/* Should only be called once... */
if (backend->priv->role != PK_TASK_ROLE_UNKNOWN) {
pk_error ("cannot set role more than once, already %s",
diff-tree 7db38bce418f35d60a96d733ebf9e009f0377f43 (from 96d7f7152261efa439b92ef96107402fa9ca4da9)
Author: Richard Hughes <richard at hughsie.com>
Date: Thu Sep 6 22:48:09 2007 +0100
add some error enums
diff --git a/TODO b/TODO
index 973f032..55ef718 100644
--- a/TODO
+++ b/TODO
@@ -22,8 +22,6 @@ string updates
string obsoletes
string update_text
}
-* Switch to dlopened backends and remove bodge of pk-task-common.*
-* add errors OutOfMemory, CannotCreateThread
* Remove the _TASK_ in the enums
Backends:
diff --git a/backends/apt/pk-backend-apt.cpp b/backends/apt/pk-backend-apt.cpp
index 35d3311..68f7437 100644
--- a/backends/apt/pk-backend-apt.cpp
+++ b/backends/apt/pk-backend-apt.cpp
@@ -191,14 +191,14 @@ void *do_update_thread(gpointer data)
// Populate it with the source selection
if (List.GetIndexes(&Fetcher) == false)
{
- pk_backend_error_code(ud->backend, PK_TASK_ERROR_CODE_UNKNOWN, "Generic Error");
+ pk_backend_error_code(ud->backend, PK_TASK_ERROR_CODE_UNKNOWN, "Failed to populate the source selection");
goto do_update_clean;
}
// Run it
if (Fetcher.Run() == pkgAcquire::Failed)
{
- pk_backend_error_code(ud->backend, PK_TASK_ERROR_CODE_UNKNOWN, "Generic Error");
+ pk_backend_error_code(ud->backend, PK_TASK_ERROR_CODE_UNKNOWN, "Failed to run the fetcher");
goto do_update_clean;
}
@@ -226,7 +226,7 @@ void *do_update_thread(gpointer data)
if (Fetcher.Clean(_config->FindDir("Dir::State::lists")) == false ||
Fetcher.Clean(_config->FindDir("Dir::State::lists") + "partial/") == false)
{
- pk_backend_error_code(ud->backend, PK_TASK_ERROR_CODE_UNKNOWN, "Generic Error");
+ pk_backend_error_code(ud->backend, PK_TASK_ERROR_CODE_UNKNOWN, "Failed to clean out any old list files");
goto do_update_clean;
}
}
@@ -235,7 +235,7 @@ void *do_update_thread(gpointer data)
Cache = getCache();
if (Cache->BuildCaches(Prog,false) == false)
{
- pk_backend_error_code(ud->backend, PK_TASK_ERROR_CODE_UNKNOWN, "Generic Error");
+ pk_backend_error_code(ud->backend, PK_TASK_ERROR_CODE_UNKNOWN, "Failed to prepare the cache");
goto do_update_clean;
}
@@ -273,7 +273,7 @@ gboolean pk_backend_refresh_cache(PkBack
UpdateData *data = g_new(UpdateData, 1);
if (data == NULL)
{
- pk_backend_error_code(backend, PK_TASK_ERROR_CODE_UNKNOWN, "can't allocate memory for update task");
+ pk_backend_error_code(backend, PK_TASK_ERROR_CODE_OOM, "Failed to allocate memory for update task");
pk_backend_finished(backend, PK_TASK_EXIT_FAILED);
}
else
@@ -281,7 +281,7 @@ gboolean pk_backend_refresh_cache(PkBack
data->backend = backend;
if (g_thread_create(do_update_thread, data, false, NULL) == NULL)
{
- pk_backend_error_code(backend, PK_TASK_ERROR_CODE_UNKNOWN, "can't spawn update thread");
+ pk_backend_error_code(backend, PK_TASK_ERROR_CODE_CREATE_THREAD_FAILED, "Failed to create update thread");
pk_backend_finished(backend, PK_TASK_EXIT_FAILED);
}
}
@@ -471,7 +471,7 @@ pk_backend_search(PkBackend * backend, c
search_task *data = g_new(struct search_task, 1);
if (data == NULL)
{
- pk_backend_error_code(backend, PK_TASK_ERROR_CODE_UNKNOWN, "can't allocate memory for search task");
+ pk_backend_error_code(backend, PK_TASK_ERROR_CODE_OOM, "Failed to allocate memory for search task");
pk_backend_finished(backend, PK_TASK_EXIT_FAILED);
}
else
@@ -483,7 +483,7 @@ pk_backend_search(PkBackend * backend, c
if (g_thread_create(get_search_thread, data, false, NULL) == NULL)
{
- pk_backend_error_code(backend, PK_TASK_ERROR_CODE_UNKNOWN, "can't spawn thread");
+ pk_backend_error_code(backend, PK_TASK_ERROR_CODE_UNKNOWN, "Failed to spawn thread");
pk_backend_finished(backend, PK_TASK_EXIT_FAILED);
}
}
@@ -589,7 +589,7 @@ backend_get_description (PkBackend *back
desc_task *data = g_new(struct desc_task, 1);
if (data == NULL)
{
- pk_backend_error_code(backend, PK_TASK_ERROR_CODE_INTERNAL_ERROR, "can't allocate memory for search task");
+ pk_backend_error_code(backend, PK_TASK_ERROR_CODE_INTERNAL_OOM, "Failed to allocate memory for search task");
pk_backend_finished(backend, PK_TASK_EXIT_FAILED);
return;
}
@@ -605,7 +605,7 @@ backend_get_description (PkBackend *back
if (g_thread_create(get_description_thread, data, false, NULL) == NULL)
{
- pk_backend_error_code(backend, PK_TASK_ERROR_CODE_INTERNAL_ERROR, "can't spawn thread");
+ pk_backend_error_code(backend, PK_TASK_ERROR_CODE_CREATE_THREAD_FAILED, "Failed to spawn description thread");
pk_backend_finished(backend, PK_TASK_EXIT_FAILED);
}
return;
diff --git a/backends/conary/helpers/conaryBackend.py b/backends/conary/helpers/conaryBackend.py
index e78169d..19d03b4 100644
--- a/backends/conary/helpers/conaryBackend.py
+++ b/backends/conary/helpers/conaryBackend.py
@@ -128,7 +128,7 @@ class PackageKitConaryBackend(PackageKit
id = self.get_package_id(name, version, flavor, fullVersion)
self.package(id, installed, summary)
except:
- self.error('internal-error', 'An internal error has occurred')
+ self.error(ERROR_INTERNAL_ERROR, 'An internal error has occurred')
def check_installed(self, troveTuple):
db = conaryclient.ConaryClient(self.cfg).db
diff --git a/backends/yum/helpers/packagekit.py b/backends/yum/helpers/packagekit.py
index 710bdd2..deab15d 100644
--- a/backends/yum/helpers/packagekit.py
+++ b/backends/yum/helpers/packagekit.py
@@ -24,6 +24,7 @@ import sys
# Constants
+ERROR_OOM = "out-of-memory"
ERROR_NO_NETWORK = "no-network"
ERROR_NOT_SUPPORTED = "not-supported"
ERROR_INTERNAL_ERROR = "internal-error"
@@ -32,6 +33,9 @@ ERROR_PACKAGE_NOT_INSTALLED = "package-n
ERROR_PACKAGE_ALREADY_INSTALLED = "package-already-installed"
ERROR_PACKAGE_DOWNLOAD_FAILED = "package-download-failed"
ERROR_DEP_RESOLUTION_FAILED = "dep-resolution-failed"
+ERROR_CREATE_THREAD_FAILED = "create-thread-failed"
+ERROR_FILTER_INVALID = "filter-invalid"
+ERROR_TRANSACTION_ERROR = "transaction-error"
STATE_DOWNLOAD = "download"
STATE_INSTALL = "install"
diff --git a/backends/yum/helpers/yumBackend.py b/backends/yum/helpers/yumBackend.py
index b1e5b98..ea670fa 100644
--- a/backends/yum/helpers/yumBackend.py
+++ b/backends/yum/helpers/yumBackend.py
@@ -331,7 +331,7 @@ class PackageKitYumBackend(PackageKitBas
self.error(ERROR_INTERNAL_ERROR,retmsg)
except yum.Errors.YumBaseError, msgs:
retmsg = "Error in Transaction Processing;" +";".join(msgs)
- self.error(ERROR_INTERNAL_ERROR,retmsg)
+ self.error(ERROR_TRANSACTION_ERROR,retmsg)
def remove(self, allowdep, package):
'''
diff --git a/libpackagekit/pk-task-utils.c b/libpackagekit/pk-task-utils.c
index 0caddc4..efddcfc 100644
--- a/libpackagekit/pk-task-utils.c
+++ b/libpackagekit/pk-task-utils.c
@@ -68,16 +68,19 @@ static PkTaskEnumMatch task_role[] = {
static PkTaskEnumMatch task_error[] = {
{PK_TASK_ERROR_CODE_UNKNOWN, "unknown"}, /* fall though value */
+ {PK_TASK_ERROR_CODE_OOM, "out-of-memory"},
{PK_TASK_ERROR_CODE_NO_NETWORK, "no-network"},
{PK_TASK_ERROR_CODE_NOT_SUPPORTED, "not-supported"},
{PK_TASK_ERROR_CODE_INTERNAL_ERROR, "internal-error"},
{PK_TASK_ERROR_CODE_GPG_FAILURE, "gpg-failure"},
{PK_TASK_ERROR_CODE_FILTER_INVALID, "filter-invalid"},
{PK_TASK_ERROR_CODE_PACKAGE_ID_INVALID, "package-id-invalid"},
+ {PK_TASK_ERROR_CODE_TRANSACTION_ERROR, "transaction-error"},
{PK_TASK_ERROR_CODE_PACKAGE_NOT_INSTALLED, "package-not-installed"},
{PK_TASK_ERROR_CODE_PACKAGE_ALREADY_INSTALLED, "package-already-installed"},
{PK_TASK_ERROR_CODE_PACKAGE_DOWNLOAD_FAILED, "package-download-failed"},
{PK_TASK_ERROR_CODE_DEP_RESOLUTION_FAILED, "dep-resolution-failed"},
+ {PK_TASK_ERROR_CODE_CREATE_THREAD_FAILED, "create-thread-failed"},
{0, NULL},
};
diff --git a/libpackagekit/pk-task-utils.h b/libpackagekit/pk-task-utils.h
index 37e12fc..f90dff0 100644
--- a/libpackagekit/pk-task-utils.h
+++ b/libpackagekit/pk-task-utils.h
@@ -65,6 +65,7 @@ typedef enum {
} PkTaskRestart;
typedef enum {
+ PK_TASK_ERROR_CODE_OOM,
PK_TASK_ERROR_CODE_NO_NETWORK,
PK_TASK_ERROR_CODE_NOT_SUPPORTED,
PK_TASK_ERROR_CODE_INTERNAL_ERROR,
@@ -75,6 +76,8 @@ typedef enum {
PK_TASK_ERROR_CODE_PACKAGE_DOWNLOAD_FAILED,
PK_TASK_ERROR_CODE_DEP_RESOLUTION_FAILED,
PK_TASK_ERROR_CODE_FILTER_INVALID,
+ PK_TASK_ERROR_CODE_CREATE_THREAD_FAILED,
+ PK_TASK_ERROR_CODE_TRANSACTION_ERROR,
PK_TASK_ERROR_CODE_UNKNOWN
} PkTaskErrorCode;
diff --git a/tools/add-error-enum.sh b/tools/add-error-enum.sh
index eb5ee0a..c30ccd9 100755
--- a/tools/add-error-enum.sh
+++ b/tools/add-error-enum.sh
@@ -1,4 +1,4 @@
#!/bin/sh
-$EDITOR helpers/README libpackagekit/pk-task-utils.h libpackagekit/pk-task-utils.c ../gnome-packagekit/src/pk-common.c
+$EDITOR backends/README libpackagekit/pk-task-utils.h libpackagekit/pk-task-utils.c ../gnome-packagekit/src/pk-common.c backends/yum/helpers/packagekit.py
diff-tree 96d7f7152261efa439b92ef96107402fa9ca4da9 (from 58785ab0eb9c850db7fb89f1ad6c08d65dd35e03)
Author: Richard Hughes <richard at hughsie.com>
Date: Thu Sep 6 22:20:07 2007 +0100
remove warning text
diff --git a/libpackagekit/pk-task-client.c b/libpackagekit/pk-task-client.c
index 77f8f4d..21e5f8a 100644
--- a/libpackagekit/pk-task-client.c
+++ b/libpackagekit/pk-task-client.c
@@ -262,7 +262,7 @@ pk_task_client_get_updates (PkTaskClient
pk_warning ("GetUpdates failed!");
return FALSE;
}
-pk_warning("set job");
+
pk_task_monitor_set_job (tclient->priv->tmonitor, tclient->priv->job);
pk_task_client_wait_if_sync (tclient);
diff-tree 58785ab0eb9c850db7fb89f1ad6c08d65dd35e03 (from 6d061b2076cb0af6e63f30d687e7586a0a5c424a)
Author: Richard Hughes <richard at hughsie.com>
Date: Thu Sep 6 21:13:24 2007 +0100
remove the task header. yay
diff --git a/src/pk-task.h b/src/pk-task.h
deleted file mode 100644
index 5212848..0000000
--- a/src/pk-task.h
+++ /dev/null
@@ -1,111 +0,0 @@
-/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
- *
- * 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.
- *
- * 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.
- */
-
-#ifndef __PK_TASK_H
-#define __PK_TASK_H
-
-#include <glib-object.h>
-#include "pk-task-utils.h"
-#include "pk-spawn.h"
-
-G_BEGIN_DECLS
-
-#define PK_TYPE_TASK (pk_task_get_type ())
-#define PK_TASK(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), PK_TYPE_TASK, PkTask))
-#define PK_TASK_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), PK_TYPE_TASK, PkTaskClass))
-#define PK_IS_TASK(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), PK_TYPE_TASK))
-#define PK_IS_TASK_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), PK_TYPE_TASK))
-#define PK_TASK_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), PK_TYPE_TASK, PkTaskClass))
-
-typedef struct PkTaskPrivate PkTaskPrivate;
-
-typedef enum {
- PK_TASK_JOB_STATUS_CHANGED,
- PK_TASK_PERCENTAGE_CHANGED,
- PK_TASK_SUB_PERCENTAGE_CHANGED,
- PK_TASK_NO_PERCENTAGE_UPDATES,
- PK_TASK_DESCRIPTION,
- PK_TASK_PACKAGE,
- PK_TASK_ERROR_CODE,
- PK_TASK_REQUIRE_RESTART,
- PK_TASK_FINISHED,
- PK_TASK_ALLOW_INTERRUPT,
- PK_TASK_LAST_SIGNAL
-} PkSignals;
-
-typedef struct
-{
- GObject parent;
- PkTaskPrivate *priv;
- gboolean assigned;
- PkTaskStatus role; /* this never changes for the lifetime of a job */
- PkTaskStatus status; /* this changes */
- gchar *package_id; /* never changes, this is linked to role */
- PkTaskExit exit;
- GTimer *timer;
- guint *signals;
- PkSpawn *spawn;
- gboolean is_killable;
-} PkTask;
-
-typedef struct
-{
- GObjectClass parent_class;
-} PkTaskClass;
-
-GType pk_task_get_type (void);
-PkTask *pk_task_new (void);
-gchar *pk_task_get_actions (void);
-
-gboolean pk_task_get_updates (PkTask *task);
-gboolean pk_task_update_system (PkTask *task);
-gboolean pk_task_search_name (PkTask *task,
- const gchar *filter,
- const gchar *search);
-gboolean pk_task_search_details (PkTask *task,
- const gchar *filter,
- const gchar *search);
-gboolean pk_task_search_group (PkTask *task,
- const gchar *filter,
- const gchar *search);
-gboolean pk_task_search_file (PkTask *task,
- const gchar *filter,
- const gchar *search);
-gboolean pk_task_get_depends (PkTask *task,
- const gchar *package);
-gboolean pk_task_get_requires (PkTask *task,
- const gchar *package);
-gboolean pk_task_remove_package (PkTask *task,
- const gchar *package,
- gboolean allow_deps);
-gboolean pk_task_refresh_cache (PkTask *task,
- gboolean force);
-gboolean pk_task_install_package (PkTask *task,
- const gchar *package);
-gboolean pk_task_update_package (PkTask *task,
- const gchar *package);
-gboolean pk_task_get_description (PkTask *task,
- const gchar *package);
-gboolean pk_task_cancel_job_try (PkTask *task);
-
-G_END_DECLS
-
-#endif /* __PK_TASK_H */
diff-tree 6d061b2076cb0af6e63f30d687e7586a0a5c424a (from d94780e73a3bc9bab8110f8d7002082c6e67589b)
Author: Richard Hughes <richard at hughsie.com>
Date: Thu Sep 6 21:11:44 2007 +0100
move the apt plugin to the new dir. i might have mis-converted it, hance why I'm being careful
diff --git a/backends/apt/pk-task-apt.cpp.delete.me b/backends/apt/pk-task-apt.cpp.delete.me
new file mode 100644
index 0000000..4a9f5ed
--- /dev/null
+++ b/backends/apt/pk-task-apt.cpp.delete.me
@@ -0,0 +1,892 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
+ *
+ * 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.
+ *
+ * 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.
+ */
+
+//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
+//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
+//!!!!! !!!!!!!!!
+//!!!!! Do not edit this file! Edit backends/$backend !!!!!!!!!
+//!!!!! !!!!!!!!!
+//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
+//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
+
+#include <apt-pkg/pkgcachegen.h>
+#include <apt-pkg/pkgcache.h>
+#include <apt-pkg/cachefile.h>
+#include <apt-pkg/progress.h>
+#include <apt-pkg/configuration.h>
+#include <apt-pkg/init.h>
+#include <apt-pkg/pkgrecords.h>
+#include <apt-pkg/sourcelist.h>
+#include <apt-pkg/error.h>
+#include <apt-pkg/acquire.h>
+#include <apt-pkg/acquire-item.h>
+
+#include <regex.h>
+#include <string.h>
+#include <math.h>
+
+#include "pk-debug.h"
+#include "pk-task.h"
+#include "pk-task-common.h"
+#include "config.h"
+#include "pk-network.h"
+#include "pk-package-id.h"
+
+static void pk_task_class_init(PkTaskClass * klass);
+static void pk_task_init(PkTask * task);
+static void pk_task_finalize(GObject * object);
+
+#define PK_TASK_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), PK_TYPE_TASK, PkTaskPrivate))
+
+struct PkTaskPrivate
+{
+ guint progress_percentage;
+ PkNetwork *network;
+};
+
+static guint signals[PK_TASK_LAST_SIGNAL] = { 0, };
+
+G_DEFINE_TYPE(PkTask, pk_task, G_TYPE_OBJECT)
+
+static pkgCacheFile *fileCache = NULL;
+pkgSourceList *SrcList = 0;
+
+static pkgCacheFile *getCache()
+{
+ if (fileCache == NULL)
+ {
+ MMap *Map = 0;
+ OpTextProgress Prog;
+ if (pkgInitConfig(*_config) == false)
+ pk_debug("pkginitconfig was false");
+ if (pkgInitSystem(*_config, _system) == false)
+ pk_debug("pkginitsystem was false");
+ // Open the cache file
+ SrcList = new pkgSourceList;
+ SrcList->ReadMainList();
+
+ // Generate it and map it
+ pkgMakeStatusCache(*SrcList, Prog, &Map, true);
+
+ fileCache = new pkgCacheFile();
+
+ if (fileCache->Open(Prog, FALSE) == FALSE)
+ {
+ pk_debug("I need more privelges");
+ fileCache->Close();
+ fileCache = NULL;
+ }
+ else
+ pk_debug("cache inited");
+ }
+ return fileCache;
+}
+
+
+/**
+ * pk_task_get_actions
+ **/
+gchar *
+pk_task_get_actions (void)
+{
+ gchar *actions;
+ actions = pk_task_action_build (PK_TASK_ACTION_REFRESH_CACHE,
+ PK_TASK_ACTION_UPDATE_SYSTEM,
+ PK_TASK_ACTION_SEARCH_NAME,
+ PK_TASK_ACTION_SEARCH_DETAILS,
+ PK_TASK_ACTION_GET_DESCRIPTION,
+ 0);
+ return actions;
+}
+
+/**
+ * pk_task_get_updates:
+ **/
+gboolean pk_task_get_updates(PkTask * task)
+{
+ g_return_val_if_fail(task != NULL, FALSE);
+ g_return_val_if_fail(PK_IS_TASK(task), FALSE);
+
+ if (pk_task_assign(task) == FALSE)
+ {
+ return FALSE;
+ }
+
+ pk_task_not_implemented_yet(task, "GetUpdates");
+ return FALSE;
+}
+
+typedef struct
+{
+ PkTask *task;
+} UpdateData;
+
+class UpdatePercentage:public pkgAcquireStatus
+{
+ double old;
+ PkTask *task;
+
+ public:
+ UpdatePercentage(PkTask *tk)
+ {
+ old = -1;
+ task = tk;
+ }
+
+ virtual bool MediaChange(string Media,string Drive)
+ {
+ pk_debug("PANIC!: we don't handle mediachange");
+ return FALSE;
+ }
+
+ virtual bool Pulse(pkgAcquire *Owner)
+ {
+ pkgAcquireStatus::Pulse(Owner);
+ double percent = double(CurrentBytes*100.0)/double(TotalBytes);
+ if (old!=percent)
+ {
+ pk_task_change_percentage(task,(guint)percent);
+ pk_task_change_sub_percentage(task,((guint)(percent*100.0))%100);
+ old = percent;
+ }
+ return true;
+ }
+};
+
+// DoUpdate - Update the package lists
+// Swiped from apt-get's update mode
+void *DoUpdate(gpointer data)
+{
+ UpdateData *ud = (UpdateData*)data;
+ pkgCacheFile *Cache;
+ bool Failed = false;
+ bool TransientNetworkFailure = false;
+ OpTextProgress Prog;
+
+ /* easy as that */
+ pk_task_change_job_status(ud->task, PK_TASK_STATUS_REFRESH_CACHE);
+
+ Cache = getCache();
+
+ // Get the source list
+ pkgSourceList List;
+ if (List.ReadMainList() == false)
+ {
+ pk_task_error_code(ud->task, PK_TASK_ERROR_CODE_UNKNOWN, "Failure reading lists");
+ pk_task_finished(ud->task, PK_TASK_EXIT_FAILED);
+ return NULL;
+ }
+
+ // Lock the list directory
+ FileFd Lock;
+ if (_config->FindB("Debug::NoLocking", false) == false)
+ {
+ Lock.Fd(GetLock(_config->FindDir("Dir::State::Lists") + "lock"));
+ if (_error->PendingError() == true)
+ {
+ _error->DumpErrors();
+ pk_task_error_code(ud->task, PK_TASK_ERROR_CODE_UNKNOWN, "Unable to lock the list directory");
+ pk_task_finished(ud->task, PK_TASK_EXIT_FAILED);
+ return NULL;
+ }
+ }
+
+ // Create the download object
+ UpdatePercentage *Stat = new UpdatePercentage(ud->task);
+ pkgAcquire Fetcher(Stat);
+
+ // Populate it with the source selection
+ if (List.GetIndexes(&Fetcher) == false)
+ {
+ pk_task_error_code(ud->task, PK_TASK_ERROR_CODE_UNKNOWN, "Generic Error");
+ goto do_update_clean;
+ }
+
+ // Run it
+ if (Fetcher.Run() == pkgAcquire::Failed)
+ {
+ pk_task_error_code(ud->task, PK_TASK_ERROR_CODE_UNKNOWN, "Generic Error");
+ goto do_update_clean;
+ }
+
+ for (pkgAcquire::ItemIterator I = Fetcher.ItemsBegin(); I != Fetcher.ItemsEnd(); I++)
+ {
+ if ((*I)->Status == pkgAcquire::Item::StatDone)
+ continue;
+
+ (*I)->Finished();
+
+ fprintf(stderr, "Failed to fetch %s %s\n", (*I)->DescURI().c_str(), (*I)->ErrorText.c_str());
+
+ if ((*I)->Status == pkgAcquire::Item::StatTransientNetworkError)
+ {
+ TransientNetworkFailure = true;
+ continue;
+ }
+
+ Failed = true;
+ }
+
+ // Clean out any old list files
+ if (!TransientNetworkFailure && _config->FindB("APT::Get::List-Cleanup", true) == true)
+ {
+ if (Fetcher.Clean(_config->FindDir("Dir::State::lists")) == false || Fetcher.Clean(_config->FindDir("Dir::State::lists") + "partial/") == false)
+ {
+ pk_task_error_code(ud->task, PK_TASK_ERROR_CODE_UNKNOWN, "Generic Error");
+ goto do_update_clean;
+ }
+ }
+
+ // Prepare the cache.
+ Cache = getCache();
+ if (Cache->BuildCaches(Prog,false) == false)
+ {
+ pk_task_error_code(ud->task, PK_TASK_ERROR_CODE_UNKNOWN, "Generic Error");
+ goto do_update_clean;
+ }
+
+ if (TransientNetworkFailure == true)
+ pk_debug("Some index files failed to download, they have been ignored, or old ones used instead.");
+ else if (Failed == true)
+ {
+ pk_task_error_code(ud->task, PK_TASK_ERROR_CODE_UNKNOWN, "Generic Error");
+ goto do_update_clean;
+ }
+
+ delete Stat;
+ pk_task_finished(ud->task, PK_TASK_EXIT_SUCCESS);
+ return NULL;
+
+ do_update_clean:
+ delete Stat;
+ pk_task_finished(ud->task, PK_TASK_EXIT_FAILED);
+ return NULL;
+}
+
+/**
+ * pk_task_refresh_cache:
+ **/
+gboolean pk_task_refresh_cache(PkTask * task, gboolean force)
+{
+ g_return_val_if_fail(task != NULL, FALSE);
+ g_return_val_if_fail(PK_IS_TASK(task), FALSE);
+
+ if (pk_task_assign(task) == FALSE)
+ {
+ return FALSE;
+ }
+
+ /* check network state */
+ if (pk_network_is_online(task->priv->network) == FALSE)
+ {
+ pk_task_error_code(task, PK_TASK_ERROR_CODE_NO_NETWORK, "Cannot refresh cache whilst offline");
+ pk_task_finished(task, PK_TASK_EXIT_FAILED);
+ return TRUE;
+ }
+
+ UpdateData *data = g_new(UpdateData, 1);
+ if (data == NULL)
+ {
+ pk_task_error_code(task, PK_TASK_ERROR_CODE_UNKNOWN, "can't allocate memory for update task");
+ pk_task_finished(task, PK_TASK_EXIT_FAILED);
+ }
+ else
+ {
+ data->task = task;
+ if (g_thread_create(DoUpdate,data, false, NULL) == NULL)
+ {
+ pk_task_error_code(task, PK_TASK_ERROR_CODE_UNKNOWN, "can't spawn update thread");
+ pk_task_finished(task, PK_TASK_EXIT_FAILED);
+ }
+ }
+ return TRUE;
+}
+
+/**
+ * pk_task_update_system:
+ **/
+gboolean pk_task_update_system(PkTask * task)
+{
+ g_return_val_if_fail(task != NULL, FALSE);
+ g_return_val_if_fail(PK_IS_TASK(task), FALSE);
+
+ if (pk_task_assign(task) == FALSE)
+ {
+ return FALSE;
+ }
+
+ /* not implimented yet */
+ return FALSE;
+}
+
+#ifdef APT_PKG_RPM
+typedef pkgCache::VerFile AptCompFile;
+#elif defined(APT_PKG_DEB)
+typedef pkgCache::DescFile AptCompFile;
+#else
+#error Need either rpm or deb defined
+#endif
+
+struct ExDescFile
+{
+ AptCompFile *Df;
+ const char *verstr;
+ const char *arch;
+ gboolean installed;
+ gboolean available;
+ char *repo;
+ bool NameMatch;
+};
+
+// LocalitySort - Sort a version list by package file locality /*{{{*/
+// ---------------------------------------------------------------------
+/* */
+static int LocalityCompare(const void *a, const void *b)
+{
+ pkgCache::VerFile *A = *(pkgCache::VerFile **)a;
+ pkgCache::VerFile *B = *(pkgCache::VerFile **)b;
+
+ if (A == 0 && B == 0)
+ return 0;
+ if (A == 0)
+ return 1;
+ if (B == 0)
+ return -1;
+
+ if (A->File == B->File)
+ return A->Offset - B->Offset;
+ return A->File - B->File;
+}
+
+static void LocalitySort(AptCompFile **begin,
+ unsigned long Count,size_t Size)
+{
+ qsort(begin,Count,Size,LocalityCompare);
+}
+
+typedef enum {SEARCH_NAME=1, SEARCH_DETAILS} SearchDepth;
+
+struct search_task
+{
+ PkTask *task;
+ gchar *search;
+ gchar *filter;
+ SearchDepth depth;
+};
+
+static gboolean buildExDesc(ExDescFile *DFList, unsigned int pid, pkgCache::VerIterator V)
+{
+ // Find the proper version to use.
+ DFList[pid].available = false;
+ if (V.end() == false)
+ {
+ #ifdef APT_PKG_RPM
+ DFList[pid].Df = V.FileList();
+ #else
+ DFList[pid].Df = V.DescriptionList().FileList();
+ #endif
+ DFList[pid].verstr = V.VerStr();
+ DFList[pid].arch = V.Arch();
+ for (pkgCache::VerFileIterator VF = V.FileList(); VF.end() == false; VF++)
+ {
+ // Locate the associated index files so we can derive a description
+ pkgIndexFile *Indx;
+ bool hasLocal = _system->FindIndex(VF.File(),Indx);
+ if (SrcList->FindIndex(VF.File(),Indx) == false && !hasLocal)
+ {
+ pk_debug("Cache is out of sync, can't x-ref a package file");
+ break;
+ }
+ gchar** items = g_strsplit_set(Indx->Describe(true).c_str()," \t",-1);
+ DFList[pid].repo = g_strdup(items[1]); // should be in format like "http://ftp.nl.debian.org unstable/main Packages"
+ DFList[pid].installed = hasLocal;
+ g_strfreev(items);
+ DFList[pid].available = true;
+ if (hasLocal)
+ break;
+ }
+ }
+ return DFList[pid].available;
+}
+
+// do_search_task
+// Swiped from apt-cache's search mode
+static void *do_search_task(gpointer data)
+{
+ search_task *st = (search_task *) data;
+ ExDescFile *DFList = NULL;
+
+ pk_task_change_job_status(st->task, PK_TASK_STATUS_QUERY);
+ pk_task_no_percentage_updates(st->task);
+
+ pk_debug("finding %s", st->search);
+ pkgCache & pkgCache = *(getCache());
+ pkgDepCache::Policy Plcy;
+ // Create the text record parser
+ pkgRecords Recs(pkgCache);
+
+ // Compile the regex pattern
+ regex_t *Pattern = new regex_t;
+ memset(Pattern, 0, sizeof(*Pattern));
+ if (regcomp(Pattern, st->search, REG_EXTENDED | REG_ICASE | REG_NOSUB) != 0)
+ {
+ pk_task_error_code(st->task, PK_TASK_ERROR_CODE_UNKNOWN, "regex compilation error");
+ pk_task_finished(st->task, PK_TASK_EXIT_FAILED);
+ goto search_task_cleanup;
+ }
+
+ DFList = new ExDescFile[pkgCache.HeaderP->PackageCount + 1];
+ memset(DFList, 0, sizeof(*DFList) * pkgCache.HeaderP->PackageCount + 1);
+
+ // Map versions that we want to write out onto the VerList array.
+ for (pkgCache::PkgIterator P = pkgCache.PkgBegin(); P.end() == false; P++)
+ {
+ DFList[P->ID].NameMatch = true;
+ if (regexec(Pattern, P.Name(), 0, 0, 0) == 0)
+ DFList[P->ID].NameMatch &= true;
+ else
+ DFList[P->ID].NameMatch = false;
+
+ // Doing names only, drop any that dont match..
+ if (st->depth == SEARCH_NAME && DFList[P->ID].NameMatch == false)
+ continue;
+
+ // Find the proper version to use.
+ pkgCache::VerIterator V = Plcy.GetCandidateVer(P);
+ buildExDesc(DFList, P->ID, V);
+ }
+
+ // Include all the packages that provide matching names too
+ for (pkgCache::PkgIterator P = pkgCache.PkgBegin(); P.end() == false; P++)
+ {
+ if (DFList[P->ID].NameMatch == false)
+ continue;
+
+ for (pkgCache::PrvIterator Prv = P.ProvidesList(); Prv.end() == false; Prv++)
+ {
+ pkgCache::VerIterator V = Plcy.GetCandidateVer(Prv.OwnerPkg());
+ if (buildExDesc(DFList, Prv.OwnerPkg()->ID, V))
+ DFList[Prv.OwnerPkg()->ID].NameMatch = true;
+ }
+ }
+
+ LocalitySort(&DFList->Df, pkgCache.HeaderP->PackageCount, sizeof(*DFList));
+
+ // Iterate over all the version records and check them
+ for (ExDescFile * J = DFList; J->Df != 0; J++)
+ {
+#ifdef APT_PKG_RPM
+ pkgRecords::Parser & P = Recs.Lookup(pkgCache::VerFileIterator(pkgCache, J->Df));
+#else
+ pkgRecords::Parser & P = Recs.Lookup(pkgCache::DescFileIterator(pkgCache, J->Df));
+#endif
+
+ gboolean Match = true;
+ if (J->NameMatch == false)
+ {
+ string LongDesc = P.LongDesc();
+ if (regexec(Pattern, LongDesc.c_str(), 0, 0, 0) == 0)
+ Match = true;
+ else
+ Match = false;
+ }
+
+ if (Match == true)// && pk_task_filter_package_name(st->task,P.Name().c_str()))
+ {
+ gchar *pid = pk_package_id_build(P.Name().c_str(),J->verstr,J->arch,J->repo);
+ pk_task_package(st->task, J->installed, pid, P.ShortDesc().c_str());
+ g_free(pid);
+ }
+ }
+
+ pk_task_finished(st->task, PK_TASK_EXIT_SUCCESS);
+
+ search_task_cleanup:
+ for (ExDescFile * J = DFList; J->Df != 0; J++)
+ {
+ g_free(J->repo);
+ }
+ delete[]DFList;
+ regfree(Pattern);
+ g_free(st->search);
+ g_free(st);
+
+ return NULL;
+}
+
+/**
+ * pk_task_search
+ **/
+static gboolean
+pk_task_search(PkTask * task, const gchar * filter, const gchar * search, SearchDepth which)
+{
+ g_return_val_if_fail(task != NULL, FALSE);
+ g_return_val_if_fail(PK_IS_TASK(task), FALSE);
+
+ if (pk_task_assign(task) == FALSE)
+ {
+ return FALSE;
+ }
+
+ if (pk_task_filter_check(filter) == FALSE)
+ {
+ pk_task_error_code(task, PK_TASK_ERROR_CODE_FILTER_INVALID, "filter '%s' not valid", filter);
+ pk_task_finished(task, PK_TASK_EXIT_FAILED);
+ return TRUE;
+ }
+
+ search_task *data = g_new(struct search_task, 1);
+ if (data == NULL)
+ {
+ pk_task_error_code(task, PK_TASK_ERROR_CODE_UNKNOWN, "can't allocate memory for search task");
+ pk_task_finished(task, PK_TASK_EXIT_FAILED);
+ }
+ else
+ {
+ data->task = task;
+ data->search = g_strdup(search);
+ data->filter = g_strdup(filter);
+ data->depth = which;
+
+ if (g_thread_create(do_search_task, data, false, NULL) == NULL)
+ {
+ pk_task_error_code(task, PK_TASK_ERROR_CODE_UNKNOWN, "can't spawn thread");
+ pk_task_finished(task, PK_TASK_EXIT_FAILED);
+ }
+ }
+ return TRUE;
+}
+
+/**
+ * pk_task_search_details:
+ **/
+gboolean pk_task_search_details(PkTask * task, const gchar * filter, const gchar * search)
+{
+ return pk_task_search(task, filter, search, SEARCH_DETAILS);
+}
+
+/**
+ * pk_task_search_name:
+ **/
+gboolean pk_task_search_name(PkTask * task, const gchar * filter, const gchar * search)
+{
+ return pk_task_search(task, filter, search, SEARCH_NAME);
+}
+
+/**
+ * pk_task_search_group:
+ **/
+gboolean pk_task_search_group(PkTask * task, const gchar * filter, const gchar * search)
+{
+ pk_task_not_implemented_yet(task, "SearchGroup");
+ return TRUE;
+}
+
+/**
+ * pk_task_search_file:
+ **/
+gboolean pk_task_search_file(PkTask * task, const gchar * filter, const gchar * search)
+{
+ pk_task_not_implemented_yet(task, "SearchFile");
+ return TRUE;
+}
+
+/**
+ * pk_task_get_depends:
+ **/
+gboolean pk_task_get_depends(PkTask * task, const gchar * package)
+{
+ g_return_val_if_fail(task != NULL, FALSE);
+ g_return_val_if_fail(PK_IS_TASK(task), FALSE);
+
+ if (pk_task_assign(task) == FALSE)
+ {
+ return FALSE;
+ }
+
+ pk_task_not_implemented_yet (task, "GetDepends");
+ return FALSE;
+}
+/**
+ * pk_task_get_requires:
+ **/
+gboolean pk_task_get_requires(PkTask * task, const gchar * package)
+{
+ g_return_val_if_fail(task != NULL, FALSE);
+ g_return_val_if_fail(PK_IS_TASK(task), FALSE);
+
+ if (pk_task_assign(task) == FALSE)
+ {
+ return FALSE;
+ }
+
+ pk_task_not_implemented_yet (task, "GetRequires");
+ return FALSE;
+}
+
+struct desc_task
+{
+ PkTask *task;
+ PkPackageId *pi;
+};
+
+static GHashTable *PackageRecord(pkgCache::VerIterator V)
+{
+ GHashTable *ret = NULL;
+
+ pkgCache & pkgCache = *(getCache());
+ // Find an appropriate file
+ pkgCache::VerFileIterator Vf = V.FileList();
+ for (; Vf.end() == false; Vf++)
+ {
+ if ((Vf.File()->Flags & pkgCache::Flag::NotSource) == 0)
+ break;
+ if (Vf.end() == true)
+ Vf = V.FileList();
+ }
+
+ // Check and load the package list file
+ pkgCache::PkgFileIterator I = Vf.File();
+ if (I.IsOk() == false)
+ return NULL;
+
+ FileFd PkgF(I.FileName(),FileFd::ReadOnly);
+ if (_error->PendingError() == true)
+ return NULL;
+
+ // Read the record
+ char *Buffer = new char[pkgCache.HeaderP->MaxVerFileSize+1];
+ Buffer[V.FileList()->Size] = '\0';
+ if (PkgF.Seek(V.FileList()->Offset) == false ||
+ PkgF.Read(Buffer,V.FileList()->Size) == false)
+ {
+ delete [] Buffer;
+ return NULL;
+ }
+ //pk_debug("buffer: '%s'\n",Buffer);
+ ret = g_hash_table_new_full(g_str_hash,g_str_equal,g_free,g_free);
+ gchar ** lines = g_strsplit(Buffer,"\n",-1);
+ guint i;
+ for (i=0;i<g_strv_length(lines);i++)
+ {
+ gchar ** parts = g_strsplit_set(lines[i],": ",2);
+ if (g_strv_length(parts)>1)
+ {
+ //pk_debug("entry = '%s' : '%s'",parts[0],parts[1]);
+ if (parts[0][0]=='\0')
+ {
+ gchar *oldval = g_strdup((const gchar*)g_hash_table_lookup(ret,"Description"));
+ g_hash_table_insert(ret,g_strdup("Description"),g_strconcat(oldval, "\n",parts[1],NULL));
+ //pk_debug("new entry = '%s'",(const gchar*)g_hash_table_lookup(ret,"Description"));
+ g_free(oldval);
+ }
+ else
+ g_hash_table_insert(ret,g_strdup(parts[0]),g_strdup(parts[1]));
+ }
+ g_strfreev(parts);
+ }
+ g_strfreev(lines);
+ return ret;
+
+}
+
+// get_desc_task
+static void *get_desc_task(gpointer data)
+{
+ desc_task *dt = (desc_task *) data;
+
+ pk_task_change_job_status(dt->task, PK_TASK_STATUS_QUERY);
+ pk_task_no_percentage_updates(dt->task);
+
+ pk_debug("finding %s", dt->pi->name);
+ pkgCache & pkgCache = *(getCache());
+ pkgDepCache::Policy Plcy;
+
+ // Map versions that we want to write out onto the VerList array.
+ for (pkgCache::PkgIterator P = pkgCache.PkgBegin(); P.end() == false; P++)
+ {
+ if (strcmp(dt->pi->name, P.Name())!=0)
+ continue;
+
+ // Find the proper version to use.
+ pkgCache::VerIterator V = Plcy.GetCandidateVer(P);
+ GHashTable *pkg = PackageRecord(V);
+ pk_task_description(dt->task,dt->pi->name,PK_TASK_GROUP_OTHER,(const gchar*)g_hash_table_lookup(pkg,"Description"),"");
+ g_hash_table_unref(pkg);
+ }
+ pk_task_finished(dt->task, PK_TASK_EXIT_SUCCESS);
+ return NULL;
+}
+
+/**
+ * pk_task_get_description:
+ **/
+gboolean pk_task_get_description(PkTask * task, const gchar * package)
+{
+ g_return_val_if_fail(task != NULL, FALSE);
+ g_return_val_if_fail(PK_IS_TASK(task), FALSE);
+
+ if (pk_task_assign(task) == FALSE)
+ {
+ return FALSE;
+ }
+
+ desc_task *data = g_new(struct desc_task, 1);
+ if (data == NULL)
+ {
+ pk_task_error_code(task, PK_TASK_ERROR_CODE_INTERNAL_ERROR, "can't allocate memory for search task");
+ pk_task_finished(task, PK_TASK_EXIT_FAILED);
+ return TRUE;
+ }
+
+ data->task = task;
+ data->pi = pk_package_id_new_from_string(package);
+ if (data->pi == NULL)
+ {
+ pk_task_error_code(task, PK_TASK_ERROR_CODE_PACKAGE_ID_INVALID, "invalid package id");
+ pk_task_finished(task, PK_TASK_EXIT_FAILED);
+ return TRUE;
+ }
+
+ if (g_thread_create(get_desc_task, data, false, NULL) == NULL)
+ {
+ pk_task_error_code(task, PK_TASK_ERROR_CODE_INTERNAL_ERROR, "can't spawn thread");
+ pk_task_finished(task, PK_TASK_EXIT_FAILED);
+ }
+ return TRUE;
+}
+
+/**
+ * pk_task_remove_package:
+ **/
+gboolean pk_task_remove_package(PkTask * task, const gchar * package, gboolean allow_deps)
+{
+ g_return_val_if_fail(task != NULL, FALSE);
+ g_return_val_if_fail(PK_IS_TASK(task), FALSE);
+
+ if (pk_task_assign(task) == FALSE)
+ {
+ return FALSE;
+ }
+
+ pk_task_not_implemented_yet(task, "RemovePackage");
+ return FALSE;
+}
+
+/**
+ * pk_task_install_package:
+ **/
+gboolean pk_task_install_package(PkTask * task, const gchar * package)
+{
+ g_return_val_if_fail(task != NULL, FALSE);
+ g_return_val_if_fail(PK_IS_TASK(task), FALSE);
+
+ if (pk_task_assign(task) == FALSE)
+ {
+ return FALSE;
+ }
+
+ pk_task_not_implemented_yet(task, "InstallPackage");
+ return FALSE;
+}
+
+/**
+ * pk_task_cancel_job_try:
+ **/
+gboolean pk_task_cancel_job_try(PkTask * task)
+{
+ g_return_val_if_fail(task != NULL, FALSE);
+ g_return_val_if_fail(PK_IS_TASK(task), FALSE);
+
+ /* check to see if we have an action */
+ if (task->assigned == FALSE)
+ {
+ pk_warning("Not assigned");
+ return FALSE;
+ }
+
+ pk_task_not_implemented_yet (task, "CancelJobTry");
+ return FALSE;
+}
+
+/**
+ * pk_task_update_package:
+ **/
+gboolean
+pk_task_update_package (PkTask *task, const gchar *package_id)
+{
+ g_return_val_if_fail (task != NULL, FALSE);
+ g_return_val_if_fail (PK_IS_TASK (task), FALSE);
+
+ if (pk_task_assign (task) == FALSE) {
+ return FALSE;
+ }
+
+ pk_task_not_implemented_yet (task, "UpdatePackage");
+ return TRUE;
+}
+
+/**
+ * pk_task_class_init:
+ **/
+static void pk_task_class_init(PkTaskClass * klass)
+{
+ GObjectClass *object_class = G_OBJECT_CLASS(klass);
+
+ object_class->finalize = pk_task_finalize;
+ pk_task_setup_signals(object_class, signals);
+ g_type_class_add_private(klass, sizeof(PkTaskPrivate));
+}
+
+/**
+ * pk_task_init:
+ **/
+static void pk_task_init(PkTask * task)
+{
+ task->priv = PK_TASK_GET_PRIVATE(task);
+ task->priv->network = pk_network_new();
+ task->signals = signals;
+ pk_task_common_init(task);
+}
+
+/**
+ * pk_task_finalize:
+ **/
+static void pk_task_finalize(GObject * object)
+{
+ PkTask *task;
+ g_return_if_fail(object != NULL);
+ g_return_if_fail(PK_IS_TASK(object));
+ task = PK_TASK(object);
+ g_return_if_fail(task->priv != NULL);
+ G_OBJECT_CLASS(pk_task_parent_class)->finalize(object);
+}
+
+/**
+ * pk_task_new:
+ **/
+PkTask *pk_task_new(void)
+{
+ PkTask *task;
+ task = (PkTask *) g_object_new(PK_TYPE_TASK, NULL);
+ return PK_TASK(task);
+}
+
diff --git a/src/pk-task-apt.cpp b/src/pk-task-apt.cpp
deleted file mode 100644
index 4a9f5ed..0000000
--- a/src/pk-task-apt.cpp
+++ /dev/null
@@ -1,892 +0,0 @@
-/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
- *
- * 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.
- *
- * 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.
- */
-
-//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
-//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
-//!!!!! !!!!!!!!!
-//!!!!! Do not edit this file! Edit backends/$backend !!!!!!!!!
-//!!!!! !!!!!!!!!
-//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
-//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
-
-#include <apt-pkg/pkgcachegen.h>
-#include <apt-pkg/pkgcache.h>
-#include <apt-pkg/cachefile.h>
-#include <apt-pkg/progress.h>
-#include <apt-pkg/configuration.h>
-#include <apt-pkg/init.h>
-#include <apt-pkg/pkgrecords.h>
-#include <apt-pkg/sourcelist.h>
-#include <apt-pkg/error.h>
-#include <apt-pkg/acquire.h>
-#include <apt-pkg/acquire-item.h>
-
-#include <regex.h>
-#include <string.h>
-#include <math.h>
-
-#include "pk-debug.h"
-#include "pk-task.h"
-#include "pk-task-common.h"
-#include "config.h"
-#include "pk-network.h"
-#include "pk-package-id.h"
-
-static void pk_task_class_init(PkTaskClass * klass);
-static void pk_task_init(PkTask * task);
-static void pk_task_finalize(GObject * object);
-
-#define PK_TASK_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), PK_TYPE_TASK, PkTaskPrivate))
-
-struct PkTaskPrivate
-{
- guint progress_percentage;
- PkNetwork *network;
-};
-
-static guint signals[PK_TASK_LAST_SIGNAL] = { 0, };
-
-G_DEFINE_TYPE(PkTask, pk_task, G_TYPE_OBJECT)
-
-static pkgCacheFile *fileCache = NULL;
-pkgSourceList *SrcList = 0;
-
-static pkgCacheFile *getCache()
-{
- if (fileCache == NULL)
- {
- MMap *Map = 0;
- OpTextProgress Prog;
- if (pkgInitConfig(*_config) == false)
- pk_debug("pkginitconfig was false");
- if (pkgInitSystem(*_config, _system) == false)
- pk_debug("pkginitsystem was false");
- // Open the cache file
- SrcList = new pkgSourceList;
- SrcList->ReadMainList();
-
- // Generate it and map it
- pkgMakeStatusCache(*SrcList, Prog, &Map, true);
-
- fileCache = new pkgCacheFile();
-
- if (fileCache->Open(Prog, FALSE) == FALSE)
- {
- pk_debug("I need more privelges");
- fileCache->Close();
- fileCache = NULL;
- }
- else
- pk_debug("cache inited");
- }
- return fileCache;
-}
-
-
-/**
- * pk_task_get_actions
- **/
-gchar *
-pk_task_get_actions (void)
-{
- gchar *actions;
- actions = pk_task_action_build (PK_TASK_ACTION_REFRESH_CACHE,
- PK_TASK_ACTION_UPDATE_SYSTEM,
- PK_TASK_ACTION_SEARCH_NAME,
- PK_TASK_ACTION_SEARCH_DETAILS,
- PK_TASK_ACTION_GET_DESCRIPTION,
- 0);
- return actions;
-}
-
-/**
- * pk_task_get_updates:
- **/
-gboolean pk_task_get_updates(PkTask * task)
-{
- g_return_val_if_fail(task != NULL, FALSE);
- g_return_val_if_fail(PK_IS_TASK(task), FALSE);
-
- if (pk_task_assign(task) == FALSE)
- {
- return FALSE;
- }
-
- pk_task_not_implemented_yet(task, "GetUpdates");
- return FALSE;
-}
-
-typedef struct
-{
- PkTask *task;
-} UpdateData;
-
-class UpdatePercentage:public pkgAcquireStatus
-{
- double old;
- PkTask *task;
-
- public:
- UpdatePercentage(PkTask *tk)
- {
- old = -1;
- task = tk;
- }
-
- virtual bool MediaChange(string Media,string Drive)
- {
- pk_debug("PANIC!: we don't handle mediachange");
- return FALSE;
- }
-
- virtual bool Pulse(pkgAcquire *Owner)
- {
- pkgAcquireStatus::Pulse(Owner);
- double percent = double(CurrentBytes*100.0)/double(TotalBytes);
- if (old!=percent)
- {
- pk_task_change_percentage(task,(guint)percent);
- pk_task_change_sub_percentage(task,((guint)(percent*100.0))%100);
- old = percent;
- }
- return true;
- }
-};
-
-// DoUpdate - Update the package lists
-// Swiped from apt-get's update mode
-void *DoUpdate(gpointer data)
-{
- UpdateData *ud = (UpdateData*)data;
- pkgCacheFile *Cache;
- bool Failed = false;
- bool TransientNetworkFailure = false;
- OpTextProgress Prog;
-
- /* easy as that */
- pk_task_change_job_status(ud->task, PK_TASK_STATUS_REFRESH_CACHE);
-
- Cache = getCache();
-
- // Get the source list
- pkgSourceList List;
- if (List.ReadMainList() == false)
- {
- pk_task_error_code(ud->task, PK_TASK_ERROR_CODE_UNKNOWN, "Failure reading lists");
- pk_task_finished(ud->task, PK_TASK_EXIT_FAILED);
- return NULL;
- }
-
- // Lock the list directory
- FileFd Lock;
- if (_config->FindB("Debug::NoLocking", false) == false)
- {
- Lock.Fd(GetLock(_config->FindDir("Dir::State::Lists") + "lock"));
- if (_error->PendingError() == true)
- {
- _error->DumpErrors();
- pk_task_error_code(ud->task, PK_TASK_ERROR_CODE_UNKNOWN, "Unable to lock the list directory");
- pk_task_finished(ud->task, PK_TASK_EXIT_FAILED);
- return NULL;
- }
- }
-
- // Create the download object
- UpdatePercentage *Stat = new UpdatePercentage(ud->task);
- pkgAcquire Fetcher(Stat);
-
- // Populate it with the source selection
- if (List.GetIndexes(&Fetcher) == false)
- {
- pk_task_error_code(ud->task, PK_TASK_ERROR_CODE_UNKNOWN, "Generic Error");
- goto do_update_clean;
- }
-
- // Run it
- if (Fetcher.Run() == pkgAcquire::Failed)
- {
- pk_task_error_code(ud->task, PK_TASK_ERROR_CODE_UNKNOWN, "Generic Error");
- goto do_update_clean;
- }
-
- for (pkgAcquire::ItemIterator I = Fetcher.ItemsBegin(); I != Fetcher.ItemsEnd(); I++)
- {
- if ((*I)->Status == pkgAcquire::Item::StatDone)
- continue;
-
- (*I)->Finished();
-
- fprintf(stderr, "Failed to fetch %s %s\n", (*I)->DescURI().c_str(), (*I)->ErrorText.c_str());
-
- if ((*I)->Status == pkgAcquire::Item::StatTransientNetworkError)
- {
- TransientNetworkFailure = true;
- continue;
- }
-
- Failed = true;
- }
-
- // Clean out any old list files
- if (!TransientNetworkFailure && _config->FindB("APT::Get::List-Cleanup", true) == true)
- {
- if (Fetcher.Clean(_config->FindDir("Dir::State::lists")) == false || Fetcher.Clean(_config->FindDir("Dir::State::lists") + "partial/") == false)
- {
- pk_task_error_code(ud->task, PK_TASK_ERROR_CODE_UNKNOWN, "Generic Error");
- goto do_update_clean;
- }
- }
-
- // Prepare the cache.
- Cache = getCache();
- if (Cache->BuildCaches(Prog,false) == false)
- {
- pk_task_error_code(ud->task, PK_TASK_ERROR_CODE_UNKNOWN, "Generic Error");
- goto do_update_clean;
- }
-
- if (TransientNetworkFailure == true)
- pk_debug("Some index files failed to download, they have been ignored, or old ones used instead.");
- else if (Failed == true)
- {
- pk_task_error_code(ud->task, PK_TASK_ERROR_CODE_UNKNOWN, "Generic Error");
- goto do_update_clean;
- }
-
- delete Stat;
- pk_task_finished(ud->task, PK_TASK_EXIT_SUCCESS);
- return NULL;
-
- do_update_clean:
- delete Stat;
- pk_task_finished(ud->task, PK_TASK_EXIT_FAILED);
- return NULL;
-}
-
-/**
- * pk_task_refresh_cache:
- **/
-gboolean pk_task_refresh_cache(PkTask * task, gboolean force)
-{
- g_return_val_if_fail(task != NULL, FALSE);
- g_return_val_if_fail(PK_IS_TASK(task), FALSE);
-
- if (pk_task_assign(task) == FALSE)
- {
- return FALSE;
- }
-
- /* check network state */
- if (pk_network_is_online(task->priv->network) == FALSE)
- {
- pk_task_error_code(task, PK_TASK_ERROR_CODE_NO_NETWORK, "Cannot refresh cache whilst offline");
- pk_task_finished(task, PK_TASK_EXIT_FAILED);
- return TRUE;
- }
-
- UpdateData *data = g_new(UpdateData, 1);
- if (data == NULL)
- {
- pk_task_error_code(task, PK_TASK_ERROR_CODE_UNKNOWN, "can't allocate memory for update task");
- pk_task_finished(task, PK_TASK_EXIT_FAILED);
- }
- else
- {
- data->task = task;
- if (g_thread_create(DoUpdate,data, false, NULL) == NULL)
- {
- pk_task_error_code(task, PK_TASK_ERROR_CODE_UNKNOWN, "can't spawn update thread");
- pk_task_finished(task, PK_TASK_EXIT_FAILED);
- }
- }
- return TRUE;
-}
-
-/**
- * pk_task_update_system:
- **/
-gboolean pk_task_update_system(PkTask * task)
-{
- g_return_val_if_fail(task != NULL, FALSE);
- g_return_val_if_fail(PK_IS_TASK(task), FALSE);
-
- if (pk_task_assign(task) == FALSE)
- {
- return FALSE;
- }
-
- /* not implimented yet */
- return FALSE;
-}
-
-#ifdef APT_PKG_RPM
-typedef pkgCache::VerFile AptCompFile;
-#elif defined(APT_PKG_DEB)
-typedef pkgCache::DescFile AptCompFile;
-#else
-#error Need either rpm or deb defined
-#endif
-
-struct ExDescFile
-{
- AptCompFile *Df;
- const char *verstr;
- const char *arch;
- gboolean installed;
- gboolean available;
- char *repo;
- bool NameMatch;
-};
-
-// LocalitySort - Sort a version list by package file locality /*{{{*/
-// ---------------------------------------------------------------------
-/* */
-static int LocalityCompare(const void *a, const void *b)
-{
- pkgCache::VerFile *A = *(pkgCache::VerFile **)a;
- pkgCache::VerFile *B = *(pkgCache::VerFile **)b;
-
- if (A == 0 && B == 0)
- return 0;
- if (A == 0)
- return 1;
- if (B == 0)
- return -1;
-
- if (A->File == B->File)
- return A->Offset - B->Offset;
- return A->File - B->File;
-}
-
-static void LocalitySort(AptCompFile **begin,
- unsigned long Count,size_t Size)
-{
- qsort(begin,Count,Size,LocalityCompare);
-}
-
-typedef enum {SEARCH_NAME=1, SEARCH_DETAILS} SearchDepth;
-
-struct search_task
-{
- PkTask *task;
- gchar *search;
- gchar *filter;
- SearchDepth depth;
-};
-
-static gboolean buildExDesc(ExDescFile *DFList, unsigned int pid, pkgCache::VerIterator V)
-{
- // Find the proper version to use.
- DFList[pid].available = false;
- if (V.end() == false)
- {
- #ifdef APT_PKG_RPM
- DFList[pid].Df = V.FileList();
- #else
- DFList[pid].Df = V.DescriptionList().FileList();
- #endif
- DFList[pid].verstr = V.VerStr();
- DFList[pid].arch = V.Arch();
- for (pkgCache::VerFileIterator VF = V.FileList(); VF.end() == false; VF++)
- {
- // Locate the associated index files so we can derive a description
- pkgIndexFile *Indx;
- bool hasLocal = _system->FindIndex(VF.File(),Indx);
- if (SrcList->FindIndex(VF.File(),Indx) == false && !hasLocal)
- {
- pk_debug("Cache is out of sync, can't x-ref a package file");
- break;
- }
- gchar** items = g_strsplit_set(Indx->Describe(true).c_str()," \t",-1);
- DFList[pid].repo = g_strdup(items[1]); // should be in format like "http://ftp.nl.debian.org unstable/main Packages"
- DFList[pid].installed = hasLocal;
- g_strfreev(items);
- DFList[pid].available = true;
- if (hasLocal)
- break;
- }
- }
- return DFList[pid].available;
-}
-
-// do_search_task
-// Swiped from apt-cache's search mode
-static void *do_search_task(gpointer data)
-{
- search_task *st = (search_task *) data;
- ExDescFile *DFList = NULL;
-
- pk_task_change_job_status(st->task, PK_TASK_STATUS_QUERY);
- pk_task_no_percentage_updates(st->task);
-
- pk_debug("finding %s", st->search);
- pkgCache & pkgCache = *(getCache());
- pkgDepCache::Policy Plcy;
- // Create the text record parser
- pkgRecords Recs(pkgCache);
-
- // Compile the regex pattern
- regex_t *Pattern = new regex_t;
- memset(Pattern, 0, sizeof(*Pattern));
- if (regcomp(Pattern, st->search, REG_EXTENDED | REG_ICASE | REG_NOSUB) != 0)
- {
- pk_task_error_code(st->task, PK_TASK_ERROR_CODE_UNKNOWN, "regex compilation error");
- pk_task_finished(st->task, PK_TASK_EXIT_FAILED);
- goto search_task_cleanup;
- }
-
- DFList = new ExDescFile[pkgCache.HeaderP->PackageCount + 1];
- memset(DFList, 0, sizeof(*DFList) * pkgCache.HeaderP->PackageCount + 1);
-
- // Map versions that we want to write out onto the VerList array.
- for (pkgCache::PkgIterator P = pkgCache.PkgBegin(); P.end() == false; P++)
- {
- DFList[P->ID].NameMatch = true;
- if (regexec(Pattern, P.Name(), 0, 0, 0) == 0)
- DFList[P->ID].NameMatch &= true;
- else
- DFList[P->ID].NameMatch = false;
-
- // Doing names only, drop any that dont match..
- if (st->depth == SEARCH_NAME && DFList[P->ID].NameMatch == false)
- continue;
-
- // Find the proper version to use.
- pkgCache::VerIterator V = Plcy.GetCandidateVer(P);
- buildExDesc(DFList, P->ID, V);
- }
-
- // Include all the packages that provide matching names too
- for (pkgCache::PkgIterator P = pkgCache.PkgBegin(); P.end() == false; P++)
- {
- if (DFList[P->ID].NameMatch == false)
- continue;
-
- for (pkgCache::PrvIterator Prv = P.ProvidesList(); Prv.end() == false; Prv++)
- {
- pkgCache::VerIterator V = Plcy.GetCandidateVer(Prv.OwnerPkg());
- if (buildExDesc(DFList, Prv.OwnerPkg()->ID, V))
- DFList[Prv.OwnerPkg()->ID].NameMatch = true;
- }
- }
-
- LocalitySort(&DFList->Df, pkgCache.HeaderP->PackageCount, sizeof(*DFList));
-
- // Iterate over all the version records and check them
- for (ExDescFile * J = DFList; J->Df != 0; J++)
- {
-#ifdef APT_PKG_RPM
- pkgRecords::Parser & P = Recs.Lookup(pkgCache::VerFileIterator(pkgCache, J->Df));
-#else
- pkgRecords::Parser & P = Recs.Lookup(pkgCache::DescFileIterator(pkgCache, J->Df));
-#endif
-
- gboolean Match = true;
- if (J->NameMatch == false)
- {
- string LongDesc = P.LongDesc();
- if (regexec(Pattern, LongDesc.c_str(), 0, 0, 0) == 0)
- Match = true;
- else
- Match = false;
- }
-
- if (Match == true)// && pk_task_filter_package_name(st->task,P.Name().c_str()))
- {
- gchar *pid = pk_package_id_build(P.Name().c_str(),J->verstr,J->arch,J->repo);
- pk_task_package(st->task, J->installed, pid, P.ShortDesc().c_str());
- g_free(pid);
- }
- }
-
- pk_task_finished(st->task, PK_TASK_EXIT_SUCCESS);
-
- search_task_cleanup:
- for (ExDescFile * J = DFList; J->Df != 0; J++)
- {
- g_free(J->repo);
- }
- delete[]DFList;
- regfree(Pattern);
- g_free(st->search);
- g_free(st);
-
- return NULL;
-}
-
-/**
- * pk_task_search
- **/
-static gboolean
-pk_task_search(PkTask * task, const gchar * filter, const gchar * search, SearchDepth which)
-{
- g_return_val_if_fail(task != NULL, FALSE);
- g_return_val_if_fail(PK_IS_TASK(task), FALSE);
-
- if (pk_task_assign(task) == FALSE)
- {
- return FALSE;
- }
-
- if (pk_task_filter_check(filter) == FALSE)
- {
- pk_task_error_code(task, PK_TASK_ERROR_CODE_FILTER_INVALID, "filter '%s' not valid", filter);
- pk_task_finished(task, PK_TASK_EXIT_FAILED);
- return TRUE;
- }
-
- search_task *data = g_new(struct search_task, 1);
- if (data == NULL)
- {
- pk_task_error_code(task, PK_TASK_ERROR_CODE_UNKNOWN, "can't allocate memory for search task");
- pk_task_finished(task, PK_TASK_EXIT_FAILED);
- }
- else
- {
- data->task = task;
- data->search = g_strdup(search);
- data->filter = g_strdup(filter);
- data->depth = which;
-
- if (g_thread_create(do_search_task, data, false, NULL) == NULL)
- {
- pk_task_error_code(task, PK_TASK_ERROR_CODE_UNKNOWN, "can't spawn thread");
- pk_task_finished(task, PK_TASK_EXIT_FAILED);
- }
- }
- return TRUE;
-}
-
-/**
- * pk_task_search_details:
- **/
-gboolean pk_task_search_details(PkTask * task, const gchar * filter, const gchar * search)
-{
- return pk_task_search(task, filter, search, SEARCH_DETAILS);
-}
-
-/**
- * pk_task_search_name:
- **/
-gboolean pk_task_search_name(PkTask * task, const gchar * filter, const gchar * search)
-{
- return pk_task_search(task, filter, search, SEARCH_NAME);
-}
-
-/**
- * pk_task_search_group:
- **/
-gboolean pk_task_search_group(PkTask * task, const gchar * filter, const gchar * search)
-{
- pk_task_not_implemented_yet(task, "SearchGroup");
- return TRUE;
-}
-
-/**
- * pk_task_search_file:
- **/
-gboolean pk_task_search_file(PkTask * task, const gchar * filter, const gchar * search)
-{
- pk_task_not_implemented_yet(task, "SearchFile");
- return TRUE;
-}
-
-/**
- * pk_task_get_depends:
- **/
-gboolean pk_task_get_depends(PkTask * task, const gchar * package)
-{
- g_return_val_if_fail(task != NULL, FALSE);
- g_return_val_if_fail(PK_IS_TASK(task), FALSE);
-
- if (pk_task_assign(task) == FALSE)
- {
- return FALSE;
- }
-
- pk_task_not_implemented_yet (task, "GetDepends");
- return FALSE;
-}
-/**
- * pk_task_get_requires:
- **/
-gboolean pk_task_get_requires(PkTask * task, const gchar * package)
-{
- g_return_val_if_fail(task != NULL, FALSE);
- g_return_val_if_fail(PK_IS_TASK(task), FALSE);
-
- if (pk_task_assign(task) == FALSE)
- {
- return FALSE;
- }
-
- pk_task_not_implemented_yet (task, "GetRequires");
- return FALSE;
-}
-
-struct desc_task
-{
- PkTask *task;
- PkPackageId *pi;
-};
-
-static GHashTable *PackageRecord(pkgCache::VerIterator V)
-{
- GHashTable *ret = NULL;
-
- pkgCache & pkgCache = *(getCache());
- // Find an appropriate file
- pkgCache::VerFileIterator Vf = V.FileList();
- for (; Vf.end() == false; Vf++)
- {
- if ((Vf.File()->Flags & pkgCache::Flag::NotSource) == 0)
- break;
- if (Vf.end() == true)
- Vf = V.FileList();
- }
-
- // Check and load the package list file
- pkgCache::PkgFileIterator I = Vf.File();
- if (I.IsOk() == false)
- return NULL;
-
- FileFd PkgF(I.FileName(),FileFd::ReadOnly);
- if (_error->PendingError() == true)
- return NULL;
-
- // Read the record
- char *Buffer = new char[pkgCache.HeaderP->MaxVerFileSize+1];
- Buffer[V.FileList()->Size] = '\0';
- if (PkgF.Seek(V.FileList()->Offset) == false ||
- PkgF.Read(Buffer,V.FileList()->Size) == false)
- {
- delete [] Buffer;
- return NULL;
- }
- //pk_debug("buffer: '%s'\n",Buffer);
- ret = g_hash_table_new_full(g_str_hash,g_str_equal,g_free,g_free);
- gchar ** lines = g_strsplit(Buffer,"\n",-1);
- guint i;
- for (i=0;i<g_strv_length(lines);i++)
- {
- gchar ** parts = g_strsplit_set(lines[i],": ",2);
- if (g_strv_length(parts)>1)
- {
- //pk_debug("entry = '%s' : '%s'",parts[0],parts[1]);
- if (parts[0][0]=='\0')
- {
- gchar *oldval = g_strdup((const gchar*)g_hash_table_lookup(ret,"Description"));
- g_hash_table_insert(ret,g_strdup("Description"),g_strconcat(oldval, "\n",parts[1],NULL));
- //pk_debug("new entry = '%s'",(const gchar*)g_hash_table_lookup(ret,"Description"));
- g_free(oldval);
- }
- else
- g_hash_table_insert(ret,g_strdup(parts[0]),g_strdup(parts[1]));
- }
- g_strfreev(parts);
- }
- g_strfreev(lines);
- return ret;
-
-}
-
-// get_desc_task
-static void *get_desc_task(gpointer data)
-{
- desc_task *dt = (desc_task *) data;
-
- pk_task_change_job_status(dt->task, PK_TASK_STATUS_QUERY);
- pk_task_no_percentage_updates(dt->task);
-
- pk_debug("finding %s", dt->pi->name);
- pkgCache & pkgCache = *(getCache());
- pkgDepCache::Policy Plcy;
-
- // Map versions that we want to write out onto the VerList array.
- for (pkgCache::PkgIterator P = pkgCache.PkgBegin(); P.end() == false; P++)
- {
- if (strcmp(dt->pi->name, P.Name())!=0)
- continue;
-
- // Find the proper version to use.
- pkgCache::VerIterator V = Plcy.GetCandidateVer(P);
- GHashTable *pkg = PackageRecord(V);
- pk_task_description(dt->task,dt->pi->name,PK_TASK_GROUP_OTHER,(const gchar*)g_hash_table_lookup(pkg,"Description"),"");
- g_hash_table_unref(pkg);
- }
- pk_task_finished(dt->task, PK_TASK_EXIT_SUCCESS);
- return NULL;
-}
-
-/**
- * pk_task_get_description:
- **/
-gboolean pk_task_get_description(PkTask * task, const gchar * package)
-{
- g_return_val_if_fail(task != NULL, FALSE);
- g_return_val_if_fail(PK_IS_TASK(task), FALSE);
-
- if (pk_task_assign(task) == FALSE)
- {
- return FALSE;
- }
-
- desc_task *data = g_new(struct desc_task, 1);
- if (data == NULL)
- {
- pk_task_error_code(task, PK_TASK_ERROR_CODE_INTERNAL_ERROR, "can't allocate memory for search task");
- pk_task_finished(task, PK_TASK_EXIT_FAILED);
- return TRUE;
- }
-
- data->task = task;
- data->pi = pk_package_id_new_from_string(package);
- if (data->pi == NULL)
- {
- pk_task_error_code(task, PK_TASK_ERROR_CODE_PACKAGE_ID_INVALID, "invalid package id");
- pk_task_finished(task, PK_TASK_EXIT_FAILED);
- return TRUE;
- }
-
- if (g_thread_create(get_desc_task, data, false, NULL) == NULL)
- {
- pk_task_error_code(task, PK_TASK_ERROR_CODE_INTERNAL_ERROR, "can't spawn thread");
- pk_task_finished(task, PK_TASK_EXIT_FAILED);
- }
- return TRUE;
-}
-
-/**
- * pk_task_remove_package:
- **/
-gboolean pk_task_remove_package(PkTask * task, const gchar * package, gboolean allow_deps)
-{
- g_return_val_if_fail(task != NULL, FALSE);
- g_return_val_if_fail(PK_IS_TASK(task), FALSE);
-
- if (pk_task_assign(task) == FALSE)
- {
- return FALSE;
- }
-
- pk_task_not_implemented_yet(task, "RemovePackage");
- return FALSE;
-}
-
-/**
- * pk_task_install_package:
- **/
-gboolean pk_task_install_package(PkTask * task, const gchar * package)
-{
- g_return_val_if_fail(task != NULL, FALSE);
- g_return_val_if_fail(PK_IS_TASK(task), FALSE);
-
- if (pk_task_assign(task) == FALSE)
- {
- return FALSE;
- }
-
- pk_task_not_implemented_yet(task, "InstallPackage");
- return FALSE;
-}
-
-/**
- * pk_task_cancel_job_try:
- **/
-gboolean pk_task_cancel_job_try(PkTask * task)
-{
- g_return_val_if_fail(task != NULL, FALSE);
- g_return_val_if_fail(PK_IS_TASK(task), FALSE);
-
- /* check to see if we have an action */
- if (task->assigned == FALSE)
- {
- pk_warning("Not assigned");
- return FALSE;
- }
-
- pk_task_not_implemented_yet (task, "CancelJobTry");
- return FALSE;
-}
-
-/**
- * pk_task_update_package:
- **/
-gboolean
-pk_task_update_package (PkTask *task, const gchar *package_id)
-{
- g_return_val_if_fail (task != NULL, FALSE);
- g_return_val_if_fail (PK_IS_TASK (task), FALSE);
-
- if (pk_task_assign (task) == FALSE) {
- return FALSE;
- }
-
- pk_task_not_implemented_yet (task, "UpdatePackage");
- return TRUE;
-}
-
-/**
- * pk_task_class_init:
- **/
-static void pk_task_class_init(PkTaskClass * klass)
-{
- GObjectClass *object_class = G_OBJECT_CLASS(klass);
-
- object_class->finalize = pk_task_finalize;
- pk_task_setup_signals(object_class, signals);
- g_type_class_add_private(klass, sizeof(PkTaskPrivate));
-}
-
-/**
- * pk_task_init:
- **/
-static void pk_task_init(PkTask * task)
-{
- task->priv = PK_TASK_GET_PRIVATE(task);
- task->priv->network = pk_network_new();
- task->signals = signals;
- pk_task_common_init(task);
-}
-
-/**
- * pk_task_finalize:
- **/
-static void pk_task_finalize(GObject * object)
-{
- PkTask *task;
- g_return_if_fail(object != NULL);
- g_return_if_fail(PK_IS_TASK(object));
- task = PK_TASK(object);
- g_return_if_fail(task->priv != NULL);
- G_OBJECT_CLASS(pk_task_parent_class)->finalize(object);
-}
-
-/**
- * pk_task_new:
- **/
-PkTask *pk_task_new(void)
-{
- PkTask *task;
- task = (PkTask *) g_object_new(PK_TYPE_TASK, NULL);
- return PK_TASK(task);
-}
-
diff-tree d94780e73a3bc9bab8110f8d7002082c6e67589b (from a442e57ccb53b710e75bca50e1cc2eeb7f5c1aef)
Author: Richard Hughes <richard at hughsie.com>
Date: Thu Sep 6 21:10:34 2007 +0100
remove the coverted box plugin
diff --git a/src/pk-task-box.c b/src/pk-task-box.c
deleted file mode 100644
index b8c934d..0000000
--- a/src/pk-task-box.c
+++ /dev/null
@@ -1,601 +0,0 @@
-/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
- *
- * Copyright (C) 2007 Grzegorz DÄ
browski <gdx at o2.pl>
- *
- * 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.
- */
-
-//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
-//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
-//!!!!! !!!!!!!!!
-//!!!!! Do not edit this file! Edit backends/$backend !!!!!!!!!
-//!!!!! !!!!!!!!!
-//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
-//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
-
-#include "config.h"
-
-#include <stdlib.h>
-#include <stdio.h>
-
-#include <string.h>
-#include <sys/types.h>
-#ifdef HAVE_UNISTD_H
-#include <unistd.h>
-#endif /* HAVE_UNISTD_H */
-
-#include <glib/gi18n.h>
-#include <dbus/dbus-glib.h>
-#include <dbus/dbus-glib-lowlevel.h>
-
-#include "pk-debug.h"
-#include "pk-task.h"
-#include "pk-task-common.h"
-#include "pk-spawn.h"
-#include "pk-network.h"
-#include "pk-package-id.h"
-
-#include <sqlite3.h>
-#include <libbox/libbox-db.h>
-#include <libbox/libbox-db-utils.h>
-#include <libbox/libbox-db-repos.h>
-
-static void pk_task_class_init (PkTaskClass *klass);
-static void pk_task_init (PkTask *task);
-static void pk_task_finalize (GObject *object);
-
-#define PK_TASK_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), PK_TYPE_TASK, PkTaskPrivate))
-
-struct PkTaskPrivate
-{
- guint progress_percentage;
- PkNetwork *network;
-};
-
-static guint signals [PK_TASK_LAST_SIGNAL] = { 0, };
-
-G_DEFINE_TYPE (PkTask, pk_task, G_TYPE_OBJECT)
-
-
-static void
-add_packages_from_list (PkTask *task, GList *list)
-{
- PackageSearch *package = NULL;
- GList *li = NULL;
- gchar *pkg_string = NULL;
-
- for (li = list; li != NULL; li = li->next) {
- package = (PackageSearch*)li->data;
- pkg_string = pk_package_id_build(package->package, package->version, package->arch, package->reponame);
-
- pk_task_package (task, package->installed, pkg_string, package->description);
-
- g_free(pkg_string);
- }
-}
-
-/* TODO: rewrite and share this code */
-static void
-parse_filter(const gchar *filter, gboolean *installed, gboolean *available, gboolean *devel,
- gboolean *nondevel, gboolean *gui, gboolean *text)
-{
- gchar **sections = NULL;
- gint i = 0;
-
- *installed = TRUE;
- *available = TRUE;
- *devel = TRUE;
- *nondevel = TRUE;
- *gui = TRUE;
- *text = TRUE;
-
- sections = g_strsplit (filter, ";", 0);
- while (sections[i]) {
- if (strcmp(sections[i], "installed") == 0)
- *available = FALSE;
- if (strcmp(sections[i], "~installed") == 0)
- *installed = FALSE;
- if (strcmp(sections[i], "devel") == 0)
- *nondevel = FALSE;
- if (strcmp(sections[i], "~devel") == 0)
- *devel = FALSE;
- if (strcmp(sections[i], "gui") == 0)
- *text = FALSE;
- if (strcmp(sections[i], "~gui") == 0)
- *gui = FALSE;
- i++;
- }
- g_strfreev (sections);
-}
-
-
-/**
- * pk_task_get_actions:
- **/
-gchar *
-pk_task_get_actions (void)
-{
- gchar *actions;
- actions = pk_task_action_build (/*PK_TASK_ACTION_INSTALL,*/
- /*PK_TASK_ACTION_REMOVE,*/
- /*PK_TASK_ACTION_UPDATE,*/
- PK_TASK_ACTION_GET_UPDATES,
- PK_TASK_ACTION_REFRESH_CACHE,
- /*PK_TASK_ACTION_UPDATE_SYSTEM,*/
- PK_TASK_ACTION_SEARCH_NAME,
- /*PK_TASK_ACTION_SEARCH_DETAILS,*/
- /*PK_TASK_ACTION_SEARCH_GROUP,*/
- PK_TASK_ACTION_SEARCH_FILE,
- /*PK_TASK_ACTION_GET_DEPENDS,*/
- /*PK_TASK_ACTION_GET_REQUIRES,*/
- PK_TASK_ACTION_GET_DESCRIPTION,
- 0);
- return actions;
-}
-
-/**
- * pk_task_get_updates:
- **/
-gboolean
-pk_task_get_updates (PkTask *task)
-{
- GList *list = NULL;
- sqlite3 *db = NULL;
-
- g_return_val_if_fail (task != NULL, FALSE);
- g_return_val_if_fail (PK_IS_TASK (task), FALSE);
-
- if (pk_task_assign (task) == FALSE) {
- return FALSE;
- }
-
- pk_task_set_job_role (task, PK_TASK_ROLE_QUERY, NULL);
- pk_task_change_job_status (task, PK_TASK_STATUS_QUERY);
-
- db = box_db_open ("/");
- box_db_attach_repo (db, "/", "core");
- box_db_repos_init (db);
-
- /* TODO: make it more async */
- list = box_db_repos_packages_for_upgrade (db);
- add_packages_from_list (task, list);
- box_db_repos_package_list_free (list);
-
- pk_task_finished (task, PK_TASK_EXIT_SUCCESS);
-
- box_db_detach_repo(db, "core");
- box_db_close(db);
-
- return TRUE;
-}
-
-/**
- * pk_task_refresh_cache:
- **/
-gboolean
-pk_task_refresh_cache (PkTask *task, gboolean force)
-{
- g_return_val_if_fail (task != NULL, FALSE);
- g_return_val_if_fail (PK_IS_TASK (task), FALSE);
-
- if (pk_task_assign (task) == FALSE) {
- return FALSE;
- }
-
- /* check network state */
- if (pk_network_is_online (task->priv->network) == FALSE) {
- pk_task_error_code (task, PK_TASK_ERROR_CODE_NO_NETWORK, "Cannot refresh cache whilst offline");
- pk_task_finished (task, PK_TASK_EXIT_FAILED);
- return TRUE;
- }
-
- /* easy as that */
- pk_task_change_job_status (task, PK_TASK_STATUS_REFRESH_CACHE);
- pk_task_spawn_helper (task, "refresh-cache.sh", NULL);
-
- return TRUE;
-}
-
-/**
- * pk_task_update_system:
- **/
-gboolean
-pk_task_update_system (PkTask *task)
-{
- g_return_val_if_fail (task != NULL, FALSE);
- g_return_val_if_fail (PK_IS_TASK (task), FALSE);
-
- if (pk_task_assign (task) == FALSE) {
- return FALSE;
- }
-
- pk_task_set_job_role (task, PK_TASK_ROLE_SYSTEM_UPDATE, NULL);
- pk_task_not_implemented_yet (task, "UpdateSystem");
- return TRUE;
-}
-
-static gboolean
-find_packages (PkTask *task, const gchar *search, const gchar *filter, gint mode)
-{
- GList *list = NULL;
- sqlite3 *db = NULL;
- gint devel_filter = 0;
- gboolean installed;
- gboolean available;
- gboolean devel;
- gboolean nondevel;
- gboolean gui;
- gboolean text;
-
- g_return_val_if_fail (task != NULL, FALSE);
- g_return_val_if_fail (PK_IS_TASK (task), FALSE);
-
- if (pk_task_assign (task) == FALSE) {
- return FALSE;
- }
- pk_task_set_job_role (task, PK_TASK_ROLE_QUERY, search);
-
- if (pk_task_filter_check (filter) == FALSE) {
- pk_task_error_code (task, PK_TASK_ERROR_CODE_FILTER_INVALID, "filter '%s' not valid", filter);
- pk_task_finished (task, PK_TASK_EXIT_FAILED);
- return TRUE;
- }
-
- parse_filter(filter, &installed, &available, &devel, &nondevel, &gui, &text);
-
- if (devel) {
- devel_filter = devel_filter | PKG_DEVEL;
- }
- if (nondevel) {
- devel_filter = devel_filter | PKG_NON_DEVEL;
- }
-
- pk_task_change_job_status (task, PK_TASK_STATUS_QUERY);
- pk_task_no_percentage_updates (task);
-
- db = box_db_open("/");
- box_db_attach_repo(db, "/", "core");
- box_db_repos_init(db);
-
- if (mode == 1) {
- /* TODO: allow filtering */
- /* TODO: make it more async */
- list = box_db_repos_search_file (db, search);
- add_packages_from_list (task, list);
- box_db_repos_package_list_free (list);
- pk_task_finished (task, PK_TASK_EXIT_SUCCESS);
- } else {
-
- if (installed == FALSE && available == FALSE) {
- pk_task_error_code (task, PK_TASK_ERROR_CODE_UNKNOWN, "invalid search mode");
- pk_task_finished (task, PK_TASK_EXIT_FAILED);
- } else {
- /* TODO: make it more async */
- if (installed == TRUE && available == TRUE) {
- list = box_db_repos_packages_search_all(db, (gchar *)search, devel_filter);
- } else if (installed == TRUE) {
- list = box_db_repos_packages_search_installed(db, (gchar *)search, devel_filter);
- } else if (available == TRUE) {
- list = box_db_repos_packages_search_available(db, (gchar *)search, devel_filter);
- }
- add_packages_from_list (task, list);
- box_db_repos_package_list_free (list);
- pk_task_finished (task, PK_TASK_EXIT_SUCCESS);
- }
- }
-
- box_db_detach_repo(db, "core");
- box_db_close(db);
-
- return TRUE;
-}
-
-static GList*
-find_package_by_id (PkPackageId *pi)
-{
- sqlite3 *db = NULL;
- GList *list;
-
- db = box_db_open("/");
- box_db_attach_repo(db, "/", "core");
- box_db_repos_init(db);
-
- // only one element is returned
- list = box_db_repos_packages_search_by_data(db, pi->name, pi->version);
- if (list == NULL)
- return NULL;
-
- box_db_detach_repo(db, "core");
- box_db_close(db);
-
- return list;
-}
-
-/**
- * pk_task_search_name:
- **/
-gboolean
-pk_task_search_name (PkTask *task, const gchar *filter, const gchar *search)
-{
- return find_packages (task, search, filter, 0);
-}
-
-/**
- * pk_task_search_details:
- **/
-gboolean
-pk_task_search_details (PkTask *task, const gchar *filter, const gchar *search)
-{
- g_return_val_if_fail (task != NULL, FALSE);
- g_return_val_if_fail (PK_IS_TASK (task), FALSE);
-
- if (pk_task_assign (task) == FALSE) {
- return FALSE;
- }
-
- pk_task_set_job_role (task, PK_TASK_ROLE_QUERY, search);
- pk_task_not_implemented_yet (task, "SearchDetails");
- return TRUE;
-}
-
-/**
- * pk_task_search_group:
- **/
-gboolean
-pk_task_search_group (PkTask *task, const gchar *filter, const gchar *search)
-{
- g_return_val_if_fail (task != NULL, FALSE);
- g_return_val_if_fail (PK_IS_TASK (task), FALSE);
-
- if (pk_task_assign (task) == FALSE) {
- return FALSE;
- }
-
- pk_task_set_job_role (task, PK_TASK_ROLE_QUERY, search);
- pk_task_not_implemented_yet (task, "SearchGroup");
- return TRUE;
-}
-
-/**
- * pk_task_search_file:
- **/
-gboolean
-pk_task_search_file (PkTask *task, const gchar *filter, const gchar *search)
-{
- return find_packages (task, search, filter, 1);
-}
-
-/**
- * pk_task_get_depends:
- **/
-gboolean
-pk_task_get_depends (PkTask *task, const gchar *package_id)
-{
- g_return_val_if_fail (task != NULL, FALSE);
- g_return_val_if_fail (PK_IS_TASK (task), FALSE);
-
- if (pk_task_assign (task) == FALSE) {
- return FALSE;
- }
-
- pk_task_set_job_role (task, PK_TASK_ROLE_QUERY, package_id);
- pk_task_not_implemented_yet (task, "GetDepends");
- return TRUE;
-}
-
-/**
- * pk_task_get_requires:
- **/
-gboolean
-pk_task_get_requires (PkTask *task, const gchar *package_id)
-{
- g_return_val_if_fail (task != NULL, FALSE);
- g_return_val_if_fail (PK_IS_TASK (task), FALSE);
-
- if (pk_task_assign (task) == FALSE) {
- return FALSE;
- }
-
- pk_task_set_job_role (task, PK_TASK_ROLE_QUERY, package_id);
- pk_task_not_implemented_yet (task, "GetRequires");
- return TRUE;
-}
-
-/**
- * pk_task_get_description:
- **/
-gboolean
-pk_task_get_description (PkTask *task, const gchar *package_id)
-{
- PkPackageId *pi;
- PackageSearch *ps;
- GList *list;
-
- g_return_val_if_fail (task != NULL, FALSE);
- g_return_val_if_fail (PK_IS_TASK (task), FALSE);
-
- if (pk_task_assign (task) == FALSE) {
- return FALSE;
- }
-
- pi = pk_package_id_new_from_string (package_id);
-
- if (pi == NULL)
- {
- pk_task_error_code (task, PK_TASK_ERROR_CODE_PACKAGE_ID_INVALID, "invalid package id");
- pk_task_finished (task, PK_TASK_EXIT_FAILED);
- return TRUE;
- }
-
- list = find_package_by_id (pi);
- ps = (PackageSearch*) list->data;
-
- if (list == NULL)
- {
- pk_task_error_code (task, PK_TASK_ERROR_CODE_PACKAGE_ID_INVALID, "cannot find package by id");
- pk_task_finished (task, PK_TASK_EXIT_FAILED);
- return TRUE;
- }
-
-
- pk_task_set_job_role (task, PK_TASK_ROLE_QUERY, package_id);
- pk_task_description (task, pi->name, PK_TASK_GROUP_OTHER, ps->description, "");
-
- pk_package_id_free (pi);
- box_db_repos_package_list_free (list);
-
- pk_task_finished (task, PK_TASK_EXIT_SUCCESS);
- return TRUE;
-}
-
-/**
- * pk_task_remove_package:
- **/
-gboolean
-pk_task_remove_package (PkTask *task, const gchar *package_id, gboolean allow_deps)
-{
- g_return_val_if_fail (task != NULL, FALSE);
- g_return_val_if_fail (PK_IS_TASK (task), FALSE);
-
- if (pk_task_assign (task) == FALSE) {
- return FALSE;
- }
-
- pk_task_set_job_role (task, PK_TASK_ROLE_PACKAGE_REMOVE, package_id);
- pk_task_not_implemented_yet (task, "RemovePackage");
- return TRUE;
-}
-
-/**
- * pk_task_install_package:
- **/
-gboolean
-pk_task_install_package (PkTask *task, const gchar *package_id)
-{
- g_return_val_if_fail (task != NULL, FALSE);
- g_return_val_if_fail (PK_IS_TASK (task), FALSE);
-
- if (pk_task_assign (task) == FALSE) {
- return FALSE;
- }
-
- /* check network state */
- if (pk_network_is_online (task->priv->network) == FALSE) {
- pk_task_error_code (task, PK_TASK_ERROR_CODE_NO_NETWORK, "Cannot install when offline");
- pk_task_finished (task, PK_TASK_EXIT_FAILED);
- return TRUE;
- }
-
- pk_task_set_job_role (task, PK_TASK_ROLE_PACKAGE_INSTALL, package_id);
- pk_task_not_implemented_yet (task, "InstallPackage");
- return TRUE;
-}
-
-/**
- * pk_task_update_package:
- **/
-gboolean
-pk_task_update_package (PkTask *task, const gchar *package_id)
-{
- g_return_val_if_fail (task != NULL, FALSE);
- g_return_val_if_fail (PK_IS_TASK (task), FALSE);
-
- if (pk_task_assign (task) == FALSE) {
- return FALSE;
- }
-
- /* check network state */
- if (pk_network_is_online (task->priv->network) == FALSE) {
- pk_task_error_code (task, PK_TASK_ERROR_CODE_NO_NETWORK, "Cannot update when offline");
- pk_task_finished (task, PK_TASK_EXIT_FAILED);
- return TRUE;
- }
-
- pk_task_set_job_role (task, PK_TASK_ROLE_PACKAGE_UPDATE, package_id);
- pk_task_not_implemented_yet (task, "UpdatePackage");
- return TRUE;
-}
-
-/**
- * pk_task_cancel_job_try:
- **/
-gboolean
-pk_task_cancel_job_try (PkTask *task)
-{
- g_return_val_if_fail (task != NULL, FALSE);
- g_return_val_if_fail (PK_IS_TASK (task), FALSE);
-
- /* check to see if we have an action */
- if (task->assigned == FALSE) {
- pk_warning ("Not assigned");
- return FALSE;
- }
-
- pk_task_not_implemented_yet (task, "CancelJobTry");
- return TRUE;
-}
-
-/**
- * pk_task_class_init:
- **/
-static void
-pk_task_class_init (PkTaskClass *klass)
-{
- GObjectClass *object_class = G_OBJECT_CLASS (klass);
-
- object_class->finalize = pk_task_finalize;
- pk_task_setup_signals (object_class, signals);
- g_type_class_add_private (klass, sizeof (PkTaskPrivate));
-}
-
-/**
- * pk_task_init:
- **/
-static void
-pk_task_init (PkTask *task)
-{
- task->priv = PK_TASK_GET_PRIVATE (task);
- task->signals = signals;
- task->priv->network = pk_network_new ();
-}
-
-/**
- * pk_task_finalize:
- **/
-static void
-pk_task_finalize (GObject *object)
-{
- PkTask *task;
- g_return_if_fail (object != NULL);
- g_return_if_fail (PK_IS_TASK (object));
- task = PK_TASK (object);
- g_return_if_fail (task->priv != NULL);
- g_object_unref (task->priv->network);
- G_OBJECT_CLASS (pk_task_parent_class)->finalize (object);
-}
-
-/**
- * pk_task_new:
- **/
-PkTask *
-pk_task_new (void)
-{
- PkTask *task;
- task = g_object_new (PK_TYPE_TASK, NULL);
- return PK_TASK (task);
-}
-
diff-tree a442e57ccb53b710e75bca50e1cc2eeb7f5c1aef (from ec3f83e71a1ecf1557d1971b563e73f6bfb2f469)
Author: Richard Hughes <richard at hughsie.com>
Date: Thu Sep 6 21:10:11 2007 +0100
remove the old dummy, yum and conary files
diff --git a/src/pk-task-conary.c b/src/pk-task-conary.c
deleted file mode 100644
index f44ed5d..0000000
--- a/src/pk-task-conary.c
+++ /dev/null
@@ -1,426 +0,0 @@
-/* -*- 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 Ken VanDine <ken at vandine.org>
- *
- * 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.
- */
-
-//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
-//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
-//!!!!! !!!!!!!!!
-//!!!!! Do not edit this file! Edit backends/$backend !!!!!!!!!
-//!!!!! !!!!!!!!!
-//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
-//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
-
-#include "config.h"
-
-#include <stdlib.h>
-#include <stdio.h>
-
-#include <string.h>
-#include <sys/types.h>
-#ifdef HAVE_UNISTD_H
-#include <unistd.h>
-#endif /* HAVE_UNISTD_H */
-
-#include <glib/gi18n.h>
-#include <dbus/dbus-glib.h>
-#include <dbus/dbus-glib-lowlevel.h>
-
-#include "pk-debug.h"
-#include "pk-task.h"
-#include "pk-task-common.h"
-#include "pk-spawn.h"
-#include "pk-network.h"
-
-static void pk_task_class_init (PkTaskClass *klass);
-static void pk_task_init (PkTask *task);
-static void pk_task_finalize (GObject *object);
-
-#define PK_TASK_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), PK_TYPE_TASK, PkTaskPrivate))
-
-struct PkTaskPrivate
-{
- gboolean whatever_you_want;
- guint progress_percentage;
- PkNetwork *network;
-};
-
-static guint signals [PK_TASK_LAST_SIGNAL] = { 0, };
-
-G_DEFINE_TYPE (PkTask, pk_task, G_TYPE_OBJECT)
-
-/**
- * pk_task_get_actions:
- **/
-gchar *
-pk_task_get_actions (void)
-{
- gchar *actions;
- actions = pk_task_action_build (PK_TASK_ACTION_INSTALL,
- PK_TASK_ACTION_REMOVE,
-/* PK_TASK_ACTION_UPDATE,*/
- PK_TASK_ACTION_GET_UPDATES,
- PK_TASK_ACTION_REFRESH_CACHE,
-/* PK_TASK_ACTION_UPDATE_SYSTEM,*/
- PK_TASK_ACTION_SEARCH_NAME,
-/* PK_TASK_ACTION_SEARCH_DETAILS,*/
-/* PK_TASK_ACTION_SEARCH_GROUP,*/
-/* PK_TASK_ACTION_SEARCH_FILE,*/
-/* PK_TASK_ACTION_GET_DEPENDS,*/
-/* PK_TASK_ACTION_GET_REQUIRES,*/
- PK_TASK_ACTION_GET_DESCRIPTION,
- 0);
- return actions;
-}
-
-/**
- * pk_task_get_updates:
- **/
-gboolean
-pk_task_get_updates (PkTask *task)
-{
- g_return_val_if_fail (task != NULL, FALSE);
- g_return_val_if_fail (PK_IS_TASK (task), FALSE);
-
- if (pk_task_assign (task) == FALSE) {
- return FALSE;
- }
-
- pk_task_set_job_role (task, PK_TASK_ROLE_QUERY, NULL);
- pk_task_spawn_helper (task, "get-updates.py", NULL);
- return TRUE;
-}
-
-/**
- * pk_task_refresh_cache:
- **/
-gboolean
-pk_task_refresh_cache (PkTask *task, gboolean force)
-{
- g_return_val_if_fail (task != NULL, FALSE);
- g_return_val_if_fail (PK_IS_TASK (task), FALSE);
-
- if (pk_task_assign (task) == FALSE) {
- return FALSE;
- }
-
- /* check network state */
- if (pk_network_is_online (task->priv->network) == FALSE) {
- pk_task_error_code (task, PK_TASK_ERROR_CODE_NO_NETWORK, "Cannot refresh cache whilst offline");
- pk_task_finished (task, PK_TASK_EXIT_FAILED);
- return TRUE;
- }
-
- /* easy as that */
- pk_task_set_job_role (task, PK_TASK_ROLE_REFRESH_CACHE, NULL);
- pk_task_spawn_helper (task, "refresh-cache.py", NULL);
-
- return TRUE;
-}
-
-/**
- * pk_task_update_system:
- **/
-gboolean
-pk_task_update_system (PkTask *task)
-{
- g_return_val_if_fail (task != NULL, FALSE);
- g_return_val_if_fail (PK_IS_TASK (task), FALSE);
-
- if (pk_task_assign (task) == FALSE) {
- return FALSE;
- }
-
- pk_task_set_job_role (task, PK_TASK_ROLE_SYSTEM_UPDATE, NULL);
- pk_task_not_implemented_yet (task, "UpdateSystem");
- return TRUE;
-}
-
-/**
- * pk_task_search_name:
- **/
-gboolean
-pk_task_search_name (PkTask *task, const gchar *filter, const gchar *search)
-{
- g_return_val_if_fail (task != NULL, FALSE);
- g_return_val_if_fail (PK_IS_TASK (task), FALSE);
-
- if (pk_task_assign (task) == FALSE) {
- return FALSE;
- }
-
- if (pk_task_filter_check (filter) == FALSE) {
- pk_task_error_code (task, PK_TASK_ERROR_CODE_FILTER_INVALID, "filter '%s' not valid", filter);
- pk_task_finished (task, PK_TASK_EXIT_FAILED);
- return TRUE;
- }
-
- pk_task_no_percentage_updates (task);
- pk_task_change_job_status (task, PK_TASK_STATUS_QUERY);
- pk_task_spawn_helper (task, "search-name.py", filter, search);
- return TRUE;
-}
-
-/**
- * pk_task_search_details:
- **/
-gboolean
-pk_task_search_details (PkTask *task, const gchar *filter, const gchar *search)
-{
- g_return_val_if_fail (task != NULL, FALSE);
- g_return_val_if_fail (PK_IS_TASK (task), FALSE);
-
- if (pk_task_assign (task) == FALSE) {
- return FALSE;
- }
-
- if (pk_task_filter_check (filter) == FALSE) {
- pk_task_error_code (task, PK_TASK_ERROR_CODE_FILTER_INVALID, "filter '%s' not valid", filter);
- pk_task_finished (task, PK_TASK_EXIT_FAILED);
- return TRUE;
- }
-
- pk_task_set_job_role (task, PK_TASK_ROLE_QUERY, search);
- pk_task_spawn_helper (task, "search-details.py", filter, search, NULL);
- return TRUE;
-}
-
-/**
- * pk_task_search_group:
- **/
-gboolean
-pk_task_search_group (PkTask *task, const gchar *filter, const gchar *search)
-{
- pk_task_set_job_role (task, PK_TASK_ROLE_QUERY, search);
- pk_task_not_implemented_yet (task, "SearchGroup");
- return TRUE;
-}
-
-/**
- * pk_task_search_file:
- **/
-gboolean
-pk_task_search_file (PkTask *task, const gchar *filter, const gchar *search)
-{
- pk_task_set_job_role (task, PK_TASK_ROLE_QUERY, search);
- pk_task_not_implemented_yet (task, "SearchFile");
- return TRUE;
-}
-
-/**
- * pk_task_get_depends:
- **/
-gboolean
-pk_task_get_depends (PkTask *task, const gchar *package_id)
-{
- g_return_val_if_fail (task != NULL, FALSE);
- g_return_val_if_fail (PK_IS_TASK (task), FALSE);
-
- if (pk_task_assign (task) == FALSE) {
- return FALSE;
- }
-
- pk_task_set_job_role (task, PK_TASK_ROLE_QUERY, package_id);
- pk_task_not_implemented_yet (task, "GetDepends");
- return TRUE;
-}
-
-/**
- * pk_task_get_requires:
- **/
-gboolean
-pk_task_get_requires (PkTask *task, const gchar *package_id)
-{
- g_return_val_if_fail (task != NULL, FALSE);
- g_return_val_if_fail (PK_IS_TASK (task), FALSE);
-
- if (pk_task_assign (task) == FALSE) {
- return FALSE;
- }
-
- pk_task_set_job_role (task, PK_TASK_ROLE_QUERY, package_id);
- pk_task_not_implemented_yet (task, "GetRequires");
- return TRUE;
-}
-
-/**
- * pk_task_get_description:
- **/
-gboolean
-pk_task_get_description (PkTask *task, const gchar *package_id)
-{
- g_return_val_if_fail (task != NULL, FALSE);
- g_return_val_if_fail (PK_IS_TASK (task), FALSE);
-
- if (pk_task_assign (task) == FALSE) {
- return FALSE;
- }
-
- /* only copy this code if you can kill the process with no ill effect */
- pk_task_allow_interrupt (task, TRUE);
-
- pk_task_set_job_role (task, PK_TASK_ROLE_QUERY, package_id);
- pk_task_spawn_helper (task, "get-description.py", package_id, NULL);
- return TRUE;
-}
-
-/**
- * pk_task_remove_package:
- **/
-gboolean
-pk_task_remove_package (PkTask *task, const gchar *package_id, gboolean allow_deps)
-{
- const gchar *deps;
- g_return_val_if_fail (task != NULL, FALSE);
- g_return_val_if_fail (PK_IS_TASK (task), FALSE);
-
- if (pk_task_assign (task) == FALSE) {
- return FALSE;
- }
-
- if (allow_deps == TRUE) {
- deps = "yes";
- } else {
- deps = "no";
- }
-
- pk_task_set_job_role (task, PK_TASK_ROLE_PACKAGE_REMOVE, package_id);
- pk_task_spawn_helper (task, "remove.py", deps, package_id, NULL);
- return TRUE;
-}
-/**
- * pk_task_install_package:
- **/
-gboolean
-pk_task_install_package (PkTask *task, const gchar *package_id)
-{
- g_return_val_if_fail (task != NULL, FALSE);
- g_return_val_if_fail (PK_IS_TASK (task), FALSE);
-
- if (pk_task_assign (task) == FALSE) {
- return FALSE;
- }
-
- /* check network state */
- if (pk_network_is_online (task->priv->network) == FALSE) {
- pk_task_error_code (task, PK_TASK_ERROR_CODE_NO_NETWORK, "Cannot install when offline");
- pk_task_finished (task, PK_TASK_EXIT_FAILED);
- return TRUE;
- }
-
- pk_task_set_job_role (task, PK_TASK_ROLE_PACKAGE_INSTALL, package_id);
- pk_task_spawn_helper (task, "install.py", package_id, NULL);
- return TRUE;
-}
-
-/**
- * pk_task_update_package:
- **/
-gboolean
-pk_task_update_package (PkTask *task, const gchar *package_id)
-{
- g_return_val_if_fail (task != NULL, FALSE);
- g_return_val_if_fail (PK_IS_TASK (task), FALSE);
-
- if (pk_task_assign (task) == FALSE) {
- return FALSE;
- }
-
- /* check network state */
- if (pk_network_is_online (task->priv->network) == FALSE) {
- pk_task_error_code (task, PK_TASK_ERROR_CODE_NO_NETWORK, "Cannot update when offline");
- pk_task_finished (task, PK_TASK_EXIT_FAILED);
- return TRUE;
- }
-
- pk_task_set_job_role (task, PK_TASK_ROLE_PACKAGE_UPDATE, package_id);
- pk_task_not_implemented_yet (task, "UpdatePackage");
- return TRUE;
-}
-
-/**
- * pk_task_cancel_job_try:
- **/
-gboolean
-pk_task_cancel_job_try (PkTask *task)
-{
- g_return_val_if_fail (task != NULL, FALSE);
- g_return_val_if_fail (PK_IS_TASK (task), FALSE);
-
- /* check to see if we have an action */
- if (task->assigned == FALSE) {
- pk_warning ("Not assigned");
- return FALSE;
- }
-
- pk_task_not_implemented_yet (task, "CancelJobTry");
- return TRUE;
-}
-
-/**
- * pk_task_class_init:
- **/
-static void
-pk_task_class_init (PkTaskClass *klass)
-{
- GObjectClass *object_class = G_OBJECT_CLASS (klass);
-
- object_class->finalize = pk_task_finalize;
- pk_task_setup_signals (object_class, signals);
- g_type_class_add_private (klass, sizeof (PkTaskPrivate));
-}
-
-/**
- * pk_task_init:
- **/
-static void
-pk_task_init (PkTask *task)
-{
- task->priv = PK_TASK_GET_PRIVATE (task);
- task->signals = signals;
- task->priv->network = pk_network_new ();
-}
-
-/**
- * pk_task_finalize:
- **/
-static void
-pk_task_finalize (GObject *object)
-{
- PkTask *task;
- g_return_if_fail (object != NULL);
- g_return_if_fail (PK_IS_TASK (object));
- task = PK_TASK (object);
- g_return_if_fail (task->priv != NULL);
- g_object_unref (task->priv->network);
- G_OBJECT_CLASS (pk_task_parent_class)->finalize (object);
-}
-
-/**
- * pk_task_new:
- **/
-PkTask *
-pk_task_new (void)
-{
- PkTask *task;
- task = g_object_new (PK_TYPE_TASK, NULL);
- return PK_TASK (task);
-}
-
diff --git a/src/pk-task-dummy.c b/src/pk-task-dummy.c
deleted file mode 100644
index 3c73530..0000000
--- a/src/pk-task-dummy.c
+++ /dev/null
@@ -1,456 +0,0 @@
-/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
- *
- * 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.
- *
- * 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.
- */
-
-//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
-//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
-//!!!!! !!!!!!!!!
-//!!!!! Do not edit this file! Edit backends/$backend !!!!!!!!!
-//!!!!! !!!!!!!!!
-//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
-//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
-
-#include "config.h"
-
-#include <stdlib.h>
-#include <stdio.h>
-
-#include <string.h>
-#include <sys/types.h>
-#ifdef HAVE_UNISTD_H
-#include <unistd.h>
-#endif /* HAVE_UNISTD_H */
-
-#include <glib/gi18n.h>
-#include <dbus/dbus-glib.h>
-#include <dbus/dbus-glib-lowlevel.h>
-
-#include "pk-debug.h"
-#include "pk-task.h"
-#include "pk-task-common.h"
-
-static void pk_task_class_init (PkTaskClass *klass);
-static void pk_task_init (PkTask *task);
-static void pk_task_finalize (GObject *object);
-
-#define PK_TASK_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), PK_TYPE_TASK, PkTaskPrivate))
-
-struct PkTaskPrivate
-{
- guint progress_percentage;
-};
-
-static guint signals [PK_TASK_LAST_SIGNAL] = { 0, };
-
-G_DEFINE_TYPE (PkTask, pk_task, G_TYPE_OBJECT)
-
-/**
- * pk_task_get_actions:
- **/
-gchar *
-pk_task_get_actions (void)
-{
- gchar *actions;
- actions = pk_task_action_build (PK_TASK_ACTION_INSTALL,
- PK_TASK_ACTION_REMOVE,
- PK_TASK_ACTION_UPDATE,
- PK_TASK_ACTION_GET_UPDATES,
- PK_TASK_ACTION_REFRESH_CACHE,
- PK_TASK_ACTION_UPDATE_SYSTEM,
- PK_TASK_ACTION_SEARCH_NAME,
- PK_TASK_ACTION_SEARCH_DETAILS,
- PK_TASK_ACTION_SEARCH_GROUP,
- PK_TASK_ACTION_SEARCH_FILE,
- PK_TASK_ACTION_GET_DEPENDS,
- PK_TASK_ACTION_GET_REQUIRES,
- PK_TASK_ACTION_GET_DESCRIPTION,
- 0);
- return actions;
-}
-
-/**
- * pk_task_get_updates:
- **/
-gboolean
-pk_task_get_updates (PkTask *task)
-{
- g_return_val_if_fail (task != NULL, FALSE);
- g_return_val_if_fail (PK_IS_TASK (task), FALSE);
-
- if (pk_task_assign (task) == FALSE) {
- return FALSE;
- }
-
- pk_task_set_job_role (task, PK_TASK_ROLE_QUERY, NULL);
- pk_task_package (task, 0, "powertop;1.8-1.fc8;i386;fedora",
- "Power consumption monitor");
- pk_task_package (task, 1, "kernel;2.6.23-0.115.rc3.git1.fc8;i386;installed",
- "The Linux kernel (the core of the Linux operating system)");
- pk_task_package (task, 1, "gtkhtml2;2.19.1-4.fc8;i386;fedora", "An HTML widget for GTK+ 2.0");
- pk_task_finished (task, PK_TASK_EXIT_SUCCESS);
- return TRUE;
-}
-
-/**
- * pk_task_refresh_cache:
- **/
-gboolean
-pk_task_refresh_cache (PkTask *task, gboolean force)
-{
- g_return_val_if_fail (task != NULL, FALSE);
- g_return_val_if_fail (PK_IS_TASK (task), FALSE);
-
- if (pk_task_assign (task) == FALSE) {
- return FALSE;
- }
-
- pk_task_set_job_role (task, PK_TASK_ROLE_REFRESH_CACHE, NULL);
- pk_task_finished (task, PK_TASK_EXIT_SUCCESS);
- return TRUE;
-}
-
-static gboolean
-pk_task_update_system_timeout (gpointer data)
-{
- PkTask *task = (PkTask *) data;
- if (task->priv->progress_percentage == 100) {
- pk_task_finished (task, PK_TASK_EXIT_SUCCESS);
- return FALSE;
- }
- pk_task_change_job_status (task, PK_TASK_STATUS_UPDATE);
- task->priv->progress_percentage += 10;
- pk_task_change_percentage (task, task->priv->progress_percentage);
- return TRUE;
-}
-
-
-/**
- * pk_task_update_system:
- **/
-gboolean
-pk_task_update_system (PkTask *task)
-{
- g_return_val_if_fail (task != NULL, FALSE);
- g_return_val_if_fail (PK_IS_TASK (task), FALSE);
-
- if (pk_task_assign (task) == FALSE) {
- return FALSE;
- }
-
- pk_task_set_job_role (task, PK_TASK_ROLE_SYSTEM_UPDATE, NULL);
- pk_task_change_job_status (task, PK_TASK_STATUS_DOWNLOAD);
- task->priv->progress_percentage = 0;
- pk_task_require_restart (task, PK_TASK_RESTART_SYSTEM, NULL);
- g_timeout_add (1000, pk_task_update_system_timeout, task);
-
- return TRUE;
-}
-
-/**
- * pk_task_search_name_timeout:
- **/
-gboolean
-pk_task_search_name_timeout (gpointer data)
-{
- PkTask *task = (PkTask *) data;
- pk_task_package (task, 1, "evince;0.9.3-5.fc8;i386;installed",
- "PDF Document viewer");
- pk_task_package (task, 1, "tetex;3.0-41.fc8;i386;fedora",
- "TeTeX is an implementation of TeX for Linux or UNIX systems.");
- pk_task_package (task, 0, "scribus;1.3.4-1.fc8;i386;fedora",
- "Scribus is an desktop open source page layout program");
- pk_task_package (task, 0, "vips-doc;7.12.4-2.fc8;noarch;linva",
- "The vips documentation package.");
- pk_task_finished (task, PK_TASK_EXIT_SUCCESS);
- return FALSE;
-}
-
-/**
- * pk_task_search_name:
- **/
-gboolean
-pk_task_search_name (PkTask *task, const gchar *filter, const gchar *search)
-{
- g_return_val_if_fail (task != NULL, FALSE);
- g_return_val_if_fail (PK_IS_TASK (task), FALSE);
-
- if (pk_task_assign (task) == FALSE) {
- return FALSE;
- }
-
- pk_task_set_job_role (task, PK_TASK_ROLE_QUERY, search);
- pk_task_no_percentage_updates (task);
-
- g_timeout_add (2000, pk_task_search_name_timeout, task);
- return TRUE;
-}
-
-/**
- * pk_task_search_details:
- **/
-gboolean
-pk_task_search_details (PkTask *task, const gchar *filter, const gchar *search)
-{
- pk_task_set_job_role (task, PK_TASK_ROLE_QUERY, search);
- pk_task_package (task, 0, "vips-doc;7.12.4-2.fc8;noarch;linva",
- "The vips documentation package.");
- pk_task_finished (task, PK_TASK_EXIT_SUCCESS);
- return TRUE;
-}
-
-/**
- * pk_task_search_group:
- **/
-gboolean
-pk_task_search_group (PkTask *task, const gchar *filter, const gchar *search)
-{
- pk_task_set_job_role (task, PK_TASK_ROLE_QUERY, search);
- pk_task_package (task, 0, "vips-doc;7.12.4-2.fc8;noarch;linva",
- "The vips documentation package.");
- pk_task_finished (task, PK_TASK_EXIT_SUCCESS);
- return TRUE;
-}
-
-/**
- * pk_task_search_file:
- **/
-gboolean
-pk_task_search_file (PkTask *task, const gchar *filter, const gchar *search)
-{
- pk_task_set_job_role (task, PK_TASK_ROLE_QUERY, search);
- pk_task_package (task, 0, "vips-doc;7.12.4-2.fc8;noarch;linva",
- "The vips documentation package.");
- pk_task_finished (task, PK_TASK_EXIT_SUCCESS);
- return TRUE;
-}
-
-/**
- * pk_task_get_depends:
- **/
-gboolean
-pk_task_get_depends (PkTask *task, const gchar *package_id)
-{
- g_return_val_if_fail (task != NULL, FALSE);
- g_return_val_if_fail (PK_IS_TASK (task), FALSE);
-
- if (pk_task_assign (task) == FALSE) {
- return FALSE;
- }
-
- pk_task_set_job_role (task, PK_TASK_ROLE_QUERY, package_id);
- pk_task_package (task, 1, "glib2;2.14.0;i386;fedora",
- "The GLib library");
- pk_task_package (task, 1, "gtk2;gtk2-2.11.6-6.fc8;i386;fedora",
- "GTK+ Libraries for GIMP");
- pk_task_finished (task, PK_TASK_EXIT_SUCCESS);
-
- return TRUE;
-}
-
-/**
- * pk_task_get_requires:
- **/
-gboolean
-pk_task_get_requires (PkTask *task, const gchar *package_id)
-{
- g_return_val_if_fail (task != NULL, FALSE);
- g_return_val_if_fail (PK_IS_TASK (task), FALSE);
-
- if (pk_task_assign (task) == FALSE) {
- return FALSE;
- }
-
- pk_task_set_job_role (task, PK_TASK_ROLE_QUERY, package_id);
- pk_task_package (task, 1, "glib2;2.14.0;i386;fedora",
- "The GLib library");
- pk_task_package (task, 1, "gtk2;gtk2-2.11.6-6.fc8;i386;fedora",
- "GTK+ Libraries for GIMP");
- pk_task_finished (task, PK_TASK_EXIT_SUCCESS);
-
- return TRUE;
-}
-
-/**
- * pk_task_get_description:
- **/
-gboolean
-pk_task_get_description (PkTask *task, const gchar *package_id)
-{
- g_return_val_if_fail (task != NULL, FALSE);
- g_return_val_if_fail (PK_IS_TASK (task), FALSE);
-
- if (pk_task_assign (task) == FALSE) {
- return FALSE;
- }
-
- pk_task_set_job_role (task, PK_TASK_ROLE_QUERY, package_id);
- pk_task_description (task, "gnome-power-manager;2.6.19;i386;fedora", PK_TASK_GROUP_PROGRAMMING,
-"Scribus is an desktop open source page layout program with "
-"the aim of producing commercial grade output in PDF and "
-"Postscript, primarily, though not exclusively for Linux.\n"
-"\n"
-"While the goals of the program are for ease of use and simple easy to "
-"understand tools, Scribus offers support for professional publishing "
-"features, such as CMYK color, easy PDF creation, Encapsulated Postscript "
-"import/export and creation of color separations.", "http://live.gnome.org/GnomePowerManager");
- pk_task_finished (task, PK_TASK_EXIT_SUCCESS);
-
- return TRUE;
-}
-
-/**
- * pk_task_remove_package:
- **/
-gboolean
-pk_task_remove_package (PkTask *task, const gchar *package_id, gboolean allow_deps)
-{
- g_return_val_if_fail (task != NULL, FALSE);
- g_return_val_if_fail (PK_IS_TASK (task), FALSE);
-
- if (pk_task_assign (task) == FALSE) {
- return FALSE;
- }
-
- pk_task_set_job_role (task, PK_TASK_ROLE_PACKAGE_REMOVE, package_id);
- pk_task_error_code (task, PK_TASK_ERROR_CODE_NO_NETWORK, "No network connection available");
- pk_task_finished (task, PK_TASK_EXIT_FAILED);
-
- return TRUE;
-}
-
-static gboolean
-pk_task_install_timeout (gpointer data)
-{
- PkTask *task = (PkTask *) data;
- if (task->priv->progress_percentage == 100) {
- pk_task_finished (task, PK_TASK_EXIT_SUCCESS);
- return FALSE;
- }
- if (task->priv->progress_percentage == 50) {
- pk_task_change_job_status (task, PK_TASK_STATUS_INSTALL);
- }
- task->priv->progress_percentage += 10;
- pk_task_change_percentage (task, task->priv->progress_percentage);
- return TRUE;
-}
-
-/**
- * pk_task_install_package:
- **/
-gboolean
-pk_task_install_package (PkTask *task, const gchar *package_id)
-{
- g_return_val_if_fail (task != NULL, FALSE);
- g_return_val_if_fail (PK_IS_TASK (task), FALSE);
-
- if (pk_task_assign (task) == FALSE) {
- return FALSE;
- }
-
- pk_task_set_job_role (task, PK_TASK_ROLE_PACKAGE_INSTALL, package_id);
- task->priv->progress_percentage = 0;
- g_timeout_add (1000, pk_task_install_timeout, task);
- return TRUE;
-}
-
-/**
- * pk_task_update_package:
- **/
-gboolean
-pk_task_update_package (PkTask *task, const gchar *package_id)
-{
- g_return_val_if_fail (task != NULL, FALSE);
- g_return_val_if_fail (PK_IS_TASK (task), FALSE);
-
- if (pk_task_assign (task) == FALSE) {
- return FALSE;
- }
-
- pk_task_set_job_role (task, PK_TASK_ROLE_PACKAGE_UPDATE, package_id);
- pk_task_package (task, 1, package_id, "The same thing");
- pk_task_finished (task, PK_TASK_EXIT_SUCCESS);
- return TRUE;
-}
-
-/**
- * pk_task_cancel_job_try:
- **/
-gboolean
-pk_task_cancel_job_try (PkTask *task)
-{
- g_return_val_if_fail (task != NULL, FALSE);
- g_return_val_if_fail (PK_IS_TASK (task), FALSE);
-
- /* check to see if we have an action */
- if (task->assigned == FALSE) {
- pk_warning ("Not assigned");
- return FALSE;
- }
- return TRUE;
-}
-
-/**
- * pk_task_class_init:
- **/
-static void
-pk_task_class_init (PkTaskClass *klass)
-{
- GObjectClass *object_class = G_OBJECT_CLASS (klass);
-
- object_class->finalize = pk_task_finalize;
- pk_task_setup_signals (object_class, signals);
- g_type_class_add_private (klass, sizeof (PkTaskPrivate));
-}
-
-/**
- * pk_task_init:
- **/
-static void
-pk_task_init (PkTask *task)
-{
- task->priv = PK_TASK_GET_PRIVATE (task);
- task->signals = signals;
-}
-
-/**
- * pk_task_finalize:
- **/
-static void
-pk_task_finalize (GObject *object)
-{
- PkTask *task;
- g_return_if_fail (object != NULL);
- g_return_if_fail (PK_IS_TASK (object));
- task = PK_TASK (object);
- g_return_if_fail (task->priv != NULL);
- G_OBJECT_CLASS (pk_task_parent_class)->finalize (object);
-}
-
-/**
- * pk_task_new:
- **/
-PkTask *
-pk_task_new (void)
-{
- PkTask *task;
- task = g_object_new (PK_TYPE_TASK, NULL);
- return PK_TASK (task);
-}
-
diff --git a/src/pk-task-yum.c b/src/pk-task-yum.c
deleted file mode 100644
index e2f9537..0000000
--- a/src/pk-task-yum.c
+++ /dev/null
@@ -1,476 +0,0 @@
-/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
- *
- * 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.
- *
- * 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.
- */
-
-//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
-//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
-//!!!!! !!!!!!!!!
-//!!!!! Do not edit this file! Edit backends/$backend !!!!!!!!!
-//!!!!! !!!!!!!!!
-//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
-//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
-
-#include "config.h"
-
-#include <stdlib.h>
-#include <stdio.h>
-
-#include <string.h>
-#include <sys/types.h>
-#ifdef HAVE_UNISTD_H
-#include <unistd.h>
-#endif /* HAVE_UNISTD_H */
-
-#include <glib/gi18n.h>
-#include <dbus/dbus-glib.h>
-#include <dbus/dbus-glib-lowlevel.h>
-
-#include "pk-debug.h"
-#include "pk-task.h"
-#include "pk-task-common.h"
-#include "pk-spawn.h"
-#include "pk-network.h"
-
-static void pk_task_class_init (PkTaskClass *klass);
-static void pk_task_init (PkTask *task);
-static void pk_task_finalize (GObject *object);
-
-#define PK_TASK_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), PK_TYPE_TASK, PkTaskPrivate))
-
-struct PkTaskPrivate
-{
- gboolean whatever_you_want;
- guint progress_percentage;
- PkNetwork *network;
-};
-
-static guint signals [PK_TASK_LAST_SIGNAL] = { 0, };
-
-G_DEFINE_TYPE (PkTask, pk_task, G_TYPE_OBJECT)
-
-/**
- * pk_task_get_actions:
- **/
-gchar *
-pk_task_get_actions (void)
-{
- gchar *actions;
- actions = pk_task_action_build (PK_TASK_ACTION_INSTALL,
- PK_TASK_ACTION_REMOVE,
- PK_TASK_ACTION_UPDATE,
- PK_TASK_ACTION_GET_UPDATES,
- PK_TASK_ACTION_REFRESH_CACHE,
- PK_TASK_ACTION_UPDATE_SYSTEM,
- PK_TASK_ACTION_SEARCH_NAME,
- PK_TASK_ACTION_SEARCH_DETAILS,
- PK_TASK_ACTION_SEARCH_GROUP,
- PK_TASK_ACTION_SEARCH_FILE,
- PK_TASK_ACTION_GET_DEPENDS,
- PK_TASK_ACTION_GET_REQUIRES,
- PK_TASK_ACTION_GET_DESCRIPTION,
- 0);
- return actions;
-}
-
-/**
- * pk_task_get_updates:
- **/
-gboolean
-pk_task_get_updates (PkTask *task)
-{
- g_return_val_if_fail (task != NULL, FALSE);
- g_return_val_if_fail (PK_IS_TASK (task), FALSE);
-
- if (pk_task_assign (task) == FALSE) {
- return FALSE;
- }
-
- pk_task_set_job_role (task, PK_TASK_ROLE_QUERY, NULL);
- pk_task_spawn_helper (task, "get-updates.py", NULL);
- return TRUE;
-}
-
-/**
- * pk_task_refresh_cache:
- **/
-gboolean
-pk_task_refresh_cache (PkTask *task, gboolean force)
-{
- g_return_val_if_fail (task != NULL, FALSE);
- g_return_val_if_fail (PK_IS_TASK (task), FALSE);
-
- if (pk_task_assign (task) == FALSE) {
- return FALSE;
- }
-
- /* check network state */
- if (pk_network_is_online (task->priv->network) == FALSE) {
- pk_task_error_code (task, PK_TASK_ERROR_CODE_NO_NETWORK, "Cannot refresh cache whilst offline");
- pk_task_finished (task, PK_TASK_EXIT_FAILED);
- return TRUE;
- }
-
- /* easy as that */
- pk_task_set_job_role (task, PK_TASK_ROLE_REFRESH_CACHE, NULL);
- pk_task_spawn_helper (task, "refresh-cache.py", NULL);
-
- return TRUE;
-}
-
-/**
- * pk_task_update_system:
- **/
-gboolean
-pk_task_update_system (PkTask *task)
-{
- g_return_val_if_fail (task != NULL, FALSE);
- g_return_val_if_fail (PK_IS_TASK (task), FALSE);
-
- if (pk_task_assign (task) == FALSE) {
- return FALSE;
- }
-
- pk_task_set_job_role (task, PK_TASK_ROLE_SYSTEM_UPDATE, NULL);
- pk_task_spawn_helper (task, "update-system.py", NULL);
- return TRUE;
-}
-
-/**
- * pk_task_search_name:
- **/
-gboolean
-pk_task_search_name (PkTask *task, const gchar *filter, const gchar *search)
-{
- g_return_val_if_fail (task != NULL, FALSE);
- g_return_val_if_fail (PK_IS_TASK (task), FALSE);
-
- if (pk_task_assign (task) == FALSE) {
- return FALSE;
- }
-
- /* only copy this code if you can kill the process with no ill effect */
- pk_task_allow_interrupt (task, TRUE);
-
- pk_task_no_percentage_updates (task);
- pk_task_set_job_role (task, PK_TASK_ROLE_QUERY, search);
- pk_task_spawn_helper (task, "search-name.py", filter, search, NULL);
- return TRUE;
-}
-
-/**
- * pk_task_search_details:
- **/
-gboolean
-pk_task_search_details (PkTask *task, const gchar *filter, const gchar *search)
-{
- g_return_val_if_fail (task != NULL, FALSE);
- g_return_val_if_fail (PK_IS_TASK (task), FALSE);
-
- if (pk_task_assign (task) == FALSE) {
- return FALSE;
- }
-
- if (pk_task_filter_check (filter) == FALSE) {
- pk_task_error_code (task, PK_TASK_ERROR_CODE_FILTER_INVALID, "filter '%s' not valid", filter);
- pk_task_finished (task, PK_TASK_EXIT_FAILED);
- return TRUE;
- }
-
- /* only copy this code if you can kill the process with no ill effect */
- pk_task_allow_interrupt (task, TRUE);
-
- pk_task_set_job_role (task, PK_TASK_ROLE_QUERY, search);
- pk_task_spawn_helper (task, "search-details.py", filter, search, NULL);
- return TRUE;
-}
-
-/**
- * pk_task_search_group:
- **/
-gboolean
-pk_task_search_group (PkTask *task, const gchar *filter, const gchar *search)
-{
- g_return_val_if_fail (task != NULL, FALSE);
- g_return_val_if_fail (PK_IS_TASK (task), FALSE);
-
- if (pk_task_filter_check (filter) == FALSE) {
- pk_task_error_code (task, PK_TASK_ERROR_CODE_FILTER_INVALID, "filter '%s' not valid", filter);
- pk_task_finished (task, PK_TASK_EXIT_FAILED);
- return TRUE;
- }
-
- if (pk_task_assign (task) == FALSE) {
- return FALSE;
- }
-
- /* only copy this code if you can kill the process with no ill effect */
- pk_task_allow_interrupt (task, TRUE);
-
- pk_task_set_job_role (task, PK_TASK_ROLE_QUERY, search);
- pk_task_spawn_helper (task, "search-group.py", filter, search, NULL);
- return TRUE;
-}
-
-/**
- * pk_task_search_file:
- **/
-gboolean
-pk_task_search_file (PkTask *task, const gchar *filter, const gchar *search)
-{
- g_return_val_if_fail (task != NULL, FALSE);
- g_return_val_if_fail (PK_IS_TASK (task), FALSE);
-
- if (pk_task_filter_check (filter) == FALSE) {
- pk_task_error_code (task, PK_TASK_ERROR_CODE_FILTER_INVALID, "filter '%s' not valid", filter);
- pk_task_finished (task, PK_TASK_EXIT_FAILED);
- return TRUE;
- }
-
- if (pk_task_assign (task) == FALSE) {
- return FALSE;
- }
-
- /* only copy this code if you can kill the process with no ill effect */
- pk_task_allow_interrupt (task, TRUE);
- pk_task_set_job_role (task, PK_TASK_ROLE_QUERY, search);
-
- pk_task_not_implemented_yet (task, "SearchFile");
- return TRUE;
-}
-
-/**
- * pk_task_get_depends:
- **/
-gboolean
-pk_task_get_depends (PkTask *task, const gchar *package_id)
-{
- g_return_val_if_fail (task != NULL, FALSE);
- g_return_val_if_fail (PK_IS_TASK (task), FALSE);
-
- if (pk_task_assign (task) == FALSE) {
- return FALSE;
- }
-
- /* only copy this code if you can kill the process with no ill effect */
- pk_task_allow_interrupt (task, TRUE);
-
- pk_task_set_job_role (task, PK_TASK_ROLE_QUERY, package_id);
- pk_task_spawn_helper (task, "get-depends.py", package_id, NULL);
- return TRUE;
-}
-
-/**
- * pk_task_get_requires:
- **/
-gboolean
-pk_task_get_requires (PkTask *task, const gchar *package_id)
-{
- g_return_val_if_fail (task != NULL, FALSE);
- g_return_val_if_fail (PK_IS_TASK (task), FALSE);
-
- if (pk_task_assign (task) == FALSE) {
- return FALSE;
- }
-
- /* only copy this code if you can kill the process with no ill effect */
- pk_task_allow_interrupt (task, TRUE);
-
- pk_task_set_job_role (task, PK_TASK_ROLE_QUERY, package_id);
- pk_task_spawn_helper (task, "get-requires.py", package_id, NULL);
- return TRUE;
-}
-
-/**
- * pk_task_get_description:
- **/
-gboolean
-pk_task_get_description (PkTask *task, const gchar *package_id)
-{
- g_return_val_if_fail (task != NULL, FALSE);
- g_return_val_if_fail (PK_IS_TASK (task), FALSE);
-
- if (pk_task_assign (task) == FALSE) {
- return FALSE;
- }
-
- /* only copy this code if you can kill the process with no ill effect */
- pk_task_allow_interrupt (task, TRUE);
-
- pk_task_set_job_role (task, PK_TASK_ROLE_QUERY, package_id);
- pk_task_spawn_helper (task, "get-description.py", package_id, NULL);
- return TRUE;
-}
-
-/**
- * pk_task_remove_package:
- **/
-gboolean
-pk_task_remove_package (PkTask *task, const gchar *package_id, gboolean allow_deps)
-{
- const gchar *deps;
- g_return_val_if_fail (task != NULL, FALSE);
- g_return_val_if_fail (PK_IS_TASK (task), FALSE);
-
- if (pk_task_assign (task) == FALSE) {
- return FALSE;
- }
-
- if (allow_deps == TRUE) {
- deps = "yes";
- } else {
- deps = "no";
- }
-
- pk_task_set_job_role (task, PK_TASK_ROLE_PACKAGE_REMOVE, package_id);
- pk_task_spawn_helper (task, "remove.py", deps, package_id, NULL);
- return TRUE;
-}
-
-/**
- * pk_task_install_package:
- **/
-gboolean
-pk_task_install_package (PkTask *task, const gchar *package_id)
-{
- g_return_val_if_fail (task != NULL, FALSE);
- g_return_val_if_fail (PK_IS_TASK (task), FALSE);
-
- if (pk_task_assign (task) == FALSE) {
- return FALSE;
- }
-
- /* check network state */
- if (pk_network_is_online (task->priv->network) == FALSE) {
- pk_task_error_code (task, PK_TASK_ERROR_CODE_NO_NETWORK, "Cannot install when offline");
- pk_task_finished (task, PK_TASK_EXIT_FAILED);
- return TRUE;
- }
-
- pk_task_set_job_role (task, PK_TASK_ROLE_PACKAGE_INSTALL, package_id);
- pk_task_spawn_helper (task, "install.py", package_id, NULL);
- return TRUE;
-}
-
-/**
- * pk_task_update_package:
- **/
-gboolean
-pk_task_update_package (PkTask *task, const gchar *package_id)
-{
- g_return_val_if_fail (task != NULL, FALSE);
- g_return_val_if_fail (PK_IS_TASK (task), FALSE);
-
- if (pk_task_assign (task) == FALSE) {
- return FALSE;
- }
-
- /* check network state */
- if (pk_network_is_online (task->priv->network) == FALSE) {
- pk_task_error_code (task, PK_TASK_ERROR_CODE_NO_NETWORK, "Cannot update when offline");
- pk_task_finished (task, PK_TASK_EXIT_FAILED);
- return TRUE;
- }
-
- pk_task_set_job_role (task, PK_TASK_ROLE_PACKAGE_UPDATE, package_id);
- pk_task_spawn_helper (task, "update.py", package_id, NULL);
- return TRUE;
-}
-
-/**
- * pk_task_cancel_job_try:
- **/
-gboolean
-pk_task_cancel_job_try (PkTask *task)
-{
- gboolean ret;
-
- g_return_val_if_fail (task != NULL, FALSE);
- g_return_val_if_fail (PK_IS_TASK (task), FALSE);
-
- /* check to see if we have an action */
- if (task->assigned == FALSE) {
- pk_warning ("Not assigned");
- return FALSE;
- }
-
- /* check if it's safe to kill */
- if (task->is_killable == FALSE) {
- pk_warning ("tried to kill a process that is not safe to kill");
- return TRUE;
- }
- if (task->spawn == NULL) {
- pk_warning ("tried to kill a process that does not exist");
- return TRUE;
- }
-
- /* this feels bad... */
- ret = pk_spawn_kill (task->spawn);
- return ret;
-}
-
-/**
- * pk_task_class_init:
- **/
-static void
-pk_task_class_init (PkTaskClass *klass)
-{
- GObjectClass *object_class = G_OBJECT_CLASS (klass);
-
- object_class->finalize = pk_task_finalize;
- pk_task_setup_signals (object_class, signals);
- g_type_class_add_private (klass, sizeof (PkTaskPrivate));
-}
-
-/**
- * pk_task_init:
- **/
-static void
-pk_task_init (PkTask *task)
-{
- task->priv = PK_TASK_GET_PRIVATE (task);
- task->signals = signals;
- task->priv->network = pk_network_new ();
-}
-
-/**
- * pk_task_finalize:
- **/
-static void
-pk_task_finalize (GObject *object)
-{
- PkTask *task;
- g_return_if_fail (object != NULL);
- g_return_if_fail (PK_IS_TASK (object));
- task = PK_TASK (object);
- g_return_if_fail (task->priv != NULL);
- G_OBJECT_CLASS (pk_task_parent_class)->finalize (object);
-}
-
-/**
- * pk_task_new:
- **/
-PkTask *
-pk_task_new (void)
-{
- PkTask *task;
- task = g_object_new (PK_TYPE_TASK, NULL);
- return PK_TASK (task);
-}
-
diff-tree ec3f83e71a1ecf1557d1971b563e73f6bfb2f469 (from f9ce4c803330ed7413ffa96fc084e9d0ed0b1ffc)
Author: Richard Hughes <richard at hughsie.com>
Date: Thu Sep 6 21:09:21 2007 +0100
remove PkTask (common files)
diff --git a/src/pk-task-common.c b/src/pk-task-common.c
deleted file mode 100644
index 3d9168a..0000000
--- a/src/pk-task-common.c
+++ /dev/null
@@ -1,639 +0,0 @@
-/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
- *
- * 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.
- *
- * 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.
- */
-
-//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
-//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
-//!!!!! !!!!!!!!!
-//!!!!! Do not edit this file! Edit backends/$backend !!!!!!!!!
-//!!!!! !!!!!!!!!
-//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
-//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
-
-#include "config.h"
-
-#include <glib/gi18n.h>
-#include <string.h>
-#include <stdlib.h>
-#include <pk-package-id.h>
-
-#include "pk-debug.h"
-#include "pk-task.h"
-#include "pk-spawn.h"
-#include "pk-task-common.h"
-#include "pk-marshal.h"
-
-/**
- * pk_task_setup_signals:
- **/
-gboolean
-pk_task_setup_signals (GObjectClass *object_class, guint *signals)
-{
- g_return_val_if_fail (object_class != NULL, FALSE);
-
- signals [PK_TASK_JOB_STATUS_CHANGED] =
- g_signal_new ("job-status-changed",
- G_TYPE_FROM_CLASS (object_class), G_SIGNAL_RUN_LAST,
- 0, NULL, NULL, g_cclosure_marshal_VOID__UINT,
- G_TYPE_NONE, 1, G_TYPE_UINT);
- signals [PK_TASK_PERCENTAGE_CHANGED] =
- g_signal_new ("percentage-changed",
- G_TYPE_FROM_CLASS (object_class), G_SIGNAL_RUN_LAST,
- 0, NULL, NULL, g_cclosure_marshal_VOID__UINT,
- G_TYPE_NONE, 1, G_TYPE_UINT);
- signals [PK_TASK_SUB_PERCENTAGE_CHANGED] =
- g_signal_new ("sub-percentage-changed",
- G_TYPE_FROM_CLASS (object_class), G_SIGNAL_RUN_LAST,
- 0, NULL, NULL, g_cclosure_marshal_VOID__UINT,
- G_TYPE_NONE, 1, G_TYPE_UINT);
- signals [PK_TASK_PACKAGE] =
- g_signal_new ("package",
- G_TYPE_FROM_CLASS (object_class), G_SIGNAL_RUN_LAST,
- 0, NULL, NULL, pk_marshal_VOID__UINT_STRING_STRING,
- G_TYPE_NONE, 3, G_TYPE_UINT, G_TYPE_STRING, G_TYPE_STRING);
- signals [PK_TASK_REQUIRE_RESTART] =
- g_signal_new ("require-restart",
- G_TYPE_FROM_CLASS (object_class), G_SIGNAL_RUN_LAST,
- 0, NULL, NULL, pk_marshal_VOID__UINT_STRING,
- G_TYPE_NONE, 2, G_TYPE_UINT, G_TYPE_STRING);
- signals [PK_TASK_DESCRIPTION] =
- g_signal_new ("description",
- G_TYPE_FROM_CLASS (object_class), G_SIGNAL_RUN_LAST,
- 0, NULL, NULL, pk_marshal_VOID__STRING_UINT_STRING_STRING,
- G_TYPE_NONE, 4, G_TYPE_STRING, G_TYPE_UINT, G_TYPE_STRING, G_TYPE_STRING);
- signals [PK_TASK_ERROR_CODE] =
- g_signal_new ("error-code",
- G_TYPE_FROM_CLASS (object_class), G_SIGNAL_RUN_LAST,
- 0, NULL, NULL, pk_marshal_VOID__UINT_STRING,
- G_TYPE_NONE, 2, G_TYPE_UINT, G_TYPE_STRING);
- signals [PK_TASK_FINISHED] =
- g_signal_new ("finished",
- G_TYPE_FROM_CLASS (object_class), G_SIGNAL_RUN_LAST,
- 0, NULL, NULL, g_cclosure_marshal_VOID__UINT,
- G_TYPE_NONE, 1, G_TYPE_UINT);
- signals [PK_TASK_NO_PERCENTAGE_UPDATES] =
- g_signal_new ("no-percentage-updates",
- G_TYPE_FROM_CLASS (object_class), G_SIGNAL_RUN_LAST,
- 0, NULL, NULL, g_cclosure_marshal_VOID__VOID,
- G_TYPE_NONE, 0);
- signals [PK_TASK_ALLOW_INTERRUPT] =
- g_signal_new ("allow-interrupt",
- G_TYPE_FROM_CLASS (object_class), G_SIGNAL_RUN_LAST,
- 0, NULL, NULL, g_cclosure_marshal_VOID__BOOLEAN,
- G_TYPE_NONE, 1, G_TYPE_BOOLEAN);
- return TRUE;
-}
-
-/**
- * pk_task_parse_common_output:
- *
- * If you are editing this function creating a new backend,
- * then you are probably doing something wrong.
- **/
-static gboolean
-pk_task_parse_common_output (PkTask *task, const gchar *line)
-{
- gchar **sections;
- guint size;
- guint value = 0;
- gchar *command;
- gboolean ret = TRUE;
- PkTaskGroup group;
-
- /* check if output line */
- if (line == NULL || strstr (line, "\t") == NULL)
- return FALSE;
-
- /* split by tab */
- sections = g_strsplit (line, "\t", 0);
- command = sections[0];
-
- /* get size */
- size = g_strv_length (sections);
-
- if (strcmp (command, "package") == 0) {
- if (size != 4) {
- g_error ("invalid command '%s'", command);
- ret = FALSE;
- goto out;
- }
- if (pk_package_id_check (sections[2]) == TRUE) {
- value = atoi(sections[1]);
- pk_debug ("value=%i, package='%s' shortdesc='%s'", value, sections[2], sections[3]);
- pk_task_package (task, value, sections[2], sections[3]);
- } else {
- pk_warning ("invalid package_id");
- }
- } else if (strcmp (command, "description") == 0) {
- if (size != 5) {
- g_error ("invalid command '%s'", command);
- ret = FALSE;
- goto out;
- }
- group = pk_task_group_from_text (sections[2]);
- pk_task_description (task, sections[1], group, sections[3], sections[4]);
- } else {
- pk_warning ("invalid command '%s'", command);
- }
-out:
- g_strfreev (sections);
- return ret;
-}
-
-/**
- * pk_task_parse_common_error:
- *
- * If you are editing this function creating a new backend,
- * then you are probably doing something wrong.
- **/
-static gboolean
-pk_task_parse_common_error (PkTask *task, const gchar *line)
-{
- gchar **sections;
- guint size;
- guint percentage;
- gchar *command;
- PkTaskErrorCode error_enum;
- PkTaskStatus status_enum;
- PkTaskRestart restart_enum;
- gboolean ret = TRUE;
-
- /* check if output line */
- if (line == NULL || strstr (line, "\t") == NULL)
- return FALSE;
-
- /* split by tab */
- sections = g_strsplit (line, "\t", 0);
- command = sections[0];
-
- /* get size */
- for (size=0; sections[size]; size++);
-
- if (strcmp (command, "percentage") == 0) {
- if (size != 2) {
- g_error ("invalid command '%s'", command);
- ret = FALSE;
- goto out;
- }
- percentage = atoi(sections[1]);
- pk_task_change_percentage (task, percentage);
- } else if (strcmp (command, "subpercentage") == 0) {
- if (size != 2) {
- g_error ("invalid command '%s'", command);
- ret = FALSE;
- goto out;
- }
- percentage = atoi(sections[1]);
- pk_task_change_sub_percentage (task, percentage);
- } else if (strcmp (command, "error") == 0) {
- if (size != 3) {
- g_error ("invalid command '%s'", command);
- ret = FALSE;
- goto out;
- }
- error_enum = pk_task_error_code_from_text (sections[1]);
- pk_task_error_code (task, error_enum, sections[2]);
- } else if (strcmp (command, "requirerestart") == 0) {
- if (size != 3) {
- g_error ("invalid command '%s'", command);
- ret = FALSE;
- goto out;
- }
- restart_enum = pk_task_restart_from_text (sections[1]);
- pk_task_require_restart (task, restart_enum, sections[2]);
- } else if (strcmp (command, "status") == 0) {
- if (size != 2) {
- g_error ("invalid command '%s'", command);
- ret = FALSE;
- goto out;
- }
- status_enum = pk_task_status_from_text (sections[1]);
- pk_task_change_job_status (task, status_enum);
- } else if (strcmp (command, "allow-interrupt") == 0) {
- if (size != 2) {
- g_error ("invalid command '%s'", command);
- ret = FALSE;
- goto out;
- }
- if (strcmp (sections[1], "true") == 0) {
- pk_task_allow_interrupt (task, TRUE);
- } else if (strcmp (sections[1], "false") == 0) {
- pk_task_allow_interrupt (task, FALSE);
- } else {
- pk_warning ("invalid section '%s'", sections[1]);
- ret = FALSE;
- goto out;
- }
- } else if (strcmp (command, "no-percentage-updates") == 0) {
- if (size != 1) {
- g_error ("invalid command '%s'", command);
- ret = FALSE;
- goto out;
- }
- pk_task_no_percentage_updates (task);
- } else {
- pk_warning ("invalid command '%s'", command);
- }
-out:
- g_strfreev (sections);
- return ret;
-}
-
-/**
- * pk_task_spawn_finished_cb:
- **/
-static void
-pk_task_spawn_finished_cb (PkSpawn *spawn, gint exitcode, PkTask *task)
-{
- PkTaskExit exit;
- pk_debug ("unref'ing spawn %p, exit code %i", spawn, exitcode);
- g_object_unref (spawn);
-
- /* only emit success with a zero exit code */
- if (exitcode == 0) {
- exit = PK_TASK_EXIT_SUCCESS;
- } else {
- exit = PK_TASK_EXIT_FAILED;
- }
- pk_task_finished (task, exit);
-}
-
-/**
- * pk_task_spawn_stdout_cb:
- **/
-static void
-pk_task_spawn_stdout_cb (PkSpawn *spawn, const gchar *line, PkTask *task)
-{
- pk_debug ("stdout from %p = '%s'", spawn, line);
- pk_task_parse_common_output (task, line);
-}
-
-/**
- * pk_task_spawn_stderr_cb:
- **/
-static void
-pk_task_spawn_stderr_cb (PkSpawn *spawn, const gchar *line, PkTask *task)
-{
- pk_debug ("stderr from %p = '%s'", spawn, line);
- pk_task_parse_common_error (task, line);
-}
-
-/**
- * pk_task_spawn_helper_internal:
- **/
-static gboolean
-pk_task_spawn_helper_internal (PkTask *task, const gchar *script, const gchar *argument)
-{
- gboolean ret;
- gchar *filename;
- gchar *command;
-
- /* build script */
- filename = g_build_filename (DATADIR, "PackageKit", "helpers", script, NULL);
-
- if (argument != NULL) {
- command = g_strdup_printf ("%s %s", filename, argument);
- } else {
- command = g_strdup (filename);
- }
-
- task->spawn = pk_spawn_new ();
- g_signal_connect (task->spawn, "finished",
- G_CALLBACK (pk_task_spawn_finished_cb), task);
- g_signal_connect (task->spawn, "stdout",
- G_CALLBACK (pk_task_spawn_stdout_cb), task);
- g_signal_connect (task->spawn, "stderr",
- G_CALLBACK (pk_task_spawn_stderr_cb), task);
- ret = pk_spawn_command (task->spawn, command);
- if (ret == FALSE) {
- g_object_unref (task->spawn);
- pk_task_error_code (task, PK_TASK_ERROR_CODE_INTERNAL_ERROR, "Spawn of helper '%s' failed", command);
- pk_task_finished (task, PK_TASK_EXIT_FAILED);
- }
- g_free (filename);
- g_free (command);
- return ret;
-}
-
-/**
- * pk_task_spawn_helper:
- **/
-gboolean
-pk_task_spawn_helper (PkTask *task, const gchar *script, ...)
-{
- gboolean ret;
- va_list args;
- gchar *arguments;
-
- /* get the argument list */
- va_start (args, script);
- arguments = g_strjoinv (" ", (gchar **)(void *)args);
- va_end (args);
-
- ret = pk_task_spawn_helper_internal (task, script, arguments);
- g_free (arguments);
- return ret;
-}
-
-/**
- * pk_task_not_implemented_yet:
- **/
-gboolean
-pk_task_not_implemented_yet (PkTask *task, const gchar *method)
-{
- pk_task_error_code (task, PK_TASK_ERROR_CODE_NOT_SUPPORTED, "the method '%s' is not implemented yet", method);
- pk_task_finished (task, PK_TASK_EXIT_FAILED);
- return TRUE;
-}
-
-/**
- * pk_task_change_percentage:
- **/
-gboolean
-pk_task_change_percentage (PkTask *task, guint percentage)
-{
- g_return_val_if_fail (task != NULL, FALSE);
- g_return_val_if_fail (PK_IS_TASK (task), FALSE);
- pk_debug ("emit percentage-changed %i", percentage);
- g_signal_emit (task, task->signals [PK_TASK_PERCENTAGE_CHANGED], 0, percentage);
- return TRUE;
-}
-
-/**
- * pk_task_change_sub_percentage:
- **/
-gboolean
-pk_task_change_sub_percentage (PkTask *task, guint percentage)
-{
- g_return_val_if_fail (task != NULL, FALSE);
- g_return_val_if_fail (PK_IS_TASK (task), FALSE);
- pk_debug ("emit sub-percentage-changed %i", percentage);
- g_signal_emit (task, task->signals [PK_TASK_SUB_PERCENTAGE_CHANGED], 0, percentage);
- return TRUE;
-}
-
-/**
- * pk_task_set_job_role:
- **/
-gboolean
-pk_task_set_job_role (PkTask *task, PkTaskRole role, const gchar *package_id)
-{
- g_return_val_if_fail (task != NULL, FALSE);
- g_return_val_if_fail (PK_IS_TASK (task), FALSE);
-
- /* Should only be called once... */
- if (task->role != PK_TASK_ROLE_UNKNOWN) {
- pk_error ("cannot set role more than once, already %i", task->role);
- }
- pk_debug ("setting role to %i (%s)", role, package_id);
- task->role = role;
- task->package_id = g_strdup (package_id);
- return TRUE;
-}
-
-/**
- * pk_task_change_job_status:
- **/
-gboolean
-pk_task_change_job_status (PkTask *task, PkTaskStatus status)
-{
- g_return_val_if_fail (task != NULL, FALSE);
- g_return_val_if_fail (PK_IS_TASK (task), FALSE);
- task->status = status;
- pk_debug ("emiting job-status-changed %i", status);
- g_signal_emit (task, task->signals [PK_TASK_JOB_STATUS_CHANGED], 0, status);
- return TRUE;
-}
-
-/**
- * pk_task_package:
- **/
-gboolean
-pk_task_package (PkTask *task, guint value, const gchar *package, const gchar *summary)
-{
- g_return_val_if_fail (task != NULL, FALSE);
- g_return_val_if_fail (PK_IS_TASK (task), FALSE);
-
- pk_debug ("emit package %i, %s, %s", value, package, summary);
- g_signal_emit (task, task->signals [PK_TASK_PACKAGE], 0, value, package, summary);
-
- return TRUE;
-}
-
-/**
- * pk_task_require_restart:
- **/
-gboolean
-pk_task_require_restart (PkTask *task, PkTaskRestart restart, const gchar *details)
-{
- g_return_val_if_fail (task != NULL, FALSE);
- g_return_val_if_fail (PK_IS_TASK (task), FALSE);
-
- pk_debug ("emit require-restart %i, %s", restart, details);
- g_signal_emit (task, task->signals [PK_TASK_REQUIRE_RESTART], 0, restart, details);
-
- return TRUE;
-}
-
-/**
- * pk_task_description:
- **/
-gboolean
-pk_task_description (PkTask *task, const gchar *package, PkTaskGroup group,
- const gchar *description, const gchar *url)
-{
- g_return_val_if_fail (task != NULL, FALSE);
- g_return_val_if_fail (PK_IS_TASK (task), FALSE);
-
- pk_debug ("emit description %s, %i, %s, %s", package, group, description, url);
- g_signal_emit (task, task->signals [PK_TASK_DESCRIPTION], 0, package, group, description, url);
-
- return TRUE;
-}
-
-/**
- * pk_task_error_code:
- **/
-gboolean
-pk_task_error_code (PkTask *task, PkTaskErrorCode code, const gchar *format, ...)
-{
- va_list args;
- gchar buffer[1025];
-
- g_return_val_if_fail (task != NULL, FALSE);
- g_return_val_if_fail (PK_IS_TASK (task), FALSE);
-
- va_start (args, format);
- g_vsnprintf (buffer, 1024, format, args);
- va_end (args);
-
- pk_debug ("emit error-code %i, %s", code, buffer);
- g_signal_emit (task, task->signals [PK_TASK_ERROR_CODE], 0, code, buffer);
-
- return TRUE;
-}
-
-/**
- * pk_task_get_job_status:
- **/
-gboolean
-pk_task_get_job_status (PkTask *task, PkTaskStatus *status)
-{
- g_return_val_if_fail (task != NULL, FALSE);
- g_return_val_if_fail (PK_IS_TASK (task), FALSE);
-
- /* check to see if we have an action */
- if (task->assigned == FALSE) {
- pk_warning ("Not assigned");
- return FALSE;
- }
- *status = task->status;
- return TRUE;
-}
-
-/**
- * pk_task_get_job_role:
- **/
-gboolean
-pk_task_get_job_role (PkTask *task, PkTaskRole *role, const gchar **package_id)
-{
- g_return_val_if_fail (task != NULL, FALSE);
- g_return_val_if_fail (PK_IS_TASK (task), FALSE);
-
- /* check to see if we have an action */
- if (task->assigned == FALSE) {
- pk_warning ("Not assigned");
- return FALSE;
- }
- *role = task->role;
- *package_id = g_strdup (task->package_id);
- return TRUE;
-}
-
-/**
- * pk_task_finished_idle:
- **/
-static gboolean
-pk_task_finished_idle (gpointer data)
-{
- PkTask *task = (PkTask *) data;
- pk_debug ("emit finished %i", task->exit);
- g_signal_emit (task, task->signals [PK_TASK_FINISHED], 0, task->exit);
- return FALSE;
-}
-
-/**
- * pk_task_finished:
- **/
-gboolean
-pk_task_finished (PkTask *task, PkTaskExit exit)
-{
- g_return_val_if_fail (task != NULL, FALSE);
- g_return_val_if_fail (PK_IS_TASK (task), FALSE);
-
- /* we have to run this idle as the command may finish before the job
- * has been sent to the client. I love async... */
- pk_debug ("adding finished %p to idle loop", task);
- task->exit = exit;
- g_idle_add (pk_task_finished_idle, task);
- return TRUE;
-}
-
-/**
- * pk_task_no_percentage_updates:
- **/
-gboolean
-pk_task_no_percentage_updates (PkTask *task)
-{
- g_return_val_if_fail (task != NULL, FALSE);
- g_return_val_if_fail (PK_IS_TASK (task), FALSE);
-
- pk_debug ("emit no-percentage-updates");
- g_signal_emit (task, task->signals [PK_TASK_NO_PERCENTAGE_UPDATES], 0);
- return TRUE;
-}
-
-/**
- * pk_task_allow_interrupt:
- **/
-gboolean
-pk_task_allow_interrupt (PkTask *task, gboolean allow_restart)
-{
- g_return_val_if_fail (task != NULL, FALSE);
- g_return_val_if_fail (PK_IS_TASK (task), FALSE);
-
- pk_debug ("emit allow-interrupt %i", allow_restart);
- task->is_killable = allow_restart;
- g_signal_emit (task, task->signals [PK_TASK_ALLOW_INTERRUPT], 0);
- return TRUE;
-}
-
-/**
- * pk_task_assign:
- **/
-gboolean
-pk_task_assign (PkTask *task)
-{
- g_return_val_if_fail (task != NULL, FALSE);
- g_return_val_if_fail (PK_IS_TASK (task), FALSE);
-
- /* check to see if we already have an action */
- if (task->assigned == TRUE) {
- pk_warning ("Already assigned");
- return FALSE;
- }
- task->assigned = TRUE;
- return TRUE;
-}
-
-/**
- * pk_task_common_init:
- **/
-gboolean
-pk_task_common_init (PkTask *task)
-{
- g_return_val_if_fail (task != NULL, FALSE);
- g_return_val_if_fail (PK_IS_TASK (task), FALSE);
-
- /* track how long the job has been running for */
- task->timer = g_timer_new ();
- task->assigned = FALSE;
- task->is_killable = FALSE;
- task->spawn = NULL;
- task->package_id = NULL;
- task->role = PK_TASK_ROLE_UNKNOWN;
- task->status = PK_TASK_STATUS_UNKNOWN;
- task->exit = PK_TASK_EXIT_UNKNOWN;
-
- return TRUE;
-}
-
-/**
- * pk_task_common_init:
- **/
-gboolean
-pk_task_common_free (PkTask *task)
-{
- g_return_val_if_fail (task != NULL, FALSE);
- g_return_val_if_fail (PK_IS_TASK (task), FALSE);
- g_timer_destroy (task->timer);
- return TRUE;
-}
-
diff --git a/src/pk-task-common.h b/src/pk-task-common.h
deleted file mode 100644
index 7b81408..0000000
--- a/src/pk-task-common.h
+++ /dev/null
@@ -1,76 +0,0 @@
-/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
- *
- * 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.
- *
- * 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.
- */
-
-#ifndef __PK_TASK_COMMON_H
-#define __PK_TASK_COMMON_H
-
-#include <glib-object.h>
-#include "pk-task.h"
-
-G_BEGIN_DECLS
-
-gboolean pk_task_common_init (PkTask *task);
-gboolean pk_task_common_free (PkTask *task);
-gboolean pk_task_change_percentage (PkTask *task,
- guint percentage);
-gboolean pk_task_change_sub_percentage (PkTask *task,
- guint percentage);
-gboolean pk_task_change_job_status (PkTask *task,
- PkTaskStatus status);
-gboolean pk_task_get_job_status (PkTask *task,
- PkTaskStatus *status);
-gboolean pk_task_set_job_role (PkTask *task,
- PkTaskRole role,
- const gchar *package_id);
-gboolean pk_task_get_job_role (PkTask *task,
- PkTaskRole *role,
- const gchar **package_id);
-gboolean pk_task_no_percentage_updates (PkTask *task);
-gboolean pk_task_finished (PkTask *task,
- PkTaskExit exit);
-gboolean pk_task_package (PkTask *task,
- guint value,
- const gchar *package_id,
- const gchar *summary);
-gboolean pk_task_require_restart (PkTask *task,
- PkTaskRestart restart,
- const gchar *details);
-gboolean pk_task_description (PkTask *task,
- const gchar *package,
- PkTaskGroup group,
- const gchar *description,
- const gchar *url);
-gboolean pk_task_error_code (PkTask *task,
- guint code,
- const gchar *details, ...);
-gboolean pk_task_assign (PkTask *task);
-gboolean pk_task_setup_signals (GObjectClass *object_class,
- guint *signals);
-gboolean pk_task_spawn_helper (PkTask *task,
- const gchar *script, ...);
-gboolean pk_task_not_implemented_yet (PkTask *task,
- const gchar *method);
-gboolean pk_task_allow_interrupt (PkTask *task,
- gboolean allow_restart);
-
-G_END_DECLS
-
-#endif /* __PK_TASK_COMMON_H */
diff-tree f9ce4c803330ed7413ffa96fc084e9d0ed0b1ffc (from 0664667c8c38ae3554771dcc0edf79c9011bdd62)
Author: Richard Hughes <richard at hughsie.com>
Date: Thu Sep 6 21:08:12 2007 +0100
add gitignore
diff --git a/backends/apt/.gitignore b/backends/apt/.gitignore
new file mode 100644
index 0000000..c851833
--- /dev/null
+++ b/backends/apt/.gitignore
@@ -0,0 +1,10 @@
+.deps
+.libs
+Makefile
+Makefile.in
+*.la
+*.lo
+*.loT
+*.o
+*~
+
diff-tree 0664667c8c38ae3554771dcc0edf79c9011bdd62 (from c15924047cea492ccd995cce96abd54c646b0d3c)
Author: Richard Hughes <richard at hughsie.com>
Date: Thu Sep 6 21:03:13 2007 +0100
make task allocation work once again
diff --git a/backends/apt/Makefile.am b/backends/apt/Makefile.am
index 76992c1..7eee77e 100644
--- a/backends/apt/Makefile.am
+++ b/backends/apt/Makefile.am
@@ -1,8 +1,8 @@
-#plugindir = @PK_PLUGIN_DIR@
-#plugin_LTLIBRARIES = libpk_backend_apt.la
-#libpk_backend_apt_la_INCLUDES = $(APT_CFLAGS)
-#libpk_backend_apt_la_SOURCES = pk-backend-apt.cpp
-#libpk_backend_apt_la_LIBADD = @PK_PLUGIN_LIBS@ $(APT_LIBS)
-#libpk_backend_apt_la_LDFLAGS = -module -avoid-version
-#libpk_backend_apt_la_CFLAGS = @PK_PLUGIN_CFLAGS@
+plugindir = @PK_PLUGIN_DIR@
+plugin_LTLIBRARIES = libpk_backend_apt.la
+libpk_backend_apt_la_INCLUDES = $(APT_CFLAGS)
+libpk_backend_apt_la_SOURCES = pk-backend-apt.cpp
+libpk_backend_apt_la_LIBADD = @PK_PLUGIN_LIBS@ $(APT_LIBS)
+libpk_backend_apt_la_LDFLAGS = -module -avoid-version
+libpk_backend_apt_la_CFLAGS = @PK_PLUGIN_CFLAGS@
diff --git a/backends/box/Makefile.am b/backends/box/Makefile.am
index 9f9d0fa..f657b0d 100644
--- a/backends/box/Makefile.am
+++ b/backends/box/Makefile.am
@@ -1,9 +1,9 @@
SUBDIRS = helpers
-#plugindir = @PK_PLUGIN_DIR@
-#plugin_LTLIBRARIES = libpk_backend_box.la
-#libpk_backend_box_la_SOURCES = pk-backend-box.c
-#libpk_backend_box_la_LIBADD = @PK_PLUGIN_LIBS@ $(BOX_LIBS)
-#libpk_backend_box_la_LDFLAGS = -module -avoid-version
-#libpk_backend_box_la_CFLAGS = @PK_PLUGIN_CFLAGS@
-#libpk_backend_box_la_INCLUDES = $(BOX_CFLAGS)
+plugindir = @PK_PLUGIN_DIR@
+plugin_LTLIBRARIES = libpk_backend_box.la
+libpk_backend_box_la_SOURCES = pk-backend-box.c
+libpk_backend_box_la_LIBADD = @PK_PLUGIN_LIBS@ $(BOX_LIBS)
+libpk_backend_box_la_LDFLAGS = -module -avoid-version
+libpk_backend_box_la_CFLAGS = @PK_PLUGIN_CFLAGS@
+libpk_backend_box_la_INCLUDES = $(BOX_CFLAGS)
diff --git a/backends/conary/Makefile.am b/backends/conary/Makefile.am
index 080caa6..49902b2 100644
--- a/backends/conary/Makefile.am
+++ b/backends/conary/Makefile.am
@@ -1,7 +1,8 @@
SUBDIRS = helpers
-#plugindir = @PK_PLUGIN_DIR@
-#plugin_LTLIBRARIES = libpk_backend_conary.la
-#libpk_backend_conary_la_SOURCES = pk-backend-conary.c
-#libpk_backend_conary_la_LIBADD = @PK_PLUGIN_LIBS@
-#libpk_backend_conary_la_LDFLAGS = -module -avoid-version
-#libpk_backend_conary_la_CFLAGS = @PK_PLUGIN_CFLAGS@
+plugindir = @PK_PLUGIN_DIR@
+plugin_LTLIBRARIES = libpk_backend_conary.la
+libpk_backend_conary_la_SOURCES = pk-backend-conary.c
+libpk_backend_conary_la_LIBADD = @PK_PLUGIN_LIBS@
+libpk_backend_conary_la_LDFLAGS = -module -avoid-version
+libpk_backend_conary_la_CFLAGS = @PK_PLUGIN_CFLAGS@
+
diff --git a/backends/dummy/Makefile.am b/backends/dummy/Makefile.am
index 4ad84c2..daff2d6 100644
--- a/backends/dummy/Makefile.am
+++ b/backends/dummy/Makefile.am
@@ -1,6 +1,7 @@
-#plugindir = @PK_PLUGIN_DIR@
-#plugin_LTLIBRARIES = libpk_backend_dummy.la
-#libpk_backend_dummy_la_SOURCES = pk-backend-dummy.c
-#libpk_backend_dummy_la_LIBADD = @PK_PLUGIN_LIBS@
-#libpk_backend_dummy_la_LDFLAGS = -module -avoid-version
-#libpk_backend_dummy_la_CFLAGS = @PK_PLUGIN_CFLAGS@
+plugindir = @PK_PLUGIN_DIR@
+plugin_LTLIBRARIES = libpk_backend_dummy.la
+libpk_backend_dummy_la_SOURCES = pk-backend-dummy.c
+libpk_backend_dummy_la_LIBADD = @PK_PLUGIN_LIBS@
+libpk_backend_dummy_la_LDFLAGS = -module -avoid-version
+libpk_backend_dummy_la_CFLAGS = @PK_PLUGIN_CFLAGS@
+
diff --git a/backends/test/Makefile.am b/backends/test/Makefile.am
index 74178c4..e26a9a3 100644
--- a/backends/test/Makefile.am
+++ b/backends/test/Makefile.am
@@ -1,6 +1,7 @@
-#plugindir = @PK_PLUGIN_DIR@
-#plugin_LTLIBRARIES = libpk_backend_test.la
-#libpk_backend_test_la_SOURCES = pk-backend-test.c
-#libpk_backend_test_la_LIBADD = @PK_PLUGIN_LIBS@
-#libpk_backend_test_la_LDFLAGS = -module -avoid-version
-#libpk_backend_test_la_CFLAGS = @PK_PLUGIN_CFLAGS@
+plugindir = @PK_PLUGIN_DIR@
+plugin_LTLIBRARIES = libpk_backend_test.la
+libpk_backend_test_la_SOURCES = pk-backend-test.c
+libpk_backend_test_la_LIBADD = @PK_PLUGIN_LIBS@
+libpk_backend_test_la_LDFLAGS = -module -avoid-version
+libpk_backend_test_la_CFLAGS = @PK_PLUGIN_CFLAGS@
+
diff --git a/backends/yum/Makefile.am b/backends/yum/Makefile.am
index fc32e63..4bd6469 100644
--- a/backends/yum/Makefile.am
+++ b/backends/yum/Makefile.am
@@ -1,7 +1,8 @@
SUBDIRS = helpers
-#plugindir = @PK_PLUGIN_DIR@
-#plugin_LTLIBRARIES = libpk_backend_yum.la
-#libpk_backend_yum_la_SOURCES = pk-backend-yum.c
-#libpk_backend_yum_la_LIBADD = @PK_PLUGIN_LIBS@
-#libpk_backend_yum_la_LDFLAGS = -module -avoid-version
-#libpk_backend_yum_la_CFLAGS = @PK_PLUGIN_CFLAGS@
+plugindir = @PK_PLUGIN_DIR@
+plugin_LTLIBRARIES = libpk_backend_yum.la
+libpk_backend_yum_la_SOURCES = pk-backend-yum.c
+libpk_backend_yum_la_LIBADD = @PK_PLUGIN_LIBS@
+libpk_backend_yum_la_LDFLAGS = -module -avoid-version
+libpk_backend_yum_la_CFLAGS = @PK_PLUGIN_CFLAGS@
+
diff --git a/src/pk-backend-internal.h b/src/pk-backend-internal.h
index b1f9b7c..926ac6f 100644
--- a/src/pk-backend-internal.h
+++ b/src/pk-backend-internal.h
@@ -50,6 +50,7 @@ struct _PkBackendClass
GObjectClass parent_class;
};
+typedef PkBackend PkTask;
/* general */
GType pk_backend_get_type (void);
diff --git a/src/pk-backend.c b/src/pk-backend.c
index 7773422..0fc5bc6 100644
--- a/src/pk-backend.c
+++ b/src/pk-backend.c
@@ -96,6 +96,8 @@ pk_backend_build_library_path (PkBackend
filename = g_strdup_printf ("libpk_backend_%s.so", backend->priv->name);
path = g_build_filename (LIBDIR, "packagekit-backend", filename, NULL);
g_free (filename);
+ pk_debug ("dlopening '%s'", path);
+
return path;
}
@@ -470,11 +472,14 @@ pk_backend_set_job_role (PkBackend *back
g_return_val_if_fail (backend != NULL, FALSE);
g_return_val_if_fail (PK_IS_BACKEND (backend), FALSE);
+ pk_debug ("TRYING to setting role to %s (string is '%s')", pk_task_role_to_text (role), package_id);
+
/* Should only be called once... */
if (backend->priv->role != PK_TASK_ROLE_UNKNOWN) {
- pk_error ("cannot set role more than once, already %i", backend->priv->role);
+ pk_error ("cannot set role more than once, already %s",
+ pk_task_role_to_text (backend->priv->role));
}
- pk_debug ("setting role to %i (%s)", role, package_id);
+ pk_debug ("setting role to %s (string is '%s')", pk_task_role_to_text (role), package_id);
backend->priv->role = role;
backend->priv->package_id = g_strdup (package_id);
return TRUE;
diff --git a/src/pk-engine.c b/src/pk-engine.c
index 7059ac1..6271555 100644
--- a/src/pk-engine.c
+++ b/src/pk-engine.c
@@ -80,7 +80,7 @@ enum {
typedef struct {
guint job;
- PkBackend *task;
+ PkTask *task;
} PkEngineMap;
static guint signals [PK_ENGINE_LAST_SIGNAL] = { 0, };
@@ -202,7 +202,7 @@ pk_get_map_from_job (PkEngine *engine, g
* pk_get_map_from_task:
**/
static PkEngineMap *
-pk_get_map_from_task (PkEngine *engine, PkBackend *task)
+pk_get_map_from_task (PkEngine *engine, PkTask *task)
{
guint i;
guint length;
@@ -245,7 +245,7 @@ pk_engine_job_list_changed (PkEngine *en
* pk_engine_job_status_changed_cb:
**/
static void
-pk_engine_job_status_changed_cb (PkBackend *task, PkTaskStatus status, PkEngine *engine)
+pk_engine_job_status_changed_cb (PkTask *task, PkTaskStatus status, PkEngine *engine)
{
PkEngineMap *map;
const gchar *status_text;
@@ -269,7 +269,7 @@ pk_engine_job_status_changed_cb (PkBacke
* pk_engine_percentage_changed_cb:
**/
static void
-pk_engine_percentage_changed_cb (PkBackend *task, guint percentage, PkEngine *engine)
+pk_engine_percentage_changed_cb (PkTask *task, guint percentage, PkEngine *engine)
{
PkEngineMap *map;
@@ -290,7 +290,7 @@ pk_engine_percentage_changed_cb (PkBacke
* pk_engine_sub_percentage_changed_cb:
**/
static void
-pk_engine_sub_percentage_changed_cb (PkBackend *task, guint percentage, PkEngine *engine)
+pk_engine_sub_percentage_changed_cb (PkTask *task, guint percentage, PkEngine *engine)
{
PkEngineMap *map;
@@ -311,7 +311,7 @@ pk_engine_sub_percentage_changed_cb (PkB
* pk_engine_no_percentage_updates_cb:
**/
static void
-pk_engine_no_percentage_updates_cb (PkBackend *task, PkEngine *engine)
+pk_engine_no_percentage_updates_cb (PkTask *task, PkEngine *engine)
{
PkEngineMap *map;
@@ -332,7 +332,7 @@ pk_engine_no_percentage_updates_cb (PkBa
* pk_engine_package_cb:
**/
static void
-pk_engine_package_cb (PkBackend *task, guint value, const gchar *package_id, const gchar *summary, PkEngine *engine)
+pk_engine_package_cb (PkTask *task, guint value, const gchar *package_id, const gchar *summary, PkEngine *engine)
{
PkEngineMap *map;
@@ -353,7 +353,7 @@ pk_engine_package_cb (PkBackend *task, g
* pk_engine_error_code_cb:
**/
static void
-pk_engine_error_code_cb (PkBackend *task, PkTaskErrorCode code, const gchar *details, PkEngine *engine)
+pk_engine_error_code_cb (PkTask *task, PkTaskErrorCode code, const gchar *details, PkEngine *engine)
{
PkEngineMap *map;
const gchar *code_text;
@@ -376,7 +376,7 @@ pk_engine_error_code_cb (PkBackend *task
* pk_engine_require_restart_cb:
**/
static void
-pk_engine_require_restart_cb (PkBackend *task, PkTaskRestart restart, const gchar *details, PkEngine *engine)
+pk_engine_require_restart_cb (PkTask *task, PkTaskRestart restart, const gchar *details, PkEngine *engine)
{
PkEngineMap *map;
const gchar *restart_text;
@@ -399,7 +399,7 @@ pk_engine_require_restart_cb (PkBackend
* pk_engine_description_cb:
**/
static void
-pk_engine_description_cb (PkBackend *task, const gchar *package_id, PkTaskGroup group,
+pk_engine_description_cb (PkTask *task, const gchar *package_id, PkTaskGroup group,
const gchar *detail, const gchar *url, PkEngine *engine)
{
PkEngineMap *map;
@@ -423,7 +423,7 @@ pk_engine_description_cb (PkBackend *tas
* pk_engine_finished_cb:
**/
static void
-pk_engine_finished_cb (PkBackend *task, PkTaskExit exit, PkEngine *engine)
+pk_engine_finished_cb (PkTask *task, PkTaskExit exit, PkEngine *engine)
{
PkEngineMap *map;
const gchar *exit_text;
@@ -461,7 +461,7 @@ pk_engine_finished_cb (PkBackend *task,
* pk_engine_allow_interrupt_cb:
**/
static void
-pk_engine_allow_interrupt_cb (PkBackend *task, gboolean allow_kill, PkEngine *engine)
+pk_engine_allow_interrupt_cb (PkTask *task, gboolean allow_kill, PkEngine *engine)
{
PkEngineMap *map;
@@ -520,10 +520,10 @@ pk_engine_save_job_count (PkEngine *engi
/**
* pk_engine_new_task:
**/
-static PkBackend *
+static PkTask *
pk_engine_new_task (PkEngine *engine)
{
- PkBackend *task;
+ PkTask *task;
gboolean ret;
/* increment the job number - we never repeat an id */
@@ -571,7 +571,7 @@ pk_engine_new_task (PkEngine *engine)
* pk_engine_add_task:
**/
static gboolean
-pk_engine_add_task (PkEngine *engine, PkBackend *task)
+pk_engine_add_task (PkEngine *engine, PkTask *task)
{
PkEngineMap *map;
@@ -656,7 +656,7 @@ gboolean
pk_engine_refresh_cache (PkEngine *engine, gboolean force, guint *job, GError **error)
{
gboolean ret;
- PkBackend *task;
+ PkTask *task;
PkEngineMap *map;
g_return_val_if_fail (engine != NULL, FALSE);
@@ -689,7 +689,7 @@ gboolean
pk_engine_get_updates (PkEngine *engine, guint *job, GError **error)
{
gboolean ret;
- PkBackend *task;
+ PkTask *task;
PkEngineMap *map;
g_return_val_if_fail (engine != NULL, FALSE);
@@ -775,7 +775,7 @@ pk_engine_search_name (PkEngine *engine,
guint *job, GError **error)
{
gboolean ret;
- PkBackend *task;
+ PkTask *task;
PkEngineMap *map;
g_return_val_if_fail (engine != NULL, FALSE);
@@ -821,7 +821,7 @@ pk_engine_search_details (PkEngine *engi
guint *job, GError **error)
{
gboolean ret;
- PkBackend *task;
+ PkTask *task;
PkEngineMap *map;
g_return_val_if_fail (engine != NULL, FALSE);
@@ -867,7 +867,7 @@ pk_engine_search_group (PkEngine *engine
guint *job, GError **error)
{
gboolean ret;
- PkBackend *task;
+ PkTask *task;
PkEngineMap *map;
g_return_val_if_fail (engine != NULL, FALSE);
@@ -913,7 +913,7 @@ pk_engine_search_file (PkEngine *engine,
guint *job, GError **error)
{
gboolean ret;
- PkBackend *task;
+ PkTask *task;
PkEngineMap *map;
g_return_val_if_fail (engine != NULL, FALSE);
@@ -959,7 +959,7 @@ pk_engine_get_depends (PkEngine *engine,
guint *job, GError **error)
{
gboolean ret;
- PkBackend *task;
+ PkTask *task;
PkEngineMap *map;
g_return_val_if_fail (engine != NULL, FALSE);
@@ -1001,7 +1001,7 @@ pk_engine_get_requires (PkEngine *engine
guint *job, GError **error)
{
gboolean ret;
- PkBackend *task;
+ PkTask *task;
PkEngineMap *map;
g_return_val_if_fail (engine != NULL, FALSE);
@@ -1043,7 +1043,7 @@ pk_engine_get_description (PkEngine *eng
guint *job, GError **error)
{
gboolean ret;
- PkBackend *task;
+ PkTask *task;
PkEngineMap *map;
g_return_val_if_fail (engine != NULL, FALSE);
@@ -1081,7 +1081,7 @@ pk_engine_update_system (PkEngine *engin
PkTaskRole role;
gboolean ret;
GError *error;
- PkBackend *task;
+ PkTask *task;
PkEngineMap *map;
g_return_if_fail (engine != NULL);
@@ -1136,7 +1136,7 @@ pk_engine_remove_package (PkEngine *engi
{
PkEngineMap *map;
gboolean ret;
- PkBackend *task;
+ PkTask *task;
GError *error;
g_return_if_fail (engine != NULL);
@@ -1189,7 +1189,7 @@ pk_engine_install_package (PkEngine *eng
{
gboolean ret;
PkEngineMap *map;
- PkBackend *task;
+ PkTask *task;
GError *error;
g_return_if_fail (engine != NULL);
@@ -1242,7 +1242,7 @@ pk_engine_update_package (PkEngine *engi
{
gboolean ret;
PkEngineMap *map;
- PkBackend *task;
+ PkTask *task;
GError *error;
g_return_if_fail (engine != NULL);
@@ -1385,7 +1385,7 @@ pk_engine_cancel_job_try (PkEngine *engi
gboolean
pk_engine_get_actions (PkEngine *engine, gchar **actions, GError **error)
{
- PkBackend *task;
+ PkTask *task;
PkActionList *alist;
g_return_val_if_fail (engine != NULL, FALSE);
diff-tree c15924047cea492ccd995cce96abd54c646b0d3c (from 5cfc8290da95ab208666977a1ead66ff4ab4cf45)
Author: Richard Hughes <richard at hughsie.com>
Date: Thu Sep 6 20:47:02 2007 +0100
make GetActions work
diff --git a/src/pk-backend.c b/src/pk-backend.c
index f57cd3e..7773422 100644
--- a/src/pk-backend.c
+++ b/src/pk-backend.c
@@ -997,6 +997,7 @@ pk_backend_finalize (GObject *object)
}
}
+ pk_debug ("freeing %s", backend->priv->name);
g_free (backend->priv->name);
pk_backend_unload (backend);
g_timer_destroy (backend->priv->timer);
diff-tree 5cfc8290da95ab208666977a1ead66ff4ab4cf45 (from ef09ac41dd254f307e230081037c549213ac4ff7)
Author: Richard Hughes <richard at hughsie.com>
Date: Thu Sep 6 20:45:31 2007 +0100
make GetActions work
diff --git a/libpackagekit/pk-task-utils.c b/libpackagekit/pk-task-utils.c
index 55b3caa..0caddc4 100644
--- a/libpackagekit/pk-task-utils.c
+++ b/libpackagekit/pk-task-utils.c
@@ -504,10 +504,12 @@ pk_util_action_to_string (PkActionList *
{
guint i;
GString *string;
+ PkTaskAction action;
string = g_string_new ("");
for (i=0; i<alist->len; i++) {
- g_string_append (string, g_ptr_array_index (alist, i));
+ action = GPOINTER_TO_UINT (g_ptr_array_index (alist, i));
+ g_string_append (string, pk_task_action_to_text (action));
g_string_append (string, ";");
}
diff --git a/src/pk-backend.c b/src/pk-backend.c
index 01dcab9..f57cd3e 100644
--- a/src/pk-backend.c
+++ b/src/pk-backend.c
@@ -110,6 +110,9 @@ pk_backend_load (PkBackend *backend, con
g_return_val_if_fail (backend_name != NULL, FALSE);
+ /* save the backend name */
+ backend->priv->name = g_strdup (backend_name);
+
pk_debug ("Trying to load : %s", backend_name);
path = pk_backend_build_library_path (backend);
handle = g_module_open (path, 0);
@@ -121,7 +124,6 @@ pk_backend_load (PkBackend *backend, con
g_free (path);
backend->priv->handle = handle;
- backend->priv->name = g_strdup (backend_name);
if (g_module_symbol (handle, "pk_backend_desc", (gpointer) &backend->desc) == FALSE) {
g_module_close (handle);
diff --git a/src/pk-engine.c b/src/pk-engine.c
index 679e546..7059ac1 100644
--- a/src/pk-engine.c
+++ b/src/pk-engine.c
@@ -1393,6 +1393,7 @@ pk_engine_get_actions (PkEngine *engine,
/* create a new task and start it */
task = pk_engine_new_task (engine);
+ pk_backend_load (task, engine->priv->backend);
alist = pk_backend_get_actions (task);
g_object_unref (task);
*actions = pk_util_action_to_string (alist);
diff-tree ef09ac41dd254f307e230081037c549213ac4ff7 (from a03e2417fdcd1f0deba14bdd863ac1388d4c71d1)
Author: Richard Hughes <richard at hughsie.com>
Date: Thu Sep 6 20:32:56 2007 +0100
impliment automatic GetActions support
diff --git a/libpackagekit/pk-task-utils.h b/libpackagekit/pk-task-utils.h
index 25fea82..37e12fc 100644
--- a/libpackagekit/pk-task-utils.h
+++ b/libpackagekit/pk-task-utils.h
@@ -98,6 +98,7 @@ typedef enum {
PK_TASK_ACTION_REMOVE,
PK_TASK_ACTION_UPDATE,
PK_TASK_ACTION_GET_UPDATES,
+ PK_TASK_ACTION_CANCEL_JOB,
PK_TASK_ACTION_REFRESH_CACHE,
PK_TASK_ACTION_UPDATE_SYSTEM,
PK_TASK_ACTION_SEARCH_NAME,
diff --git a/src/pk-backend-internal.h b/src/pk-backend-internal.h
index 223dbf1..b1f9b7c 100644
--- a/src/pk-backend-internal.h
+++ b/src/pk-backend-internal.h
@@ -54,10 +54,11 @@ struct _PkBackendClass
/* general */
GType pk_backend_get_type (void);
PkBackend *pk_backend_new (void);
-PkActionList pk_backend_get_actions (PkBackend *backend);
+PkActionList *pk_backend_get_actions (PkBackend *backend);
gdouble pk_backend_get_runtime (PkBackend *backend);
gboolean pk_backend_load (PkBackend *backend,
const gchar *name);
+gboolean pk_backend_unload (PkBackend *backend);
const gchar *pk_backend_get_name (PkBackend *backend);
gboolean pk_backend_cancel_job_try (PkBackend *backend);
gboolean pk_backend_get_depends (PkBackend *backend,
diff --git a/src/pk-backend.c b/src/pk-backend.c
index 5e7ec17..01dcab9 100644
--- a/src/pk-backend.c
+++ b/src/pk-backend.c
@@ -82,20 +82,36 @@ static guint signals [PK_TASK_LAST_SIGNA
G_DEFINE_TYPE (PkBackend, pk_backend, G_TYPE_OBJECT)
+/**
+ * pk_backend_build_library_path:
+ **/
+gchar *
+pk_backend_build_library_path (PkBackend *backend)
+{
+ gchar *path;
+ gchar *filename;
+
+ g_return_val_if_fail (backend != NULL, NULL);
+
+ filename = g_strdup_printf ("libpk_backend_%s.so", backend->priv->name);
+ path = g_build_filename (LIBDIR, "packagekit-backend", filename, NULL);
+ g_free (filename);
+ return path;
+}
+
+/**
+ * pk_backend_load:
+ **/
gboolean
pk_backend_load (PkBackend *backend, const gchar *backend_name)
{
GModule *handle;
gchar *path;
- gchar *filename;
g_return_val_if_fail (backend_name != NULL, FALSE);
pk_debug ("Trying to load : %s", backend_name);
-
- filename = g_strdup_printf ("libpk_backend_%s.so", backend_name);
- path = g_build_filename (LIBDIR, "packagekit-backend", filename, NULL);
- g_free (filename);
+ path = pk_backend_build_library_path (backend);
handle = g_module_open (path, 0);
if (handle == NULL) {
pk_debug ("opening module %s failed : %s", backend_name, g_module_error ());
@@ -118,6 +134,20 @@ pk_backend_load (PkBackend *backend, con
return TRUE;
}
+/**
+ * pk_backend_unload:
+ **/
+gboolean
+pk_backend_unload (PkBackend *backend)
+{
+ if (backend->priv->handle == NULL) {
+ return FALSE;
+ }
+ g_module_close (backend->priv->handle);
+ backend->priv->handle = NULL;
+ return TRUE;
+}
+
const gchar *
pk_backend_get_name (PkBackend *backend)
{
@@ -879,11 +909,11 @@ pk_backend_update_system (PkBackend *bac
/**
* pk_backend_get_actions:
*/
-PkActionList
+PkActionList *
pk_backend_get_actions (PkBackend *backend)
{
PkActionList *alist;
- alist = pk_util_action_append (alist, PK_TASK_ACTION_UNKNOWN);
+ alist = pk_util_action_new (PK_TASK_ACTION_UNKNOWN);
if (backend->desc->cancel_job_try != NULL) {
pk_util_action_append (alist, PK_TASK_ACTION_CANCEL_JOB);
}
@@ -966,8 +996,7 @@ pk_backend_finalize (GObject *object)
}
g_free (backend->priv->name);
- g_debug ("g_module_close(%p)", backend->priv->handle);
- g_module_close (backend->priv->handle);
+ pk_backend_unload (backend);
g_timer_destroy (backend->priv->timer);
g_object_unref (backend->priv->network);
diff --git a/src/pk-engine.c b/src/pk-engine.c
index 88aa0f7..679e546 100644
--- a/src/pk-engine.c
+++ b/src/pk-engine.c
@@ -1385,11 +1385,18 @@ pk_engine_cancel_job_try (PkEngine *engi
gboolean
pk_engine_get_actions (PkEngine *engine, gchar **actions, GError **error)
{
+ PkBackend *task;
+ PkActionList *alist;
+
g_return_val_if_fail (engine != NULL, FALSE);
g_return_val_if_fail (PK_IS_ENGINE (engine), FALSE);
-// *actions = pk_backend_get_actions ();
-xxx
+ /* create a new task and start it */
+ task = pk_engine_new_task (engine);
+ alist = pk_backend_get_actions (task);
+ g_object_unref (task);
+ *actions = pk_util_action_to_string (alist);
+
return TRUE;
}
diff-tree a03e2417fdcd1f0deba14bdd863ac1388d4c71d1 (from dbb3f04496ea365da87a60860e4542b986e4eb87)
Author: Richard Hughes <richard at hughsie.com>
Date: Thu Sep 6 19:42:42 2007 +0100
add some extra enums
diff --git a/libpackagekit/pk-task-utils.h b/libpackagekit/pk-task-utils.h
index 5609ecb..25fea82 100644
--- a/libpackagekit/pk-task-utils.h
+++ b/libpackagekit/pk-task-utils.h
@@ -107,6 +107,9 @@ typedef enum {
PK_TASK_ACTION_GET_DEPENDS,
PK_TASK_ACTION_GET_REQUIRES,
PK_TASK_ACTION_GET_DESCRIPTION,
+ PK_TASK_ACTION_INSTALL_PACKAGE,
+ PK_TASK_ACTION_REMOVE_PACKAGE,
+ PK_TASK_ACTION_UPDATE_PACKAGE,
PK_TASK_ACTION_UNKNOWN
} PkTaskAction;
diff --git a/src/pk-backend.c b/src/pk-backend.c
index 7b500fd..5e7ec17 100644
--- a/src/pk-backend.c
+++ b/src/pk-backend.c
@@ -38,6 +38,7 @@
#include <glib/gi18n.h>
#include <gmodule.h>
#include <pk-package-id.h>
+#include <pk-task-utils.h>
#include "pk-debug.h"
#include "pk-backend-internal.h"
@@ -878,7 +879,7 @@ pk_backend_update_system (PkBackend *bac
/**
* pk_backend_get_actions:
*/
-PkActionLisk
+PkActionList
pk_backend_get_actions (PkBackend *backend)
{
PkActionList *alist;
diff-tree dbb3f04496ea365da87a60860e4542b986e4eb87 (from parents)
Merge: 4ca827c751d8609f0d938d544570a674c557741a 8d16b959fff9df9d07d93c6315b960a159bdf29f
Author: Richard Hughes <richard at hughsie.com>
Date: Thu Sep 6 19:39:07 2007 +0100
Merge branch 'master' into plugin
diff-tree 8d16b959fff9df9d07d93c6315b960a159bdf29f (from 702f6d1d66126606d4b48c409036c790774c5019)
Author: Richard Hughes <richard at hughsie.com>
Date: Thu Sep 6 19:37:38 2007 +0100
automatically get the actions
diff --git a/libpackagekit/pk-task-utils.c b/libpackagekit/pk-task-utils.c
index 492c4b3..55b3caa 100644
--- a/libpackagekit/pk-task-utils.c
+++ b/libpackagekit/pk-task-utils.c
@@ -518,6 +518,16 @@ pk_util_action_to_string (PkActionList *
}
/**
+ * pk_util_action_append:
+ **/
+gboolean
+pk_util_action_append (PkActionList *alist, PkTaskAction action)
+{
+ g_ptr_array_add (alist, GUINT_TO_POINTER(action));
+ return TRUE;
+}
+
+/**
* pk_util_action_contains:
**/
gboolean
diff --git a/libpackagekit/pk-task-utils.h b/libpackagekit/pk-task-utils.h
index 873caa6..5609ecb 100644
--- a/libpackagekit/pk-task-utils.h
+++ b/libpackagekit/pk-task-utils.h
@@ -144,6 +144,8 @@ PkActionList *pk_util_action_new_from_st
gchar *pk_util_action_to_string (PkActionList *alist);
gboolean pk_util_action_contains (PkActionList *alist,
PkTaskAction action);
+gboolean pk_util_action_append (PkActionList *alist,
+ PkTaskAction action);
gboolean pk_util_action_free (PkActionList *alist);
G_END_DECLS
diff --git a/src/pk-backend-internal.h b/src/pk-backend-internal.h
index 7cb9e7e..223dbf1 100644
--- a/src/pk-backend-internal.h
+++ b/src/pk-backend-internal.h
@@ -23,6 +23,7 @@
#define __PK_BACKEND_INTERNAL_H
#include <glib-object.h>
+#include <pk-task-utils.h>
#include "pk-backend.h"
G_BEGIN_DECLS
@@ -53,6 +54,7 @@ struct _PkBackendClass
/* general */
GType pk_backend_get_type (void);
PkBackend *pk_backend_new (void);
+PkActionList pk_backend_get_actions (PkBackend *backend);
gdouble pk_backend_get_runtime (PkBackend *backend);
gboolean pk_backend_load (PkBackend *backend,
const gchar *name);
diff --git a/src/pk-backend.c b/src/pk-backend.c
index 964fa76..7b500fd 100644
--- a/src/pk-backend.c
+++ b/src/pk-backend.c
@@ -876,6 +876,59 @@ pk_backend_update_system (PkBackend *bac
}
/**
+ * pk_backend_get_actions:
+ */
+PkActionLisk
+pk_backend_get_actions (PkBackend *backend)
+{
+ PkActionList *alist;
+ alist = pk_util_action_append (alist, PK_TASK_ACTION_UNKNOWN);
+ if (backend->desc->cancel_job_try != NULL) {
+ pk_util_action_append (alist, PK_TASK_ACTION_CANCEL_JOB);
+ }
+ if (backend->desc->get_depends != NULL) {
+ pk_util_action_append (alist, PK_TASK_ACTION_GET_DEPENDS);
+ }
+ if (backend->desc->get_description != NULL) {
+ pk_util_action_append (alist, PK_TASK_ACTION_GET_DESCRIPTION);
+ }
+ if (backend->desc->get_requires != NULL) {
+ pk_util_action_append (alist, PK_TASK_ACTION_GET_REQUIRES);
+ }
+ if (backend->desc->get_updates != NULL) {
+ pk_util_action_append (alist, PK_TASK_ACTION_GET_UPDATES);
+ }
+ if (backend->desc->install_package != NULL) {
+ pk_util_action_append (alist, PK_TASK_ACTION_INSTALL_PACKAGE);
+ }
+ if (backend->desc->refresh_cache != NULL) {
+ pk_util_action_append (alist, PK_TASK_ACTION_REFRESH_CACHE);
+ }
+ if (backend->desc->remove_package != NULL) {
+ pk_util_action_append (alist, PK_TASK_ACTION_REMOVE_PACKAGE);
+ }
+ if (backend->desc->search_details != NULL) {
+ pk_util_action_append (alist, PK_TASK_ACTION_SEARCH_DETAILS);
+ }
+ if (backend->desc->search_file != NULL) {
+ pk_util_action_append (alist, PK_TASK_ACTION_SEARCH_FILE);
+ }
+ if (backend->desc->search_group != NULL) {
+ pk_util_action_append (alist, PK_TASK_ACTION_SEARCH_GROUP);
+ }
+ if (backend->desc->search_name != NULL) {
+ pk_util_action_append (alist, PK_TASK_ACTION_SEARCH_NAME);
+ }
+ if (backend->desc->update_package != NULL) {
+ pk_util_action_append (alist, PK_TASK_ACTION_UPDATE_PACKAGE);
+ }
+ if (backend->desc->update_system != NULL) {
+ pk_util_action_append (alist, PK_TASK_ACTION_UPDATE_SYSTEM);
+ }
+ return alist;
+}
+
+/**
* pk_backend_get_runtime:
*/
gdouble
diff-tree 4ca827c751d8609f0d938d544570a674c557741a (from parents)
Merge: 74b8ef8ed1b7ef243a082c82c5f738d8e352b1bc 83c8cdcde6a0ba7bb8b9debd316c7d3120431395
Author: Richard Hughes <richard at hughsie.com>
Date: Thu Sep 6 18:29:24 2007 +0100
Merge branch 'master' into plugin
diff-tree 74b8ef8ed1b7ef243a082c82c5f738d8e352b1bc (from parents)
Merge: 5a3e274941117833c42e2e2b750742c4763f60d7 67ef712edcb52b0b75ab43d44222f8b172a92b64
Author: Richard Hughes <richard at hughsie.com>
Date: Thu Sep 6 18:24:44 2007 +0100
Merge branch 'master' into plugin
diff --cc src/pk-engine.c
index 5648e63,7dd1c91..88aa0f7
@@@ -1314,10 -1309,10 +1314,10 @@@
map = pk_get_map_from_job (engine, job);
if (map == NULL) {
g_set_error (error, PK_ENGINE_ERROR, PK_ENGINE_ERROR_NO_SUCH_JOB,
- "No job:%i", map->job);
+ "No job:%i", job);
return FALSE;
}
- pk_task_get_job_status (map->task, &status_enum);
+ pk_backend_get_job_status (map->task, &status_enum);
*status = g_strdup (pk_task_status_to_text (status_enum));
return TRUE;
@@@ -1339,10 -1334,10 +1339,10 @@@
map = pk_get_map_from_job (engine, job);
if (map == NULL) {
g_set_error (error, PK_ENGINE_ERROR, PK_ENGINE_ERROR_NO_SUCH_JOB,
- "No job:%i", map->job);
+ "No job:%i", job);
return FALSE;
}
- pk_task_get_job_role (map->task, &role_enum, package_id);
+ pk_backend_get_job_role (map->task, &role_enum, package_id);
*role = g_strdup (pk_task_role_to_text (role_enum));
return TRUE;
diff-tree 5a3e274941117833c42e2e2b750742c4763f60d7 (from 1451794d8315f447f85fa51a639c0b85effc06c5)
Author: Richard Hughes <richard at hughsie.com>
Date: Thu Sep 6 01:00:23 2007 +0100
connect up the backend code
diff --git a/src/Makefile.am b/src/Makefile.am
index a24d24a..da3a95e 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -39,11 +39,11 @@ sbin_PROGRAMS = \
packagekitd_SOURCES = \
pk-main.c \
- pk-task.h \
- pk-task-common.h \
- pk-task-common.c \
pk-marshal.c \
pk-marshal.h \
+ pk-backend-internal.h \
+ pk-backend.c \
+ pk-backend.h \
pk-spawn.c \
pk-spawn.h \
pk-engine.h \
@@ -52,31 +52,6 @@ packagekitd_SOURCES = \
pk-network.c \
$(NULL)
-if BACKEND_TYPE_DUMMY
-packagekitd_SOURCES += \
- pk-task-dummy.c
-endif
-
-if BACKEND_TYPE_APT
-packagekitd_SOURCES += \
- pk-task-apt.cpp
-endif
-
-if BACKEND_TYPE_YUM
-packagekitd_SOURCES += \
- pk-task-yum.c
-endif
-
-if BACKEND_TYPE_CONARY
-packagekitd_SOURCES += \
- pk-task-conary.c
-endif
-
-if BACKEND_TYPE_BOX
-packagekitd_SOURCES += \
- pk-task-box.c
-endif
-
packagekitd_LDADD = \
$(GLIB_LIBS) \
$(GMODULE_LIBS) \
diff --git a/src/pk-engine.c b/src/pk-engine.c
index e8ff6e9..5648e63 100644
--- a/src/pk-engine.c
+++ b/src/pk-engine.c
@@ -41,9 +41,8 @@
#include <pk-package-id.h>
#include <pk-debug.h>
-#include "pk-task.h"
#include "pk-task-utils.h"
-#include "pk-task-common.h"
+#include "pk-backend-internal.h"
#include "pk-engine.h"
#include "pk-marshal.h"
@@ -61,6 +60,7 @@ struct PkEnginePrivate
guint job_count;
PolKitContext *pk_context;
DBusConnection *connection;
+ gchar *backend;
};
enum {
@@ -80,7 +80,7 @@ enum {
typedef struct {
guint job;
- PkTask *task;
+ PkBackend *task;
} PkEngineMap;
static guint signals [PK_ENGINE_LAST_SIGNAL] = { 0, };
@@ -134,6 +134,7 @@ gboolean
pk_engine_use_backend (PkEngine *engine, const gchar *backend)
{
pk_debug ("trying backend %s", backend);
+ engine->priv->backend = g_strdup (backend);
return TRUE;
}
@@ -201,7 +202,7 @@ pk_get_map_from_job (PkEngine *engine, g
* pk_get_map_from_task:
**/
static PkEngineMap *
-pk_get_map_from_task (PkEngine *engine, PkTask *task)
+pk_get_map_from_task (PkEngine *engine, PkBackend *task)
{
guint i;
guint length;
@@ -244,7 +245,7 @@ pk_engine_job_list_changed (PkEngine *en
* pk_engine_job_status_changed_cb:
**/
static void
-pk_engine_job_status_changed_cb (PkTask *task, PkTaskStatus status, PkEngine *engine)
+pk_engine_job_status_changed_cb (PkBackend *task, PkTaskStatus status, PkEngine *engine)
{
PkEngineMap *map;
const gchar *status_text;
@@ -257,7 +258,7 @@ pk_engine_job_status_changed_cb (PkTask
pk_warning ("could not find task");
return;
}
- status_text = pk_task_status_to_text (status);
+ status_text = pk_task_status_to_text (status);
pk_debug ("emitting job-status-changed job:%i, '%s'", map->job, status_text);
g_signal_emit (engine, signals [PK_ENGINE_JOB_STATUS_CHANGED], 0, map->job, status_text);
@@ -268,7 +269,7 @@ pk_engine_job_status_changed_cb (PkTask
* pk_engine_percentage_changed_cb:
**/
static void
-pk_engine_percentage_changed_cb (PkTask *task, guint percentage, PkEngine *engine)
+pk_engine_percentage_changed_cb (PkBackend *task, guint percentage, PkEngine *engine)
{
PkEngineMap *map;
@@ -289,7 +290,7 @@ pk_engine_percentage_changed_cb (PkTask
* pk_engine_sub_percentage_changed_cb:
**/
static void
-pk_engine_sub_percentage_changed_cb (PkTask *task, guint percentage, PkEngine *engine)
+pk_engine_sub_percentage_changed_cb (PkBackend *task, guint percentage, PkEngine *engine)
{
PkEngineMap *map;
@@ -310,7 +311,7 @@ pk_engine_sub_percentage_changed_cb (PkT
* pk_engine_no_percentage_updates_cb:
**/
static void
-pk_engine_no_percentage_updates_cb (PkTask *task, PkEngine *engine)
+pk_engine_no_percentage_updates_cb (PkBackend *task, PkEngine *engine)
{
PkEngineMap *map;
@@ -331,7 +332,7 @@ pk_engine_no_percentage_updates_cb (PkTa
* pk_engine_package_cb:
**/
static void
-pk_engine_package_cb (PkTask *task, guint value, const gchar *package_id, const gchar *summary, PkEngine *engine)
+pk_engine_package_cb (PkBackend *task, guint value, const gchar *package_id, const gchar *summary, PkEngine *engine)
{
PkEngineMap *map;
@@ -352,7 +353,7 @@ pk_engine_package_cb (PkTask *task, guin
* pk_engine_error_code_cb:
**/
static void
-pk_engine_error_code_cb (PkTask *task, PkTaskErrorCode code, const gchar *details, PkEngine *engine)
+pk_engine_error_code_cb (PkBackend *task, PkTaskErrorCode code, const gchar *details, PkEngine *engine)
{
PkEngineMap *map;
const gchar *code_text;
@@ -375,7 +376,7 @@ pk_engine_error_code_cb (PkTask *task, P
* pk_engine_require_restart_cb:
**/
static void
-pk_engine_require_restart_cb (PkTask *task, PkTaskRestart restart, const gchar *details, PkEngine *engine)
+pk_engine_require_restart_cb (PkBackend *task, PkTaskRestart restart, const gchar *details, PkEngine *engine)
{
PkEngineMap *map;
const gchar *restart_text;
@@ -398,7 +399,7 @@ pk_engine_require_restart_cb (PkTask *ta
* pk_engine_description_cb:
**/
static void
-pk_engine_description_cb (PkTask *task, const gchar *package_id, PkTaskGroup group,
+pk_engine_description_cb (PkBackend *task, const gchar *package_id, PkTaskGroup group,
const gchar *detail, const gchar *url, PkEngine *engine)
{
PkEngineMap *map;
@@ -422,7 +423,7 @@ pk_engine_description_cb (PkTask *task,
* pk_engine_finished_cb:
**/
static void
-pk_engine_finished_cb (PkTask *task, PkTaskExit exit, PkEngine *engine)
+pk_engine_finished_cb (PkBackend *task, PkTaskExit exit, PkEngine *engine)
{
PkEngineMap *map;
const gchar *exit_text;
@@ -439,7 +440,8 @@ pk_engine_finished_cb (PkTask *task, PkT
exit_text = pk_task_exit_to_text (exit);
/* find the length of time we have been running */
- time = g_timer_elapsed (task->timer, NULL);
+ time = pk_backend_get_runtime (task);
+
pk_debug ("task was running for %f seconds", time);
pk_debug ("emitting finished job: %i, '%s', %i", map->job, exit_text, (guint) time);
@@ -449,7 +451,6 @@ pk_engine_finished_cb (PkTask *task, PkT
g_ptr_array_remove (engine->priv->array, map);
g_free (map);
- pk_task_common_free (task);
g_object_unref (task);
pk_debug ("removed task %p", task);
pk_engine_job_list_changed (engine);
@@ -460,7 +461,7 @@ pk_engine_finished_cb (PkTask *task, PkT
* pk_engine_allow_interrupt_cb:
**/
static void
-pk_engine_allow_interrupt_cb (PkTask *task, gboolean allow_kill, PkEngine *engine)
+pk_engine_allow_interrupt_cb (PkBackend *task, gboolean allow_kill, PkEngine *engine)
{
PkEngineMap *map;
@@ -519,16 +520,21 @@ pk_engine_save_job_count (PkEngine *engi
/**
* pk_engine_new_task:
**/
-static PkTask *
+static PkBackend *
pk_engine_new_task (PkEngine *engine)
{
- PkTask *task;
+ PkBackend *task;
+ gboolean ret;
/* increment the job number - we never repeat an id */
engine->priv->job_count++;
/* allocate a new task */
- task = pk_task_new ();
+ task = pk_backend_new ();
+ ret = pk_backend_load (task, engine->priv->backend);
+ if (ret == FALSE) {
+ pk_error ("Cannot use backend '%s'", engine->priv->backend);
+ }
pk_debug ("adding task %p", task);
/* connect up signals */
@@ -554,7 +560,6 @@ pk_engine_new_task (PkEngine *engine)
G_CALLBACK (pk_engine_allow_interrupt_cb), engine);
/* initialise some stuff */
- pk_task_common_init (task);
pk_engine_reset_timer (engine);
/* we don't add to the array or do the job-list-changed yet
@@ -566,7 +571,7 @@ pk_engine_new_task (PkEngine *engine)
* pk_engine_add_task:
**/
static gboolean
-pk_engine_add_task (PkEngine *engine, PkTask *task)
+pk_engine_add_task (PkEngine *engine, PkBackend *task)
{
PkEngineMap *map;
@@ -651,7 +656,7 @@ gboolean
pk_engine_refresh_cache (PkEngine *engine, gboolean force, guint *job, GError **error)
{
gboolean ret;
- PkTask *task;
+ PkBackend *task;
PkEngineMap *map;
g_return_val_if_fail (engine != NULL, FALSE);
@@ -659,7 +664,7 @@ pk_engine_refresh_cache (PkEngine *engin
/* create a new task and start it */
task = pk_engine_new_task (engine);
- ret = pk_task_refresh_cache (task, force);
+ ret = pk_backend_refresh_cache (task, force);
if (ret == FALSE) {
g_set_error (error, PK_ENGINE_ERROR, PK_ENGINE_ERROR_NOT_SUPPORTED,
"operation not yet supported by backend");
@@ -684,7 +689,7 @@ gboolean
pk_engine_get_updates (PkEngine *engine, guint *job, GError **error)
{
gboolean ret;
- PkTask *task;
+ PkBackend *task;
PkEngineMap *map;
g_return_val_if_fail (engine != NULL, FALSE);
@@ -692,7 +697,7 @@ pk_engine_get_updates (PkEngine *engine,
/* create a new task and start it */
task = pk_engine_new_task (engine);
- ret = pk_task_get_updates (task);
+ ret = pk_backend_get_updates (task);
if (ret == FALSE) {
g_set_error (error, PK_ENGINE_ERROR, PK_ENGINE_ERROR_NOT_SUPPORTED,
"operation not yet supported by backend");
@@ -711,7 +716,7 @@ pk_engine_get_updates (PkEngine *engine,
}
/**
- * pk_task_search_check:
+ * pk_engine_search_check:
**/
gboolean
pk_engine_search_check (const gchar *search, GError **error)
@@ -745,7 +750,7 @@ pk_engine_search_check (const gchar *sea
}
/**
- * pk_task_filter_check:
+ * pk_engine_filter_check:
**/
gboolean
pk_engine_filter_check (const gchar *filter, GError **error)
@@ -770,7 +775,7 @@ pk_engine_search_name (PkEngine *engine,
guint *job, GError **error)
{
gboolean ret;
- PkTask *task;
+ PkBackend *task;
PkEngineMap *map;
g_return_val_if_fail (engine != NULL, FALSE);
@@ -790,7 +795,7 @@ pk_engine_search_name (PkEngine *engine,
/* create a new task and start it */
task = pk_engine_new_task (engine);
- ret = pk_task_search_name (task, filter, search);
+ ret = pk_backend_search_name (task, filter, search);
if (ret == FALSE) {
g_set_error (error, PK_ENGINE_ERROR, PK_ENGINE_ERROR_NOT_SUPPORTED,
"operation not yet supported by backend");
@@ -816,7 +821,7 @@ pk_engine_search_details (PkEngine *engi
guint *job, GError **error)
{
gboolean ret;
- PkTask *task;
+ PkBackend *task;
PkEngineMap *map;
g_return_val_if_fail (engine != NULL, FALSE);
@@ -836,7 +841,7 @@ pk_engine_search_details (PkEngine *engi
/* create a new task and start it */
task = pk_engine_new_task (engine);
- ret = pk_task_search_details (task, filter, search);
+ ret = pk_backend_search_details (task, filter, search);
if (ret == FALSE) {
g_set_error (error, PK_ENGINE_ERROR, PK_ENGINE_ERROR_NOT_SUPPORTED,
"operation not yet supported by backend");
@@ -862,7 +867,7 @@ pk_engine_search_group (PkEngine *engine
guint *job, GError **error)
{
gboolean ret;
- PkTask *task;
+ PkBackend *task;
PkEngineMap *map;
g_return_val_if_fail (engine != NULL, FALSE);
@@ -882,7 +887,7 @@ pk_engine_search_group (PkEngine *engine
/* create a new task and start it */
task = pk_engine_new_task (engine);
- ret = pk_task_search_group (task, filter, search);
+ ret = pk_backend_search_group (task, filter, search);
if (ret == FALSE) {
g_set_error (error, PK_ENGINE_ERROR, PK_ENGINE_ERROR_NOT_SUPPORTED,
"operation not yet supported by backend");
@@ -908,7 +913,7 @@ pk_engine_search_file (PkEngine *engine,
guint *job, GError **error)
{
gboolean ret;
- PkTask *task;
+ PkBackend *task;
PkEngineMap *map;
g_return_val_if_fail (engine != NULL, FALSE);
@@ -928,7 +933,7 @@ pk_engine_search_file (PkEngine *engine,
/* create a new task and start it */
task = pk_engine_new_task (engine);
- ret = pk_task_search_file (task, filter, search);
+ ret = pk_backend_search_file (task, filter, search);
if (ret == FALSE) {
g_set_error (error, PK_ENGINE_ERROR, PK_ENGINE_ERROR_NOT_SUPPORTED,
"operation not yet supported by backend");
@@ -954,7 +959,7 @@ pk_engine_get_depends (PkEngine *engine,
guint *job, GError **error)
{
gboolean ret;
- PkTask *task;
+ PkBackend *task;
PkEngineMap *map;
g_return_val_if_fail (engine != NULL, FALSE);
@@ -970,7 +975,7 @@ pk_engine_get_depends (PkEngine *engine,
/* create a new task and start it */
task = pk_engine_new_task (engine);
- ret = pk_task_get_depends (task, package_id);
+ ret = pk_backend_get_depends (task, package_id);
if (ret == FALSE) {
g_set_error (error, PK_ENGINE_ERROR, PK_ENGINE_ERROR_NOT_SUPPORTED,
"operation not yet supported by backend");
@@ -996,7 +1001,7 @@ pk_engine_get_requires (PkEngine *engine
guint *job, GError **error)
{
gboolean ret;
- PkTask *task;
+ PkBackend *task;
PkEngineMap *map;
g_return_val_if_fail (engine != NULL, FALSE);
@@ -1012,7 +1017,7 @@ pk_engine_get_requires (PkEngine *engine
/* create a new task and start it */
task = pk_engine_new_task (engine);
- ret = pk_task_get_requires (task, package_id);
+ ret = pk_backend_get_requires (task, package_id);
if (ret == FALSE) {
g_set_error (error, PK_ENGINE_ERROR, PK_ENGINE_ERROR_NOT_SUPPORTED,
"operation not yet supported by backend");
@@ -1038,7 +1043,7 @@ pk_engine_get_description (PkEngine *eng
guint *job, GError **error)
{
gboolean ret;
- PkTask *task;
+ PkBackend *task;
PkEngineMap *map;
g_return_val_if_fail (engine != NULL, FALSE);
@@ -1046,7 +1051,7 @@ pk_engine_get_description (PkEngine *eng
/* create a new task and start it */
task = pk_engine_new_task (engine);
- ret = pk_task_get_description (task, package_id);
+ ret = pk_backend_get_description (task, package_id);
if (ret == FALSE) {
g_set_error (error, PK_ENGINE_ERROR, PK_ENGINE_ERROR_NOT_SUPPORTED,
"operation not yet supported by backend");
@@ -1076,7 +1081,7 @@ pk_engine_update_system (PkEngine *engin
PkTaskRole role;
gboolean ret;
GError *error;
- PkTask *task;
+ PkBackend *task;
PkEngineMap *map;
g_return_if_fail (engine != NULL);
@@ -1093,7 +1098,7 @@ pk_engine_update_system (PkEngine *engin
length = engine->priv->array->len;
for (i=0; i<length; i++) {
map = (PkEngineMap *) g_ptr_array_index (engine->priv->array, i);
- ret = pk_task_get_job_role (map->task, &role, NULL);
+ ret = pk_backend_get_job_role (map->task, &role, NULL);
if (ret == TRUE && role == PK_TASK_ROLE_SYSTEM_UPDATE) {
error = g_error_new (PK_ENGINE_ERROR, PK_ENGINE_ERROR_DENIED,
"operation not yet supported by backend");
@@ -1104,7 +1109,7 @@ pk_engine_update_system (PkEngine *engin
/* create a new task and start it */
task = pk_engine_new_task (engine);
- ret = pk_task_update_system (task);
+ ret = pk_backend_update_system (task);
if (ret == FALSE) {
error = g_error_new (PK_ENGINE_ERROR, PK_ENGINE_ERROR_NOT_SUPPORTED,
"operation not yet supported by backend");
@@ -1131,7 +1136,7 @@ pk_engine_remove_package (PkEngine *engi
{
PkEngineMap *map;
gboolean ret;
- PkTask *task;
+ PkBackend *task;
GError *error;
g_return_if_fail (engine != NULL);
@@ -1155,7 +1160,7 @@ pk_engine_remove_package (PkEngine *engi
/* create a new task and start it */
task = pk_engine_new_task (engine);
- ret = pk_task_remove_package (task, package_id, allow_deps);
+ ret = pk_backend_remove_package (task, package_id, allow_deps);
if (ret == FALSE) {
error = g_error_new (PK_ENGINE_ERROR, PK_ENGINE_ERROR_NOT_SUPPORTED,
"operation not yet supported by backend");
@@ -1184,7 +1189,7 @@ pk_engine_install_package (PkEngine *eng
{
gboolean ret;
PkEngineMap *map;
- PkTask *task;
+ PkBackend *task;
GError *error;
g_return_if_fail (engine != NULL);
@@ -1208,7 +1213,7 @@ pk_engine_install_package (PkEngine *eng
/* create a new task and start it */
task = pk_engine_new_task (engine);
- ret = pk_task_install_package (task, package_id);
+ ret = pk_backend_install_package (task, package_id);
if (ret == FALSE) {
error = g_error_new (PK_ENGINE_ERROR, PK_ENGINE_ERROR_NOT_SUPPORTED,
"operation not yet supported by backend");
@@ -1237,7 +1242,7 @@ pk_engine_update_package (PkEngine *engi
{
gboolean ret;
PkEngineMap *map;
- PkTask *task;
+ PkBackend *task;
GError *error;
g_return_if_fail (engine != NULL);
@@ -1261,7 +1266,7 @@ pk_engine_update_package (PkEngine *engi
/* create a new task and start it */
task = pk_engine_new_task (engine);
- ret = pk_task_update_package (task, package_id);
+ ret = pk_backend_update_package (task, package_id);
if (ret == FALSE) {
error = g_error_new (PK_ENGINE_ERROR, PK_ENGINE_ERROR_NOT_SUPPORTED,
"operation not yet supported by backend");
@@ -1312,7 +1317,7 @@ pk_engine_get_job_status (PkEngine *engi
"No job:%i", map->job);
return FALSE;
}
- pk_task_get_job_status (map->task, &status_enum);
+ pk_backend_get_job_status (map->task, &status_enum);
*status = g_strdup (pk_task_status_to_text (status_enum));
return TRUE;
@@ -1337,7 +1342,7 @@ pk_engine_get_job_role (PkEngine *engine
"No job:%i", map->job);
return FALSE;
}
- pk_task_get_job_role (map->task, &role_enum, package_id);
+ pk_backend_get_job_role (map->task, &role_enum, package_id);
*role = g_strdup (pk_task_role_to_text (role_enum));
return TRUE;
@@ -1362,7 +1367,7 @@ pk_engine_cancel_job_try (PkEngine *engi
return FALSE;
}
- ret = pk_task_cancel_job_try (map->task);
+ ret = pk_backend_cancel_job_try (map->task);
if (ret == FALSE) {
g_set_error (error, PK_ENGINE_ERROR, PK_ENGINE_ERROR_NOT_SUPPORTED,
"operation not yet supported by backend");
@@ -1383,7 +1388,8 @@ pk_engine_get_actions (PkEngine *engine,
g_return_val_if_fail (engine != NULL, FALSE);
g_return_val_if_fail (PK_IS_ENGINE (engine), FALSE);
- *actions = pk_task_get_actions ();
+// *actions = pk_backend_get_actions ();
+xxx
return TRUE;
}
@@ -1496,6 +1502,7 @@ pk_engine_init (PkEngine *engine)
engine->priv = PK_ENGINE_GET_PRIVATE (engine);
engine->priv->array = g_ptr_array_new ();
engine->priv->timer = g_timer_new ();
+ engine->priv->backend = NULL;
engine->priv->job_count = pk_engine_load_job_count (engine);
@@ -1538,6 +1545,7 @@ pk_engine_finalize (GObject *object)
/* compulsory gobjects */
g_ptr_array_free (engine->priv->array, TRUE);
g_timer_destroy (engine->priv->timer);
+ g_free (engine->priv->backend);
polkit_context_unref (engine->priv->pk_context);
G_OBJECT_CLASS (pk_engine_parent_class)->finalize (object);
More information about the PackageKit
mailing list