[packagekit] packagekit: Branch 'master' - 6 commits
Richard Hughes
hughsient at kemper.freedesktop.org
Fri Aug 31 18:31:52 PDT 2007
Makefile.am | 1
configure.ac | 15 +
data/.gitignore | 2
data/Makefile.am | 33 ++
data/job_count.dat | 1
helpers/BACKENDS | 24 -
helpers/Makefile.am | 46 ---
helpers/README | 2
helpers/box/Makefile.am | 15 +
helpers/box/refresh-cache.sh | 8
helpers/conary-get-description.py | 14 -
helpers/conary-remove.py | 14 -
helpers/conary-update-system.py | 14 -
helpers/conary/Makefile.am | 25 +
helpers/conary/packagekit.py | 1
helpers/test-backend.sh | 28 +-
helpers/yum-search-group.py | 23 -
helpers/yum/Makefile.am | 28 ++
src/.gitignore | 1
src/Makefile.am | 36 +-
src/pk-engine.c | 53 +++
src/pk-task-box.c | 525 ++++++++++++++++++++++++++++++++++++++
src/pk-task-common.c | 5
23 files changed, 749 insertions(+), 165 deletions(-)
New commits:
diff-tree 819bfb84e0f0c55b390401256d680012f1232d5c (from 164174a9b59f394a6226405fa7af4d9c7b2165cd)
Author: Richard Hughes <richard at hughsie.com>
Date: Sat Sep 1 02:25:05 2007 +0100
add a job_count file to keep track of job ids. This should fix many hard to fix oddites when restarting the daemon at odd times
diff --git a/Makefile.am b/Makefile.am
index 50a956f..fd5c47c 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -1,6 +1,7 @@
SUBDIRS = \
policy \
man \
+ data \
libselftest \
libgbus \
libpackagekit \
diff --git a/configure.ac b/configure.ac
index d9acf4b..7201e94 100644
--- a/configure.ac
+++ b/configure.ac
@@ -313,6 +313,7 @@ AC_OUTPUT([
packagekit.pc
Makefile
man/Makefile
+data/Makefile
libselftest/Makefile
libgbus/Makefile
libpackagekit/Makefile
diff --git a/data/.gitignore b/data/.gitignore
new file mode 100644
index 0000000..db48c64
--- /dev/null
+++ b/data/.gitignore
@@ -0,0 +1,2 @@
+org.freedesktop.PackageKit.service
+
diff --git a/data/Makefile.am b/data/Makefile.am
new file mode 100644
index 0000000..a96d1fc
--- /dev/null
+++ b/data/Makefile.am
@@ -0,0 +1,33 @@
+## We require new-style dependency handling.
+AUTOMAKE_OPTIONS = 1.7
+
+NULL =
+
+servicedir = $(DBUS_SERVICES_DIR)
+service_in_files = org.freedesktop.PackageKit.service.in
+service_DATA = $(service_in_files:.service.in=.service)
+
+$(service_DATA): $(service_in_files) Makefile
+ @sed -e "s|\@servicedir\@|$(sbindir)|" $< > $@
+
+localcachedir = $(localstatedir)/run/PackageKit
+localcache_DATA = \
+ job_count.dat \
+ $(NULL)
+
+EXTRA_DIST = \
+ $(service_in_files) \
+ $(localcache_DATA) \
+ $(NULL)
+
+clean-local:
+ rm -f *~
+
+DISTCLEANFILES = \
+ org.freedesktop.PackageKit.service
+
+MAINTAINERCLEANFILES = \
+ *~ \
+ Makefile.in \
+ $(NULL)
+
diff --git a/data/job_count.dat b/data/job_count.dat
new file mode 100644
index 0000000..573541a
--- /dev/null
+++ b/data/job_count.dat
@@ -0,0 +1 @@
+0
diff --git a/data/org.freedesktop.PackageKit.service.in b/data/org.freedesktop.PackageKit.service.in
new file mode 100644
index 0000000..b778142
--- /dev/null
+++ b/data/org.freedesktop.PackageKit.service.in
@@ -0,0 +1,5 @@
+[D-BUS Service]
+Name=org.freedesktop.PackageKit
+Exec=@servicedir@/packagekitd
+User=root
+
diff --git a/src/.gitignore b/src/.gitignore
index 147af76..c2c4d8a 100644
--- a/src/.gitignore
+++ b/src/.gitignore
@@ -7,5 +7,4 @@ pk-interface.h
packagekitd
pk-self-test
debug.log
-org.freedesktop.PackageKit.service
diff --git a/src/Makefile.am b/src/Makefile.am
index deb9bb0..25dc135 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -3,13 +3,6 @@ AUTOMAKE_OPTIONS = 1.7
NULL =
-servicedir = $(DBUS_SERVICES_DIR)
-service_in_files = org.freedesktop.PackageKit.service.in
-service_DATA = $(service_in_files:.service.in=.service)
-
-$(service_DATA): $(service_in_files) Makefile
- @sed -e "s|\@servicedir\@|$(sbindir)|" $< > $@
-
PK_LIBS = \
$(top_builddir)/libpackagekit/libpackagekit.la \
$(NULL)
@@ -18,13 +11,6 @@ SELFTEST_LIBS = \
$(top_builddir)/libselftest/libselftest.la \
$(NULL)
-EXTRA_DIST = \
- pk-marshal.list \
- pk-interface.xml \
- pk-spawn-test.sh \
- $(service_in_files) \
- $(NULL)
-
INCLUDES = \
$(GLIB_CFLAGS) \
$(DBUS_CFLAGS) \
@@ -37,6 +23,7 @@ INCLUDES = \
-DLIBDIR=\""$(libdir)"\" \
-DVERSION="\"$(VERSION)\"" \
-DPK_DATA=\"$(pkgdatadir)\" \
+ -DLOCALSTATEDIR=\""$(localstatedir)"\" \
-I$(top_srcdir)/libpackagekit \
-I$(top_srcdir)/libselftest \
$(NULL)
@@ -148,13 +135,16 @@ pk_self_test_LDADD = \
pk_self_test_CPPFLAGS= \
-DPK_BUILD_TESTS
+EXTRA_DIST = \
+ pk-marshal.list \
+ pk-interface.xml \
+ pk-spawn-test.sh \
+ $(NULL)
+
clean-local:
rm -f *~
rm -f pk-marshal.c pk-marshal.h
-DISTCLEANFILES = \
- org.freedesktop.PackageKit.service
-
CLEANFILES = $(BUILT_SOURCES)
TESTS = pk-self-test
diff --git a/src/org.freedesktop.PackageKit.service.in b/src/org.freedesktop.PackageKit.service.in
deleted file mode 100644
index b778142..0000000
--- a/src/org.freedesktop.PackageKit.service.in
+++ /dev/null
@@ -1,5 +0,0 @@
-[D-BUS Service]
-Name=org.freedesktop.PackageKit
-Exec=@servicedir@/packagekitd
-User=root
-
diff --git a/src/pk-engine.c b/src/pk-engine.c
index 1491747..c476f3e 100644
--- a/src/pk-engine.c
+++ b/src/pk-engine.c
@@ -52,11 +52,13 @@ static void pk_engine_init (PkEngin
static void pk_engine_finalize (GObject *object);
#define PK_ENGINE_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), PK_TYPE_ENGINE, PkEnginePrivate))
+#define PK_ENGINE_JOB_LAST_COUNT_FILE LOCALSTATEDIR "/run/PackageKit/job_count.dat"
struct PkEnginePrivate
{
GPtrArray *array;
GTimer *timer;
+ guint job_count;
PolKitContext *pk_context;
DBusConnection *connection;
};
@@ -400,16 +402,53 @@ pk_engine_allow_interrupt_cb (PkTask *ta
}
/**
+ * pk_engine_load_job_count:
+ **/
+static gboolean
+pk_engine_load_job_count (PkEngine *engine)
+{
+ gboolean ret;
+ gchar *contents;
+ ret = g_file_get_contents (PK_ENGINE_JOB_LAST_COUNT_FILE, &contents, NULL, NULL);
+ if (ret == FALSE) {
+ pk_warning ("failed to get last job");
+ return FALSE;
+ }
+ engine->priv->job_count = atoi (contents);
+ pk_debug ("job=%i", engine->priv->job_count);
+ return TRUE;
+}
+
+/**
+ * pk_engine_save_job_count:
+ **/
+static gboolean
+pk_engine_save_job_count (PkEngine *engine)
+{
+ gboolean ret;
+ gchar *contents;
+
+ pk_debug ("saving %i", engine->priv->job_count);
+ contents = g_strdup_printf ("%i", engine->priv->job_count);
+ ret = g_file_set_contents (PK_ENGINE_JOB_LAST_COUNT_FILE, contents, -1, NULL);
+ g_free (contents);
+ if (ret == FALSE) {
+ pk_warning ("failed to set last job");
+ return FALSE;
+ }
+ return TRUE;
+}
+
+/**
* pk_engine_new_task:
**/
static PkTask *
pk_engine_new_task (PkEngine *engine)
{
PkTask *task;
- static guint job = 0;
/* increment the job number - we never repeat an id */
- job++;
+ engine->priv->job_count++;
/* allocate a new task */
task = pk_task_new ();
@@ -441,9 +480,12 @@ pk_engine_new_task (PkEngine *engine)
pk_task_common_init (task);
/* set the job ID */
- pk_task_set_job (task, job);
+ pk_task_set_job (task, engine->priv->job_count);
pk_engine_reset_timer (engine);
+ /* in an ideal workd we don't need this, but do it in case the daemon is ctrl-c;d */
+ pk_engine_save_job_count (engine);
+
/* we don't add to the array or do the job-list-changed yet
* as this job might fail */
return task;
@@ -1271,6 +1313,8 @@ pk_engine_init (PkEngine *engine)
engine->priv->array = g_ptr_array_new ();
engine->priv->timer = g_timer_new ();
+ engine->priv->job_count = pk_engine_load_job_count (engine);
+
/* get a connection to the bus */
dbus_error_init (&dbus_error);
engine->priv->connection = dbus_bus_get (DBUS_BUS_SYSTEM, &dbus_error);
@@ -1304,6 +1348,9 @@ pk_engine_finalize (GObject *object)
g_return_if_fail (engine->priv != NULL);
+ /* save last job id so we don't ever repeat */
+ pk_engine_save_job_count (engine);
+
/* compulsory gobjects */
g_ptr_array_free (engine->priv->array, TRUE);
g_timer_destroy (engine->priv->timer);
diff-tree 164174a9b59f394a6226405fa7af4d9c7b2165cd (from 94dcc14ace39f287b0432d800cb2e16783d28f7a)
Author: Richard Hughes <richard at hughsie.com>
Date: Sat Sep 1 01:27:46 2007 +0100
fix test script
diff --git a/helpers/test-backend.sh b/helpers/test-backend.sh
index 5784f79..0856173 100755
--- a/helpers/test-backend.sh
+++ b/helpers/test-backend.sh
@@ -6,58 +6,58 @@ package_id="BasiliskII;1.0-0.20060501.1.
backend="yum"
echo "get deps $package_id"
-./$backend-get-deps.py $package_id
+./$backend/get-deps.py $package_id
echo "exitcode=$?"
echo "get description $package_id"
-./$backend-get-description.py $package_id
+./$backend/get-description.py $package_id
echo "exitcode=$?"
echo "get updates"
-./$backend-get-updates.py
+./$backend/get-updates.py
echo "exitcode=$?"
echo "refresh cache"
-./$backend-refresh-cache.py
+./$backend/refresh-cache.py
echo "exitcode=$?"
echo "remove $package_id"
-./$backend-remove.py no $package_id
+./$backend/remove.py no $package_id
echo "exitcode=$?"
echo "remove $package_id (already removed)"
-./$backend-remove.py no $package_id
+./$backend/remove.py no $package_id
echo "exitcode=$?"
echo "install $package_id"
-./$backend-install.py $package_id
+./$backend/install.py $package_id
echo "exitcode=$?"
echo "install $package_id (already installed)"
-./$backend-install.py $package_id
+./$backend/install.py $package_id
echo "exitcode=$?"
echo "search details lm_sensors"
-./$backend-search-details.py none lm_sensors
+./$backend/search-details.py none lm_sensors
echo "exitcode=$?"
echo "search file gpm-prefs.glade"
-./$backend-search-file.py none gpm-prefs.glade
+./$backend/search-file.py none gpm-prefs.glade
echo "exitcode=$?"
echo "search group system"
-./$backend-search-group.py none system
+./$backend/search-group.py none system
echo "exitcode=$?"
echo "search name power"
-./$backend-search-name.py none power
+./$backend/search-name.py none power
echo "exitcode=$?"
echo "update $package_id"
-./$backend-update.py $package_id
+./$backend/update.py $package_id
echo "exitcode=$?"
echo "update system"
-./$backend-update-system.py
+./$backend/update-system.py
echo "exitcode=$?"
diff-tree 94dcc14ace39f287b0432d800cb2e16783d28f7a (from f7869a403ad9996bbd0c3a56bf4543cd4c84f94b)
Author: Richard Hughes <richard at hughsie.com>
Date: Sat Sep 1 01:04:20 2007 +0100
move the helper files into seporate folders
diff --git a/configure.ac b/configure.ac
index 74985d5..d9acf4b 100644
--- a/configure.ac
+++ b/configure.ac
@@ -320,6 +320,9 @@ policy/Makefile
src/Makefile
client/Makefile
helpers/Makefile
+helpers/box/Makefile
+helpers/conary/Makefile
+helpers/yum/Makefile
PackageKit.conf
])
diff --git a/helpers/Makefile.am b/helpers/Makefile.am
index 84e0a33..cb107a1 100644
--- a/helpers/Makefile.am
+++ b/helpers/Makefile.am
@@ -1,62 +1,13 @@
-
-helperdir = $(datadir)/PackageKit/helpers
-
-NULL =
-
-if BACKEND_TYPE_YUM
-dist_helper_DATA = \
- yum-search-name.py \
- yum-search-details.py \
- yum-search-group.py \
- yum-search-file.py \
- yum-get-deps.py \
- yum-get-updates.py \
- yum-get-description.py \
- yum-install.py \
- yum-remove.py \
- yum-update.py \
- yum-refresh-cache.py \
- yum-update-system.py \
- yumBackend.py \
- packagekit.py \
- $(NULL)
-endif
-
-if BACKEND_TYPE_CONARY
-dist_helper_DATA = \
- conary-search-name.py \
- conary-search-details.py \
- conary-get-deps.py \
- conary-get-updates.py \
- conary-install.py \
- conary-refresh-cache.py \
- conary-remove.py \
- conary-update-system.py \
- conary-get-description.py \
- conaryBackend.py \
- packagekit.py \
- $(NULL)
-endif
-
-if BACKEND_TYPE_BOX
-dist_helper_DATA = \
- box-refresh-cache.sh \
- $(NULL)
-endif
-
if BACKEND_TYPE_YUM
-install-data-hook:
- chmod a+rx $(DESTDIR)$(helperdir)/yum*.py
+SUBDIRS = yum
endif
if BACKEND_TYPE_CONARY
-install-data-hook:
- chmod a+rx $(DESTDIR)$(helperdir)/conary*.py
+SUBDIRS = conary
endif
if BACKEND_TYPE_BOX
-install-data-hook:
- chmod a+rx $(DESTDIR)$(helperdir)/box*.sh
+SUBDIRS = box
endif
clean-local :
diff --git a/helpers/box-refresh-cache.sh b/helpers/box-refresh-cache.sh
deleted file mode 100644
index c236369..0000000
--- a/helpers/box-refresh-cache.sh
+++ /dev/null
@@ -1,12 +0,0 @@
-#!/bin/sh
-#
-# Copyright (C) 2007 Grzegorz Dabrowski <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.
-
-box --sync-repos
diff --git a/helpers/box/Makefile.am b/helpers/box/Makefile.am
new file mode 100644
index 0000000..64b14fa
--- /dev/null
+++ b/helpers/box/Makefile.am
@@ -0,0 +1,15 @@
+
+helperdir = $(datadir)/PackageKit/helpers
+
+NULL =
+
+dist_helper_DATA = \
+ refresh-cache.sh \
+ $(NULL)
+
+install-data-hook:
+ chmod a+rx $(DESTDIR)$(helperdir)/*.sh
+
+clean-local :
+ rm -f *~
+
diff --git a/helpers/box/refresh-cache.sh b/helpers/box/refresh-cache.sh
new file mode 100644
index 0000000..c236369
--- /dev/null
+++ b/helpers/box/refresh-cache.sh
@@ -0,0 +1,12 @@
+#!/bin/sh
+#
+# Copyright (C) 2007 Grzegorz Dabrowski <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.
+
+box --sync-repos
diff --git a/helpers/conary-get-deps.py b/helpers/conary-get-deps.py
deleted file mode 100755
index 339fca9..0000000
--- a/helpers/conary-get-deps.py
+++ /dev/null
@@ -1,14 +0,0 @@
-#!/usr/bin/python
-#
-# 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.
-
-import sys
-
-sys.exit(0)
diff --git a/helpers/conary-get-description.py b/helpers/conary-get-description.py
deleted file mode 100755
index 339fca9..0000000
--- a/helpers/conary-get-description.py
+++ /dev/null
@@ -1,14 +0,0 @@
-#!/usr/bin/python
-#
-# 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.
-
-import sys
-
-sys.exit(0)
diff --git a/helpers/conary-get-updates.py b/helpers/conary-get-updates.py
deleted file mode 100755
index 9c1e0d1..0000000
--- a/helpers/conary-get-updates.py
+++ /dev/null
@@ -1,17 +0,0 @@
-#!/usr/bin/python
-#
-# 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.
-
-import sys
-from conaryBackend import PackageKitConaryBackend
-
-backend = PackageKitConaryBackend(sys.argv[1:])
-backend.get_updates()
-sys.exit(0)
diff --git a/helpers/conary-install.py b/helpers/conary-install.py
deleted file mode 100755
index 5e5ead7..0000000
--- a/helpers/conary-install.py
+++ /dev/null
@@ -1,18 +0,0 @@
-#!/usr/bin/python
-#
-# 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.
-
-import sys
-from conaryBackend import PackageKitConaryBackend
-
-package = sys.argv[1]
-backend = PackageKitConaryBackend(sys.argv[1:])
-backend.install(package)
-sys.exit(0)
diff --git a/helpers/conary-refresh-cache.py b/helpers/conary-refresh-cache.py
deleted file mode 100755
index 277c942..0000000
--- a/helpers/conary-refresh-cache.py
+++ /dev/null
@@ -1,17 +0,0 @@
-#!/usr/bin/python
-#
-# 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.
-
-import sys
-from conaryBackend import PackageKitConaryBackend
-
-backend = PackageKitConaryBackend(sys.argv[1:])
-backend.refresh_cache()
-sys.exit(0)
diff --git a/helpers/conary-remove.py b/helpers/conary-remove.py
deleted file mode 100755
index 339fca9..0000000
--- a/helpers/conary-remove.py
+++ /dev/null
@@ -1,14 +0,0 @@
-#!/usr/bin/python
-#
-# 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.
-
-import sys
-
-sys.exit(0)
diff --git a/helpers/conary-search-details.py b/helpers/conary-search-details.py
deleted file mode 100755
index f11fb0e..0000000
--- a/helpers/conary-search-details.py
+++ /dev/null
@@ -1,81 +0,0 @@
-#!/usr/bin/python
-#
-# 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.
-
-import sys
-from conary import conarycfg, conaryclient, queryrep, versions
-from conary.conaryclient import cmdline
-
-
-cfg = conarycfg.ConaryConfiguration()
-client = conaryclient.ConaryClient(cfg)
-cfg.readFiles()
-cfg.initializeFlavors()
-repos = client.getRepos()
-db = conaryclient.ConaryClient(cfg).db
-affinityDb = client.db
-
-options = sys.argv[1]
-searchterms = sys.argv[2]
-
-sys.stderr.write('no-percentage-updates\n')
-
-try:
- localInstall = db.findTrove(None, (searchterms, None, None))
- installed = 1
-except:
- installed = 0
-
-troveSpecs = [ cmdline.parseTroveSpec(searchterms, allowEmptyName=False)]
-
-try:
- # Look for packages with affinity
- troveTupleList = queryrep.getTrovesToDisplay(repos, troveSpecs,
- None, None, queryrep.VERSION_FILTER_LATEST,
- queryrep.FLAVOR_FILTER_BEST, cfg.installLabelPath,
- cfg.flavor, affinityDb)
- # Look for packages regardless of affinity
- troveTupleList.extend(queryrep.getTrovesToDisplay(repos, troveSpecs,
- None, None, queryrep.VERSION_FILTER_LATEST,
- queryrep.FLAVOR_FILTER_BEST, cfg.installLabelPath,
- cfg.flavor, None))
- # Remove dupes
- tempDict = {}
- for element in troveTupleList:
- tempDict[element] = None
- troveTupleList = tempDict.keys()
-
- # Get the latest first
- troveTupleList.sort()
- troveTupleList.reverse()
-
- for troveTuple in troveTupleList:
- name = troveTuple[0]
- version = troveTuple[1].trailingRevision().asString()
- # Hard code this until i get the flavor parsing right
- arch = "x86"
- fullVersion = troveTuple[1].asString()
- flavor = str(troveTuple[2])
- data = fullVersion + " " + flavor
- # We don't have summary data yet... so leave it blank for now
- summary = " "
- package_id = name + ";" + version + ";" + arch + ";" + data
- do_print = 0;
- if options == 'installed' and installed == 1:
- do_print = 1
- elif options == 'available' and installed == 0:
- do_print = 1
- elif options == 'all':
- do_print = 1
- # print in correct format
- if do_print == 1:
- print "package\t%s\t%s\t%s" % (installed, package_id, summary)
-except:
- sys.stderr.write('error\tinternal-error\tAn internal error has occurred')
diff --git a/helpers/conary-search-name-live.py b/helpers/conary-search-name-live.py
deleted file mode 100755
index 2abc674..0000000
--- a/helpers/conary-search-name-live.py
+++ /dev/null
@@ -1,21 +0,0 @@
-#!/usr/bin/python
-#
-# 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.
-
-import sys
-
-options = sys.argv[1]
-searchlist = sys.argv[2]
-
-from conaryBackend import PackageKitConaryBackend
-
-backend = PackageKitConaryBackend(sys.argv[1:])
-backend.search_name_live(options,searchlist)
-sys.exit(0)
diff --git a/helpers/conary-search-name.py b/helpers/conary-search-name.py
deleted file mode 100755
index 327e42f..0000000
--- a/helpers/conary-search-name.py
+++ /dev/null
@@ -1,21 +0,0 @@
-#!/usr/bin/python
-#
-# 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.
-
-import sys
-
-options = sys.argv[1]
-searchlist = sys.argv[2]
-
-from conaryBackend import PackageKitConaryBackend
-
-backend = PackageKitConaryBackend(sys.argv[1:])
-backend.search_name(options,searchlist)
-sys.exit(0)
diff --git a/helpers/conary-update-system.py b/helpers/conary-update-system.py
deleted file mode 100755
index 339fca9..0000000
--- a/helpers/conary-update-system.py
+++ /dev/null
@@ -1,14 +0,0 @@
-#!/usr/bin/python
-#
-# 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.
-
-import sys
-
-sys.exit(0)
diff --git a/helpers/conary/Makefile.am b/helpers/conary/Makefile.am
new file mode 100644
index 0000000..a2b0308
--- /dev/null
+++ b/helpers/conary/Makefile.am
@@ -0,0 +1,25 @@
+
+helperdir = $(datadir)/PackageKit/helpers
+
+NULL =
+
+dist_helper_DATA = \
+ search-name.py \
+ search-details.py \
+ get-deps.py \
+ get-updates.py \
+ install.py \
+ refresh-cache.py \
+ remove.py \
+ update-system.py \
+ get-description.py \
+ conaryBackend.py \
+ packagekit.py \
+ $(NULL)
+
+install-data-hook:
+ chmod a+rx $(DESTDIR)$(helperdir)/*.py
+
+clean-local :
+ rm -f *~
+
diff --git a/helpers/conary/conaryBackend.py b/helpers/conary/conaryBackend.py
new file mode 100644
index 0000000..f6ee825
--- /dev/null
+++ b/helpers/conary/conaryBackend.py
@@ -0,0 +1,440 @@
+#
+# 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.
+
+import sys
+import os
+
+from conary.deps import deps
+from conary.conaryclient import cmdline
+from conary import conarycfg, conaryclient, queryrep, versions, updatecmd
+from pysqlite2 import dbapi2 as sqlite
+
+from packagekit import *
+
+class PackageKitConaryBackend(PackageKitBaseBackend):
+ def __init__(self, args):
+ PackageKitBaseBackend.__init__(self,args)
+ self.cfg = conarycfg.ConaryConfiguration(True)
+ self.cfg.initializeFlavors()
+ self.client = conaryclient.ConaryClient(self.cfg)
+
+ def _get_arch(self, flavor):
+ isdep = deps.InstructionSetDependency
+ arches = [ x.name for x in flavor.iterDepsByClass(isdep) ]
+ if not arches:
+ arches = [ 'noarch' ]
+ return ','.join(arches)
+
+ def _get_version(self, version):
+ return version.asString()
+
+ def get_package_id(self, name, version, flavor, fullVersion=None):
+ version = self._get_version(version)
+ arch = self._get_arch(flavor)
+ return PackageKitBaseBackend.get_package_id(self, name, version,
+ arch, fullVersion)
+
+ def _do_search(self,searchlist,filters):
+ fltlist = filters.split(';')
+ troveSpecs = [ cmdline.parseTroveSpec(searchlist, allowEmptyName=False)]
+ # get a hold of cached data
+ cache = Cache()
+
+ try:
+ troveTupleList = cache.search(searchlist)
+ finally:
+ pass
+
+ # Remove dupes
+ tempDict = {}
+ for element in troveTupleList:
+ tempDict[element] = None
+ troveTupleList = tempDict.keys()
+
+ # Get the latest first
+ troveTupleList.sort()
+ troveTupleList.reverse()
+
+ for troveTuple in troveTupleList:
+ troveTuple = tuple([item.encode('UTF-8') for item in troveTuple])
+ name = troveTuple[0]
+ version = versions.ThawVersion(troveTuple[1]).trailingRevision()
+ fullVersion = troveTuple[1]
+ #fullVersion = versions.ThawVersion(troveTuple[1])
+ flavor = deps.ThawFlavor(troveTuple[2])
+ # We don't have summary data yet... so leave it blank for now
+ summary = " "
+ troveTuple = tuple([name, fullVersion, flavor])
+ installed = self.check_installed(troveTuple)
+
+ if self._do_filtering(name,fltlist,installed):
+ id = self.get_package_id(name, version, flavor, fullVersion)
+ self.package(id, installed, summary)
+
+ def _do_search_live(self,searchlist,filters):
+ '''
+ Search for conary packages
+ @param searchlist: The conary package fields to search in
+ @param options: package types to search (all,installed,available)
+ '''
+ repos = self.client.getRepos()
+ db = conaryclient.ConaryClient(self.cfg).db
+ affinityDb = self.client.db
+ fltlist = filters.split(';')
+
+ troveSpecs = [ cmdline.parseTroveSpec(searchlist, allowEmptyName=False)]
+
+ try:
+ # Look for packages with affinity
+ troveTupleList = queryrep.getTrovesToDisplay(repos, troveSpecs,
+ None, None, queryrep.VERSION_FILTER_LATEST,
+ queryrep.FLAVOR_FILTER_BEST, self.cfg.installLabelPath,
+ self.cfg.flavor, affinityDb)
+ # Look for packages regardless of affinity
+ troveTupleList.extend(queryrep.getTrovesToDisplay(repos, troveSpecs,
+ None, None, queryrep.VERSION_FILTER_LATEST,
+ queryrep.FLAVOR_FILTER_BEST, self.cfg.installLabelPath,
+ self.cfg.flavor, None))
+ # Remove dupes
+ tempDict = {}
+ for element in troveTupleList:
+ tempDict[element] = None
+ troveTupleList = tempDict.keys()
+
+ # Get the latest first
+ troveTupleList.sort()
+ troveTupleList.reverse()
+
+ for troveTuple in troveTupleList:
+ name = troveTuple[0]
+ version = troveTuple[1].trailingRevision()
+ fullVersion = troveTuple[1].asString()
+ flavor = troveTuple[2]
+ # We don't have summary data yet... so leave it blank for now
+ summary = " "
+ installed = self.check_installed(troveTuple)
+
+ if self._do_filtering(name,fltlist,installed):
+ id = self.get_package_id(name, version, flavor, fullVersion)
+ self.package(id, installed, summary)
+ except:
+ self.error('internal-error', 'An internal error has occurred')
+
+ def check_installed(self, troveTuple):
+ db = conaryclient.ConaryClient(self.cfg).db
+ try:
+ troveTuple = troveTuple[0], versions.ThawVersion(troveTuple[1]), troveTuple[2]
+ localInstall = db.findTrove(None, troveTuple)
+ installed = 1
+ except:
+ installed = 0
+ return installed
+
+ def search_name(self, options, searchlist):
+ '''
+ Implement the {backend}-search-name functionality
+ '''
+ self._do_search(searchlist, options)
+
+ def search_name_live(self, options, searchlist):
+ '''
+ Implement the {backend}-search-name-live functionality
+ '''
+ self._do_search_live(searchlist, options)
+
+ def search_details(self, opt, key):
+ pass
+
+ def get_deps(self, package_id):
+ pass
+
+ def update_system(self):
+ pass
+
+ def refresh_cache(self):
+ cache = Cache()
+ cache.populate_database()
+
+ def install(self, package_id):
+ '''
+ Implement the {backend}-install functionality
+ '''
+ pkg,inst = self._findPackage(package_id)
+
+ if pkg:
+ if inst:
+ self.error(ERROR_PACKAGE_ALREADY_INSTALLED,'Package already installed')
+ try:
+ print "FOOOOO"
+ except:
+ pass
+ else:
+ self.error(ERROR_PACKAGE_ALREADY_INSTALLED,"Package was not found")
+
+ pass
+
+ def remove(self, allowdep, package_id):
+ pass
+
+ def get_description(self, package_id):
+ return ''
+
+ def get_updates(self):
+ updateItems = self.client.fullUpdateItemList()
+ applyList = [ (x[0], (None, None), x[1:], True) for x in updateItems ]
+ updJob = self.client.newUpdateJob()
+ suggMap = self.client.prepareUpdateJob(updJob, applyList,
+ resolveDeps=True,
+ migrate=False)
+ jobLists = updJob.getJobs()
+
+ totalJobs = len(jobLists)
+ for num, job in enumerate(jobLists):
+ status = '2'
+ name = job[0][0]
+ version = job[0][2][0]
+ flavor = job[0][2][1]
+ troveTuple = []
+ troveTuple.append(name)
+ troveTuple.append(version)
+ installed = self.check_installed(troveTuple)
+ id = self.get_package_id(name, version, flavor)
+ summary = ""
+ self.package(id, installed, summary)
+
+ def _do_filtering(self,pkg,filterList,installed):
+ ''' Filter the package, based on the filter in filterList '''
+ # do we print to stdout?
+ do_print = False;
+ if filterList == ['none']: # 'none' = all packages.
+ return True
+ elif 'installed' in filterList and installed == 1:
+ do_print = True
+ elif '~installed' in filterList and installed == 0:
+ do_print = True
+
+ if len(filterList) == 1: # Only one filter, return
+ return do_print
+
+ if do_print:
+ return self._do_extra_filtering(pkg,filterList)
+ else:
+ return do_print
+
+ def _do_extra_filtering(self,pkg,filterList):
+ ''' do extra filtering (devel etc) '''
+
+ for flt in filterList:
+ if flt == 'installed' or flt =='~installed':
+ continue
+ elif flt =='devel' or flt=='~devel':
+ if not self._do_devel_filtering(flt,pkg):
+ return False
+ return True
+
+ def _do_devel_filtering(self,flt,pkg):
+ isDevel = False
+ if flt == 'devel':
+ wantDevel = True
+ else:
+ wantDevel = False
+ #
+ # TODO: Add Devel detection Code here.Set isDevel = True, if it is a devel app
+ #
+ regex = re.compile(r'(:devel)')
+ if regex.search(pkg.name):
+ isDevel = True
+ #
+ #
+ return isDevel == wantDevel
+
+ def _findPackage(self,id):
+ '''
+ find a package based on a package id (name;version;arch;repoid)
+ '''
+ # Split up the id
+ (name,version,arch,fullVersion) = self.get_package_from_id(id)
+ cache = Cache()
+ troveTuple = cache.search(name,fullVersion)
+ troveTuple = [item.encode('UTF-8') for item in troveTuple[0]]
+
+ installed = self.check_installed(troveTuple)
+ return name,installed
+
+class Cache(object):
+ # Database name and path
+ dbName = 'cache.db'
+ # Someday we might want to make this writable by users
+ #if 'HOME' in os.environ:
+ # dbPath = '%s/.conary/cache/data/' % os.environ['HOME']
+ #else:
+ # dbPath = '/var/cache/conary/'
+ dbPath = '/var/cache/conary/'
+
+ """ Class to retrieve and cache package information from label. """
+ def __init__(self):
+ if not os.path.isdir(self.dbPath):
+ os.makedirs(self.dbPath)
+
+ self.conn = sqlite.connect(os.path.join(self.dbPath, self.dbName), isolation_level=None)
+ self.cursor = self.conn.cursor()
+ self.cursor.execute("PRAGMA count_changes=0")
+ self.cursor.execute("pragma synchronous=off")
+
+ if os.path.isfile(os.path.join(self.dbPath, self.dbName)):
+ self._validate_tables()
+
+ def _validate_tables(self):
+ """ Validates that all tables are up to date. """
+ stmt = "select tbl_name from sqlite_master where type = 'table' and tbl_name like 'conary_%'"
+ self.cursor.execute(stmt)
+ # List of all tables with names that start with "conary_"
+ tbllist = self.cursor.fetchall()
+ if tbllist != []:
+ return True
+ #print "Verified packages table"
+ else:
+ #print "Creating packages table..."
+ # Create all tables if database is empty
+ if len(tbllist) == 0:
+ self._create_database()
+ return True
+
+ def conaryquery(self):
+ self.cfg = conarycfg.ConaryConfiguration()
+ self.client = conaryclient.ConaryClient(self.cfg)
+ self.cfg.readFiles()
+ self.cfg.initializeFlavors()
+ self.repos = self.client.getRepos()
+ self.db = conaryclient.ConaryClient(self.cfg).db
+
+ troves = queryrep.getTrovesToDisplay(self.repos, None, None, None,
+ queryrep.VERSION_FILTER_LEAVES, queryrep.FLAVOR_FILTER_BEST,
+ self.cfg.installLabelPath, self.cfg.flavor, None)
+
+ packages = []
+
+ for troveTuple in troves:
+ # troveTuple is probably what we want to store in the cachedb
+ # Then use the below methods to present them in a nicer fashion
+ if troveTuple[0].endswith(':source'):
+ continue
+ if ":" in troveTuple[0]:
+ fragments = troveTuple[0].split(":")
+ trove = fragments[0]
+ component = fragments[1]
+ else:
+ trove = troveTuple[0]
+ component = ""
+
+ installed = 0
+ localVersion = ""
+ flavor = troveTuple[2]
+ frozenFlavor = troveTuple[2].freeze()
+ version = str(troveTuple[1].trailingRevision())
+ frozenVersion = troveTuple[1].freeze()
+ label = str(troveTuple[1].branch().label())
+ description = ""
+ category = ""
+ packagegroup = ""
+ size = ""
+ packages.append([trove, component, frozenVersion, label, frozenFlavor, description, category, packagegroup, size])
+
+ return packages
+
+ def connect_memory(self):
+ return sqlite.connect(':memory:')
+
+ def cursor(self, connection):
+ return connection.cursor()
+
+ def _create_database(self):
+ """ Creates a blank database. """
+ sql = '''CREATE TABLE conary_packages (
+ trove text,
+ component text,
+ version text,
+ label text,
+ flavor text,
+ description text,
+ category text,
+ packagegroup text,
+ size text)'''
+
+ self.cursor.execute(sql)
+
+ def commit(self):
+ self.cursor.commit()
+
+ def getTroves(self, label=None):
+ """
+ Returns all troves for now. Add filtering capability.
+ """
+ stmt = "select distinct trove, version, flavor, description, category, packagegroup, size" \
+ " from conary_packages"
+
+ try:
+ self.cursor.execute(stmt)
+ return self.cursor.fetchall()
+ except Exception, e:
+ print str(e)
+ return None
+
+ def search(self, package, fullVersion=None):
+ """
+ Returns all troves for now. Add filtering capability.
+ """
+ stmt = "select distinct trove, version, flavor, description, category, packagegroup, size" \
+ " from conary_packages"
+
+ if package and fullVersion:
+ stmt = "select distinct trove, version, flavor from conary_packages where trove ='" + package + "' and version = '" + fullVersion +"'"
+ elif package:
+ stmt = stmt + " where trove like '%" + package + "%' and component = '' order by version desc"
+
+ try:
+ self.cursor.execute(stmt)
+ results = self.cursor.fetchall()
+ return results
+ except Exception, e:
+ print str(e)
+ return None
+
+ def _insert(self, trove):
+ """
+ Insert trove into database.
+ """
+ values = [str(field) for field in trove]
+ cols = ",".join("?" * len(trove))
+ sql = "INSERT INTO conary_packages VALUES (%s)" % cols
+
+ try:
+ self.cursor.execute(sql, values)
+ except Exception,e:
+ print str(e)
+
+ def _clear_table(self, tableName='conary_packages'):
+ """
+ Deletes * records from table.
+ """
+ stmt = "DELETE FROM %s" % tableName
+ self.cursor.execute(stmt)
+
+ def populate_database(self):
+ try:
+ packages = self.conaryquery()
+ # Clear table first
+ self._clear_table()
+ for package in packages:
+ self._insert(package)
+ except Exception, e:
+ print str(e)
+
+
diff --git a/helpers/conary/get-deps.py b/helpers/conary/get-deps.py
new file mode 100755
index 0000000..339fca9
--- /dev/null
+++ b/helpers/conary/get-deps.py
@@ -0,0 +1,14 @@
+#!/usr/bin/python
+#
+# 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.
+
+import sys
+
+sys.exit(0)
diff --git a/helpers/conary/get-description.py b/helpers/conary/get-description.py
new file mode 100755
index 0000000..339fca9
--- /dev/null
+++ b/helpers/conary/get-description.py
@@ -0,0 +1,14 @@
+#!/usr/bin/python
+#
+# 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.
+
+import sys
+
+sys.exit(0)
diff --git a/helpers/conary/get-updates.py b/helpers/conary/get-updates.py
new file mode 100755
index 0000000..9c1e0d1
--- /dev/null
+++ b/helpers/conary/get-updates.py
@@ -0,0 +1,17 @@
+#!/usr/bin/python
+#
+# 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.
+
+import sys
+from conaryBackend import PackageKitConaryBackend
+
+backend = PackageKitConaryBackend(sys.argv[1:])
+backend.get_updates()
+sys.exit(0)
diff --git a/helpers/conary/install.py b/helpers/conary/install.py
new file mode 100755
index 0000000..5e5ead7
--- /dev/null
+++ b/helpers/conary/install.py
@@ -0,0 +1,18 @@
+#!/usr/bin/python
+#
+# 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.
+
+import sys
+from conaryBackend import PackageKitConaryBackend
+
+package = sys.argv[1]
+backend = PackageKitConaryBackend(sys.argv[1:])
+backend.install(package)
+sys.exit(0)
diff --git a/helpers/conary/packagekit.py b/helpers/conary/packagekit.py
new file mode 120000
index 0000000..e328b22
--- /dev/null
+++ b/helpers/conary/packagekit.py
@@ -0,0 +1 @@
+../yum/packagekit.py
\ No newline at end of file
diff --git a/helpers/conary/refresh-cache.py b/helpers/conary/refresh-cache.py
new file mode 100755
index 0000000..277c942
--- /dev/null
+++ b/helpers/conary/refresh-cache.py
@@ -0,0 +1,17 @@
+#!/usr/bin/python
+#
+# 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.
+
+import sys
+from conaryBackend import PackageKitConaryBackend
+
+backend = PackageKitConaryBackend(sys.argv[1:])
+backend.refresh_cache()
+sys.exit(0)
diff --git a/helpers/conary/remove.py b/helpers/conary/remove.py
new file mode 100755
index 0000000..339fca9
--- /dev/null
+++ b/helpers/conary/remove.py
@@ -0,0 +1,14 @@
+#!/usr/bin/python
+#
+# 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.
+
+import sys
+
+sys.exit(0)
diff --git a/helpers/conary/search-details.py b/helpers/conary/search-details.py
new file mode 100755
index 0000000..f11fb0e
--- /dev/null
+++ b/helpers/conary/search-details.py
@@ -0,0 +1,81 @@
+#!/usr/bin/python
+#
+# 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.
+
+import sys
+from conary import conarycfg, conaryclient, queryrep, versions
+from conary.conaryclient import cmdline
+
+
+cfg = conarycfg.ConaryConfiguration()
+client = conaryclient.ConaryClient(cfg)
+cfg.readFiles()
+cfg.initializeFlavors()
+repos = client.getRepos()
+db = conaryclient.ConaryClient(cfg).db
+affinityDb = client.db
+
+options = sys.argv[1]
+searchterms = sys.argv[2]
+
+sys.stderr.write('no-percentage-updates\n')
+
+try:
+ localInstall = db.findTrove(None, (searchterms, None, None))
+ installed = 1
+except:
+ installed = 0
+
+troveSpecs = [ cmdline.parseTroveSpec(searchterms, allowEmptyName=False)]
+
+try:
+ # Look for packages with affinity
+ troveTupleList = queryrep.getTrovesToDisplay(repos, troveSpecs,
+ None, None, queryrep.VERSION_FILTER_LATEST,
+ queryrep.FLAVOR_FILTER_BEST, cfg.installLabelPath,
+ cfg.flavor, affinityDb)
+ # Look for packages regardless of affinity
+ troveTupleList.extend(queryrep.getTrovesToDisplay(repos, troveSpecs,
+ None, None, queryrep.VERSION_FILTER_LATEST,
+ queryrep.FLAVOR_FILTER_BEST, cfg.installLabelPath,
+ cfg.flavor, None))
+ # Remove dupes
+ tempDict = {}
+ for element in troveTupleList:
+ tempDict[element] = None
+ troveTupleList = tempDict.keys()
+
+ # Get the latest first
+ troveTupleList.sort()
+ troveTupleList.reverse()
+
+ for troveTuple in troveTupleList:
+ name = troveTuple[0]
+ version = troveTuple[1].trailingRevision().asString()
+ # Hard code this until i get the flavor parsing right
+ arch = "x86"
+ fullVersion = troveTuple[1].asString()
+ flavor = str(troveTuple[2])
+ data = fullVersion + " " + flavor
+ # We don't have summary data yet... so leave it blank for now
+ summary = " "
+ package_id = name + ";" + version + ";" + arch + ";" + data
+ do_print = 0;
+ if options == 'installed' and installed == 1:
+ do_print = 1
+ elif options == 'available' and installed == 0:
+ do_print = 1
+ elif options == 'all':
+ do_print = 1
+ # print in correct format
+ if do_print == 1:
+ print "package\t%s\t%s\t%s" % (installed, package_id, summary)
+except:
+ sys.stderr.write('error\tinternal-error\tAn internal error has occurred')
diff --git a/helpers/conary/search-name-live.py b/helpers/conary/search-name-live.py
new file mode 100755
index 0000000..2abc674
--- /dev/null
+++ b/helpers/conary/search-name-live.py
@@ -0,0 +1,21 @@
+#!/usr/bin/python
+#
+# 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.
+
+import sys
+
+options = sys.argv[1]
+searchlist = sys.argv[2]
+
+from conaryBackend import PackageKitConaryBackend
+
+backend = PackageKitConaryBackend(sys.argv[1:])
+backend.search_name_live(options,searchlist)
+sys.exit(0)
diff --git a/helpers/conary/search-name.py b/helpers/conary/search-name.py
new file mode 100755
index 0000000..327e42f
--- /dev/null
+++ b/helpers/conary/search-name.py
@@ -0,0 +1,21 @@
+#!/usr/bin/python
+#
+# 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.
+
+import sys
+
+options = sys.argv[1]
+searchlist = sys.argv[2]
+
+from conaryBackend import PackageKitConaryBackend
+
+backend = PackageKitConaryBackend(sys.argv[1:])
+backend.search_name(options,searchlist)
+sys.exit(0)
diff --git a/helpers/conary/update-system.py b/helpers/conary/update-system.py
new file mode 100755
index 0000000..339fca9
--- /dev/null
+++ b/helpers/conary/update-system.py
@@ -0,0 +1,14 @@
+#!/usr/bin/python
+#
+# 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.
+
+import sys
+
+sys.exit(0)
diff --git a/helpers/conaryBackend.py b/helpers/conaryBackend.py
deleted file mode 100644
index f6ee825..0000000
--- a/helpers/conaryBackend.py
+++ /dev/null
@@ -1,440 +0,0 @@
-#
-# 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.
-
-import sys
-import os
-
-from conary.deps import deps
-from conary.conaryclient import cmdline
-from conary import conarycfg, conaryclient, queryrep, versions, updatecmd
-from pysqlite2 import dbapi2 as sqlite
-
-from packagekit import *
-
-class PackageKitConaryBackend(PackageKitBaseBackend):
- def __init__(self, args):
- PackageKitBaseBackend.__init__(self,args)
- self.cfg = conarycfg.ConaryConfiguration(True)
- self.cfg.initializeFlavors()
- self.client = conaryclient.ConaryClient(self.cfg)
-
- def _get_arch(self, flavor):
- isdep = deps.InstructionSetDependency
- arches = [ x.name for x in flavor.iterDepsByClass(isdep) ]
- if not arches:
- arches = [ 'noarch' ]
- return ','.join(arches)
-
- def _get_version(self, version):
- return version.asString()
-
- def get_package_id(self, name, version, flavor, fullVersion=None):
- version = self._get_version(version)
- arch = self._get_arch(flavor)
- return PackageKitBaseBackend.get_package_id(self, name, version,
- arch, fullVersion)
-
- def _do_search(self,searchlist,filters):
- fltlist = filters.split(';')
- troveSpecs = [ cmdline.parseTroveSpec(searchlist, allowEmptyName=False)]
- # get a hold of cached data
- cache = Cache()
-
- try:
- troveTupleList = cache.search(searchlist)
- finally:
- pass
-
- # Remove dupes
- tempDict = {}
- for element in troveTupleList:
- tempDict[element] = None
- troveTupleList = tempDict.keys()
-
- # Get the latest first
- troveTupleList.sort()
- troveTupleList.reverse()
-
- for troveTuple in troveTupleList:
- troveTuple = tuple([item.encode('UTF-8') for item in troveTuple])
- name = troveTuple[0]
- version = versions.ThawVersion(troveTuple[1]).trailingRevision()
- fullVersion = troveTuple[1]
- #fullVersion = versions.ThawVersion(troveTuple[1])
- flavor = deps.ThawFlavor(troveTuple[2])
- # We don't have summary data yet... so leave it blank for now
- summary = " "
- troveTuple = tuple([name, fullVersion, flavor])
- installed = self.check_installed(troveTuple)
-
- if self._do_filtering(name,fltlist,installed):
- id = self.get_package_id(name, version, flavor, fullVersion)
- self.package(id, installed, summary)
-
- def _do_search_live(self,searchlist,filters):
- '''
- Search for conary packages
- @param searchlist: The conary package fields to search in
- @param options: package types to search (all,installed,available)
- '''
- repos = self.client.getRepos()
- db = conaryclient.ConaryClient(self.cfg).db
- affinityDb = self.client.db
- fltlist = filters.split(';')
-
- troveSpecs = [ cmdline.parseTroveSpec(searchlist, allowEmptyName=False)]
-
- try:
- # Look for packages with affinity
- troveTupleList = queryrep.getTrovesToDisplay(repos, troveSpecs,
- None, None, queryrep.VERSION_FILTER_LATEST,
- queryrep.FLAVOR_FILTER_BEST, self.cfg.installLabelPath,
- self.cfg.flavor, affinityDb)
- # Look for packages regardless of affinity
- troveTupleList.extend(queryrep.getTrovesToDisplay(repos, troveSpecs,
- None, None, queryrep.VERSION_FILTER_LATEST,
- queryrep.FLAVOR_FILTER_BEST, self.cfg.installLabelPath,
- self.cfg.flavor, None))
- # Remove dupes
- tempDict = {}
- for element in troveTupleList:
- tempDict[element] = None
- troveTupleList = tempDict.keys()
-
- # Get the latest first
- troveTupleList.sort()
- troveTupleList.reverse()
-
- for troveTuple in troveTupleList:
- name = troveTuple[0]
- version = troveTuple[1].trailingRevision()
- fullVersion = troveTuple[1].asString()
- flavor = troveTuple[2]
- # We don't have summary data yet... so leave it blank for now
- summary = " "
- installed = self.check_installed(troveTuple)
-
- if self._do_filtering(name,fltlist,installed):
- id = self.get_package_id(name, version, flavor, fullVersion)
- self.package(id, installed, summary)
- except:
- self.error('internal-error', 'An internal error has occurred')
-
- def check_installed(self, troveTuple):
- db = conaryclient.ConaryClient(self.cfg).db
- try:
- troveTuple = troveTuple[0], versions.ThawVersion(troveTuple[1]), troveTuple[2]
- localInstall = db.findTrove(None, troveTuple)
- installed = 1
- except:
- installed = 0
- return installed
-
- def search_name(self, options, searchlist):
- '''
- Implement the {backend}-search-name functionality
- '''
- self._do_search(searchlist, options)
-
- def search_name_live(self, options, searchlist):
- '''
- Implement the {backend}-search-name-live functionality
- '''
- self._do_search_live(searchlist, options)
-
- def search_details(self, opt, key):
- pass
-
- def get_deps(self, package_id):
- pass
-
- def update_system(self):
- pass
-
- def refresh_cache(self):
- cache = Cache()
- cache.populate_database()
-
- def install(self, package_id):
- '''
- Implement the {backend}-install functionality
- '''
- pkg,inst = self._findPackage(package_id)
-
- if pkg:
- if inst:
- self.error(ERROR_PACKAGE_ALREADY_INSTALLED,'Package already installed')
- try:
- print "FOOOOO"
- except:
- pass
- else:
- self.error(ERROR_PACKAGE_ALREADY_INSTALLED,"Package was not found")
-
- pass
-
- def remove(self, allowdep, package_id):
- pass
-
- def get_description(self, package_id):
- return ''
-
- def get_updates(self):
- updateItems = self.client.fullUpdateItemList()
- applyList = [ (x[0], (None, None), x[1:], True) for x in updateItems ]
- updJob = self.client.newUpdateJob()
- suggMap = self.client.prepareUpdateJob(updJob, applyList,
- resolveDeps=True,
- migrate=False)
- jobLists = updJob.getJobs()
-
- totalJobs = len(jobLists)
- for num, job in enumerate(jobLists):
- status = '2'
- name = job[0][0]
- version = job[0][2][0]
- flavor = job[0][2][1]
- troveTuple = []
- troveTuple.append(name)
- troveTuple.append(version)
- installed = self.check_installed(troveTuple)
- id = self.get_package_id(name, version, flavor)
- summary = ""
- self.package(id, installed, summary)
-
- def _do_filtering(self,pkg,filterList,installed):
- ''' Filter the package, based on the filter in filterList '''
- # do we print to stdout?
- do_print = False;
- if filterList == ['none']: # 'none' = all packages.
- return True
- elif 'installed' in filterList and installed == 1:
- do_print = True
- elif '~installed' in filterList and installed == 0:
- do_print = True
-
- if len(filterList) == 1: # Only one filter, return
- return do_print
-
- if do_print:
- return self._do_extra_filtering(pkg,filterList)
- else:
- return do_print
-
- def _do_extra_filtering(self,pkg,filterList):
- ''' do extra filtering (devel etc) '''
-
- for flt in filterList:
- if flt == 'installed' or flt =='~installed':
- continue
- elif flt =='devel' or flt=='~devel':
- if not self._do_devel_filtering(flt,pkg):
- return False
- return True
-
- def _do_devel_filtering(self,flt,pkg):
- isDevel = False
- if flt == 'devel':
- wantDevel = True
- else:
- wantDevel = False
- #
- # TODO: Add Devel detection Code here.Set isDevel = True, if it is a devel app
- #
- regex = re.compile(r'(:devel)')
- if regex.search(pkg.name):
- isDevel = True
- #
- #
- return isDevel == wantDevel
-
- def _findPackage(self,id):
- '''
- find a package based on a package id (name;version;arch;repoid)
- '''
- # Split up the id
- (name,version,arch,fullVersion) = self.get_package_from_id(id)
- cache = Cache()
- troveTuple = cache.search(name,fullVersion)
- troveTuple = [item.encode('UTF-8') for item in troveTuple[0]]
-
- installed = self.check_installed(troveTuple)
- return name,installed
-
-class Cache(object):
- # Database name and path
- dbName = 'cache.db'
- # Someday we might want to make this writable by users
- #if 'HOME' in os.environ:
- # dbPath = '%s/.conary/cache/data/' % os.environ['HOME']
- #else:
- # dbPath = '/var/cache/conary/'
- dbPath = '/var/cache/conary/'
-
- """ Class to retrieve and cache package information from label. """
- def __init__(self):
- if not os.path.isdir(self.dbPath):
- os.makedirs(self.dbPath)
-
- self.conn = sqlite.connect(os.path.join(self.dbPath, self.dbName), isolation_level=None)
- self.cursor = self.conn.cursor()
- self.cursor.execute("PRAGMA count_changes=0")
- self.cursor.execute("pragma synchronous=off")
-
- if os.path.isfile(os.path.join(self.dbPath, self.dbName)):
- self._validate_tables()
-
- def _validate_tables(self):
- """ Validates that all tables are up to date. """
- stmt = "select tbl_name from sqlite_master where type = 'table' and tbl_name like 'conary_%'"
- self.cursor.execute(stmt)
- # List of all tables with names that start with "conary_"
- tbllist = self.cursor.fetchall()
- if tbllist != []:
- return True
- #print "Verified packages table"
- else:
- #print "Creating packages table..."
- # Create all tables if database is empty
- if len(tbllist) == 0:
- self._create_database()
- return True
-
- def conaryquery(self):
- self.cfg = conarycfg.ConaryConfiguration()
- self.client = conaryclient.ConaryClient(self.cfg)
- self.cfg.readFiles()
- self.cfg.initializeFlavors()
- self.repos = self.client.getRepos()
- self.db = conaryclient.ConaryClient(self.cfg).db
-
- troves = queryrep.getTrovesToDisplay(self.repos, None, None, None,
- queryrep.VERSION_FILTER_LEAVES, queryrep.FLAVOR_FILTER_BEST,
- self.cfg.installLabelPath, self.cfg.flavor, None)
-
- packages = []
-
- for troveTuple in troves:
- # troveTuple is probably what we want to store in the cachedb
- # Then use the below methods to present them in a nicer fashion
- if troveTuple[0].endswith(':source'):
- continue
- if ":" in troveTuple[0]:
- fragments = troveTuple[0].split(":")
- trove = fragments[0]
- component = fragments[1]
- else:
- trove = troveTuple[0]
- component = ""
-
- installed = 0
- localVersion = ""
- flavor = troveTuple[2]
- frozenFlavor = troveTuple[2].freeze()
- version = str(troveTuple[1].trailingRevision())
- frozenVersion = troveTuple[1].freeze()
- label = str(troveTuple[1].branch().label())
- description = ""
- category = ""
- packagegroup = ""
- size = ""
- packages.append([trove, component, frozenVersion, label, frozenFlavor, description, category, packagegroup, size])
-
- return packages
-
- def connect_memory(self):
- return sqlite.connect(':memory:')
-
- def cursor(self, connection):
- return connection.cursor()
-
- def _create_database(self):
- """ Creates a blank database. """
- sql = '''CREATE TABLE conary_packages (
- trove text,
- component text,
- version text,
- label text,
- flavor text,
- description text,
- category text,
- packagegroup text,
- size text)'''
-
- self.cursor.execute(sql)
-
- def commit(self):
- self.cursor.commit()
-
- def getTroves(self, label=None):
- """
- Returns all troves for now. Add filtering capability.
- """
- stmt = "select distinct trove, version, flavor, description, category, packagegroup, size" \
- " from conary_packages"
-
- try:
- self.cursor.execute(stmt)
- return self.cursor.fetchall()
- except Exception, e:
- print str(e)
- return None
-
- def search(self, package, fullVersion=None):
- """
- Returns all troves for now. Add filtering capability.
- """
- stmt = "select distinct trove, version, flavor, description, category, packagegroup, size" \
- " from conary_packages"
-
- if package and fullVersion:
- stmt = "select distinct trove, version, flavor from conary_packages where trove ='" + package + "' and version = '" + fullVersion +"'"
- elif package:
- stmt = stmt + " where trove like '%" + package + "%' and component = '' order by version desc"
-
- try:
- self.cursor.execute(stmt)
- results = self.cursor.fetchall()
- return results
- except Exception, e:
- print str(e)
- return None
-
- def _insert(self, trove):
- """
- Insert trove into database.
- """
- values = [str(field) for field in trove]
- cols = ",".join("?" * len(trove))
- sql = "INSERT INTO conary_packages VALUES (%s)" % cols
-
- try:
- self.cursor.execute(sql, values)
- except Exception,e:
- print str(e)
-
- def _clear_table(self, tableName='conary_packages'):
- """
- Deletes * records from table.
- """
- stmt = "DELETE FROM %s" % tableName
- self.cursor.execute(stmt)
-
- def populate_database(self):
- try:
- packages = self.conaryquery()
- # Clear table first
- self._clear_table()
- for package in packages:
- self._insert(package)
- except Exception, e:
- print str(e)
-
-
diff --git a/helpers/packagekit.py b/helpers/packagekit.py
deleted file mode 100644
index 7824dab..0000000
--- a/helpers/packagekit.py
+++ /dev/null
@@ -1,229 +0,0 @@
-#!/usr/bin/python -tt
-# 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 Library General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License
-# along with this program; if not, write to the Free Software
-# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
-#
-# Copyright (C) 2007 Tim Lauridsen <timlau at fedoraproject.org>
-
-#
-# This file contain the base classes to implement a PackageKit python backend
-#
-
-# imports
-import sys
-
-# Constants
-
-ERROR_NO_NETWORK = "no-network"
-ERROR_NOT_SUPPORTED = "not-supported"
-ERROR_INTERNAL_ERROR = "internal-error"
-ERROR_GPG_FAILURE = "gpg-failure"
-ERROR_PACKAGE_NOT_INSTALLED = "package-not-installed"
-ERROR_PACKAGE_ALREADY_INSTALLED = "package-already-installed"
-ERROR_PACKAGE_DOWNLOAD_FAILED = "package-download-failed"
-ERROR_DEP_RESOLUTION_FAILED = "dep-resolution-failed"
-
-STATE_DOWNLOAD = "download"
-STATE_INSTALL = "install"
-STATE_UPDATE = "update"
-STATE_REMOVE = "remove"
-
-RESTART_SYSTEM = "system"
-RESTART_APPLICATION = "application"
-RESTART_SESSION = "session"
-
-# Classes
-
-class PackageKitBaseBackend:
-
- def __init__(self,cmds):
- self.cmds = cmds
-
- def percentage(self,percent=None):
- '''
- Write progress percentage
- @param percent: Progress percentage
- '''
- if percent != None:
- print >> sys.stderr, "percentage\t%i" % (percent)
- else:
- print >> sys.stderr, "no-percentage-updates"
-
- def sub_percentage(self,percent=None):
- '''
- send 'subpercentage' signal : subprogress percentage
- @param percent: subprogress percentage
- '''
- print >> sys.stderr, "subpercentage\t%i" % (percent)
-
- def error(self,err,description,exit=True):
- '''
- send 'error'
- @param err: Error Type (ERROR_NO_NETWORK, ERROR_NOT_SUPPORTED, ERROR_INTERNAL_ERROR)
- @param description: Error description
- @param exit: exit application with rc=1, if true
- '''
- print >> sys.stderr,"error\t%s\t%s" % (err,description)
- if exit:
- sys.exit(1)
-
- def package(self,id,status,summary):
- '''
- send 'package' signal
- @param status: 1 = Installed, 0 = not
- @param id: The package ID name, e.g. openoffice-clipart;2.6.22;ppc64;fedora
- @param summary: The package Summary
- '''
- print >> sys.stdout,"package\t%s\t%s\t%s" % (status,id,summary)
-
- def status(self,state):
- '''
- send 'status' signal
- @param state: STATE_DOWNLOAD, STATE_INSTALL, STATE_UPDATE, STATE_REMOVE
- '''
- print >> sys.stderr,"status\t%s" % (state)
-
- def data(self,data):
- '''
- send 'data' signal:
- @param data: The current worked on package
- '''
- print >> sys.stderr,"data\t%s" % (data)
-
- def description(self,id,group,desc,url):
- '''
- Send 'description' signal
- @param id: The package ID name, e.g. openoffice-clipart;2.6.22;ppc64;fedora
- @param group: The enumerated group
- @param desc: The multi line package description
- @param url: The upstream project homepage
- '''
- print >> sys.stdout,"description\t%s\t%s\t%s\t%s" % (id,group,desc,url)
-
- def require_restart(self,restart_type,details):
- '''
- Send 'requirerestart' signal
- @param restart_type: RESTART_SYSTEM, RESTART_APPLICATION,RESTART_SESSION
- @param details: Optional details about the restart
- '''
- print >> sys.stderr,"requirerestart\t%s\t%s" % (restart_type,details)
-
- def allow_interrupt(self,allow):
- '''
- send 'allow-interrupt' signal:
- @param allow: Allow the current process to be aborted.
- '''
- if allow:
- data = 'true'
- else:
- data = 'false'
- print >> sys.stderr,"allow-interrupt\t%s" % (data)
-
- def get_package_id(self,name,version,arch,data):
- return "%s;%s;%s;%s" % (name,version,arch,data)
-
- def get_package_from_id(self,id):
- ''' split up a package id name;ver;arch;data into a tuple
- containing (name,ver,arch,data)
- '''
- return tuple(id.split(';'))
-#
-# Backend Action Methods
-#
-
- def search_name(self,filters,key):
- '''
- Implement the {backend}-search-name functionality
- Needed to be implemented in a sub class
- '''
- self.error(ERROR_NOT_SUPPORTED,"This function is not implemented in this backend")
-
- def search_details(self,filters,key):
- '''
- Implement the {backend}-search-details functionality
- Needed to be implemented in a sub class
- '''
- self.error(ERROR_NOT_SUPPORTED,"This function is not implemented in this backend")
-
- def search_group(self,filters,key):
- '''
- Implement the {backend}-search-group functionality
- Needed to be implemented in a sub class
- '''
- self.error(ERROR_NOT_SUPPORTED,"This function is not implemented in this backend")
-
- def search_file(self,filters,key):
- '''
- Implement the {backend}-search-file functionality
- Needed to be implemented in a sub class
- '''
- self.error(ERROR_NOT_SUPPORTED,"This function is not implemented in this backend")
-
-
- def get_deps(self,package):
- '''
- Implement the {backend}-get-deps functionality
- Needed to be implemented in a sub class
- '''
- self.error(ERROR_NOT_SUPPORTED,"This function is not implemented in this backend")
-
- def update_system(self):
- '''
- Implement the {backend}-update-system functionality
- Needed to be implemented in a sub class
- '''
- self.error(ERROR_NOT_SUPPORTED,"This function is not implemented in this backend")
-
-
- def refresh_cache(self):
- '''
- Implement the {backend}-refresh_cache functionality
- Needed to be implemented in a sub class
- '''
- self.error(ERROR_NOT_SUPPORTED,"This function is not implemented in this backend")
-
- def install(self, package):
- '''
- Implement the {backend}-install functionality
- Needed to be implemented in a sub class
- '''
- self.error(ERROR_NOT_SUPPORTED,"This function is not implemented in this backend")
-
- def remove(self, allowdep, package):
- '''
- Implement the {backend}-remove functionality
- Needed to be implemented in a sub class
- '''
- self.error(ERROR_NOT_SUPPORTED,"This function is not implemented in this backend")
-
- def update(self, package):
- '''
- Implement the {backend}-update functionality
- Needed to be implemented in a sub class
- '''
- self.error(ERROR_NOT_SUPPORTED,"This function is not implemented in this backend")
-
- def get_description(self, package):
- '''
- Implement the {backend}-get-description functionality
- Needed to be implemented in a sub class
- '''
- self.error(ERROR_NOT_SUPPORTED,"This function is not implemented in this backend")
-
- def get_updates(self, package):
- '''
- Implement the {backend}-get-updates functionality
- Needed to be implemented in a sub class
- '''
- self.error(ERROR_NOT_SUPPORTED,"This function is not implemented in this backend")
-
diff --git a/helpers/yum-get-deps.py b/helpers/yum-get-deps.py
deleted file mode 100755
index caef349..0000000
--- a/helpers/yum-get-deps.py
+++ /dev/null
@@ -1,18 +0,0 @@
-#!/usr/bin/python
-#
-# 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.
-
-import sys
-
-from yumBackend import PackageKitYumBackend
-package=sys.argv[1]
-backend = PackageKitYumBackend(sys.argv[1:])
-backend.get_deps(package)
-sys.exit(0)
diff --git a/helpers/yum-get-description.py b/helpers/yum-get-description.py
deleted file mode 100755
index 459caa4..0000000
--- a/helpers/yum-get-description.py
+++ /dev/null
@@ -1,19 +0,0 @@
-#!/usr/bin/python
-#
-# Copyright (C) 2007 Richard Hughes <richard at hughsie.com>
-# Copyright (C) 2007 Luke Macken <lmacken at redhat.com>
-#
-# Licensed under the GNU General Public License Version 2
-#
-# This program is free software; you can redistribute it and/or modify
-# it under the terms of the GNU General Public License as published by
-# the Free Software Foundation; either version 2 of the License, or
-# (at your option) any later version.
-
-import sys
-
-from yumBackend import PackageKitYumBackend
-package = sys.argv[1]
-backend = PackageKitYumBackend(sys.argv[1:])
-backend.get_description(package)
-sys.exit(0)
diff --git a/helpers/yum-get-updates.py b/helpers/yum-get-updates.py
deleted file mode 100755
index 2330f7a..0000000
--- a/helpers/yum-get-updates.py
+++ /dev/null
@@ -1,18 +0,0 @@
-#!/usr/bin/python
-#
-# 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.
-
-import sys
-
-from yumBackend import PackageKitYumBackend
-
-backend = PackageKitYumBackend(sys.argv[1:])
-backend.get_updates()
-sys.exit(0)
\ No newline at end of file
diff --git a/helpers/yum-install.py b/helpers/yum-install.py
deleted file mode 100755
index 69cb2ab..0000000
--- a/helpers/yum-install.py
+++ /dev/null
@@ -1,20 +0,0 @@
-#!/usr/bin/python
-#
-# Copyright (C) 2007 Richard Hughes <richard at hughsie.com>
-# Copyright (C) 2007 Red Hat Inc, Seth Vidal <skvidal at fedoraproject.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.
-
-import sys
-
-from yumBackend import PackageKitYumBackend
-
-package = sys.argv[1]
-backend = PackageKitYumBackend(sys.argv[1:])
-backend.install(package)
-sys.exit(0)
\ No newline at end of file
diff --git a/helpers/yum-refresh-cache.py b/helpers/yum-refresh-cache.py
deleted file mode 100755
index 4c1aca1..0000000
--- a/helpers/yum-refresh-cache.py
+++ /dev/null
@@ -1,19 +0,0 @@
-#!/usr/bin/python
-#
-# Copyright (C) 2007 Richard Hughes <richard at hughsie.com>
-# Copyright (C) 2007 Red Hat Inc, Seth Vidal <skvidal at fedoraproject.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.
-
-import sys
-
-from yumBackend import PackageKitYumBackend
-
-backend = PackageKitYumBackend(sys.argv[1:])
-backend.refresh_cache()
-sys.exit(0)
diff --git a/helpers/yum-remove.py b/helpers/yum-remove.py
deleted file mode 100755
index 7536d05..0000000
--- a/helpers/yum-remove.py
+++ /dev/null
@@ -1,22 +0,0 @@
-#!/usr/bin/python
-#
-# 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.
-
-
-import sys
-
-from yumBackend import PackageKitYumBackend
-
-allowdeps = sys.argv[1]
-package = sys.argv[2]
-
-backend = PackageKitYumBackend(sys.argv[1:])
-backend.remove(allowdeps, package)
-sys.exit(0)
diff --git a/helpers/yum-search-details.py b/helpers/yum-search-details.py
deleted file mode 100755
index e5e5ec1..0000000
--- a/helpers/yum-search-details.py
+++ /dev/null
@@ -1,23 +0,0 @@
-#!/usr/bin/python
-#
-# Copyright (C) 2007 Richard Hughes <richard at hughsie.com>
-# Copyright (C) 2007 Red Hat Inc, Seth Vidal <skvidal at fedoraproject.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.
-
-import sys
-
-options = sys.argv[1]
-searchterms = sys.argv[2]
-
-from yumBackend import PackageKitYumBackend
-
-backend = PackageKitYumBackend(sys.argv[1:])
-backend.search_details(options,searchterms)
-sys.exit(0)
-
diff --git a/helpers/yum-search-file.py b/helpers/yum-search-file.py
deleted file mode 100755
index 2066526..0000000
--- a/helpers/yum-search-file.py
+++ /dev/null
@@ -1,23 +0,0 @@
-#!/usr/bin/python
-#
-# Copyright (C) 2007 Richard Hughes <richard at hughsie.com>
-# Copyright (C) 2007 Red Hat Inc, Seth Vidal <skvidal at fedoraproject.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.
-
-import sys
-
-options = sys.argv[1]
-searchterms = sys.argv[2]
-
-from yumBackend import PackageKitYumBackend
-
-backend = PackageKitYumBackend(sys.argv[1:])
-backend.search_group(options,searchterms)
-sys.exit(0)
-
diff --git a/helpers/yum-search-group.py b/helpers/yum-search-group.py
deleted file mode 100755
index 2066526..0000000
--- a/helpers/yum-search-group.py
+++ /dev/null
@@ -1,23 +0,0 @@
-#!/usr/bin/python
-#
-# Copyright (C) 2007 Richard Hughes <richard at hughsie.com>
-# Copyright (C) 2007 Red Hat Inc, Seth Vidal <skvidal at fedoraproject.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.
-
-import sys
-
-options = sys.argv[1]
-searchterms = sys.argv[2]
-
-from yumBackend import PackageKitYumBackend
-
-backend = PackageKitYumBackend(sys.argv[1:])
-backend.search_group(options,searchterms)
-sys.exit(0)
-
diff --git a/helpers/yum-search-name.py b/helpers/yum-search-name.py
deleted file mode 100755
index c1cc342..0000000
--- a/helpers/yum-search-name.py
+++ /dev/null
@@ -1,23 +0,0 @@
-#!/usr/bin/python
-#
-# Copyright (C) 2007 Richard Hughes <richard at hughsie.com>
-# Copyright (C) 2007 Red Hat Inc, Seth Vidal <skvidal at fedoraproject.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.
-
-import sys
-
-options = sys.argv[1]
-searchterms = sys.argv[2]
-
-from yumBackend import PackageKitYumBackend
-
-backend = PackageKitYumBackend(sys.argv[1:])
-backend.search_name(options,searchterms)
-sys.exit(0)
-
diff --git a/helpers/yum-update-system.py b/helpers/yum-update-system.py
deleted file mode 100755
index 243a5f6..0000000
--- a/helpers/yum-update-system.py
+++ /dev/null
@@ -1,20 +0,0 @@
-#!/usr/bin/python
-#
-# Copyright (C) 2007 Richard Hughes <richard at hughsie.com>
-# Copyright (C) 2007 Tim Lauridsen <timlau at fedoraproject.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.
-
-import sys
-
-from yumBackend import PackageKitYumBackend
-
-backend = PackageKitYumBackend(sys.argv[1:])
-backend.update_system()
-sys.exit(0)
-
diff --git a/helpers/yum-update.py b/helpers/yum-update.py
deleted file mode 100755
index 3bc9d42..0000000
--- a/helpers/yum-update.py
+++ /dev/null
@@ -1,20 +0,0 @@
-#!/usr/bin/python
-#
-# Copyright (C) 2007 Richard Hughes <richard at hughsie.com>
-# Copyright (C) 2007 Red Hat Inc, Seth Vidal <skvidal at fedoraproject.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.
-
-import sys
-
-from yumBackend import PackageKitYumBackend
-
-package = sys.argv[1]
-backend = PackageKitYumBackend(sys.argv[1:])
-backend.update(package)
-sys.exit(0)
\ No newline at end of file
diff --git a/helpers/yum/Makefile.am b/helpers/yum/Makefile.am
new file mode 100644
index 0000000..fe6a94b
--- /dev/null
+++ b/helpers/yum/Makefile.am
@@ -0,0 +1,28 @@
+
+helperdir = $(datadir)/PackageKit/helpers
+
+NULL =
+
+dist_helper_DATA = \
+ search-name.py \
+ search-details.py \
+ search-group.py \
+ search-file.py \
+ get-deps.py \
+ get-updates.py \
+ get-description.py \
+ install.py \
+ remove.py \
+ update.py \
+ refresh-cache.py \
+ update-system.py \
+ yumBackend.py \
+ packagekit.py \
+ $(NULL)
+
+install-data-hook:
+ chmod a+rx $(DESTDIR)$(helperdir)/*.py
+
+clean-local :
+ rm -f *~
+
diff --git a/helpers/yum/get-deps.py b/helpers/yum/get-deps.py
new file mode 100755
index 0000000..caef349
--- /dev/null
+++ b/helpers/yum/get-deps.py
@@ -0,0 +1,18 @@
+#!/usr/bin/python
+#
+# 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.
+
+import sys
+
+from yumBackend import PackageKitYumBackend
+package=sys.argv[1]
+backend = PackageKitYumBackend(sys.argv[1:])
+backend.get_deps(package)
+sys.exit(0)
diff --git a/helpers/yum/get-description.py b/helpers/yum/get-description.py
new file mode 100755
index 0000000..459caa4
--- /dev/null
+++ b/helpers/yum/get-description.py
@@ -0,0 +1,19 @@
+#!/usr/bin/python
+#
+# Copyright (C) 2007 Richard Hughes <richard at hughsie.com>
+# Copyright (C) 2007 Luke Macken <lmacken at redhat.com>
+#
+# Licensed under the GNU General Public License Version 2
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+
+import sys
+
+from yumBackend import PackageKitYumBackend
+package = sys.argv[1]
+backend = PackageKitYumBackend(sys.argv[1:])
+backend.get_description(package)
+sys.exit(0)
diff --git a/helpers/yum/get-updates.py b/helpers/yum/get-updates.py
new file mode 100755
index 0000000..2330f7a
--- /dev/null
+++ b/helpers/yum/get-updates.py
@@ -0,0 +1,18 @@
+#!/usr/bin/python
+#
+# 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.
+
+import sys
+
+from yumBackend import PackageKitYumBackend
+
+backend = PackageKitYumBackend(sys.argv[1:])
+backend.get_updates()
+sys.exit(0)
\ No newline at end of file
diff --git a/helpers/yum/install.py b/helpers/yum/install.py
new file mode 100755
index 0000000..69cb2ab
--- /dev/null
+++ b/helpers/yum/install.py
@@ -0,0 +1,20 @@
+#!/usr/bin/python
+#
+# Copyright (C) 2007 Richard Hughes <richard at hughsie.com>
+# Copyright (C) 2007 Red Hat Inc, Seth Vidal <skvidal at fedoraproject.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.
+
+import sys
+
+from yumBackend import PackageKitYumBackend
+
+package = sys.argv[1]
+backend = PackageKitYumBackend(sys.argv[1:])
+backend.install(package)
+sys.exit(0)
\ No newline at end of file
diff --git a/helpers/yum/packagekit.py b/helpers/yum/packagekit.py
new file mode 100644
index 0000000..7824dab
--- /dev/null
+++ b/helpers/yum/packagekit.py
@@ -0,0 +1,229 @@
+#!/usr/bin/python -tt
+# 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 Library General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+#
+# Copyright (C) 2007 Tim Lauridsen <timlau at fedoraproject.org>
+
+#
+# This file contain the base classes to implement a PackageKit python backend
+#
+
+# imports
+import sys
+
+# Constants
+
+ERROR_NO_NETWORK = "no-network"
+ERROR_NOT_SUPPORTED = "not-supported"
+ERROR_INTERNAL_ERROR = "internal-error"
+ERROR_GPG_FAILURE = "gpg-failure"
+ERROR_PACKAGE_NOT_INSTALLED = "package-not-installed"
+ERROR_PACKAGE_ALREADY_INSTALLED = "package-already-installed"
+ERROR_PACKAGE_DOWNLOAD_FAILED = "package-download-failed"
+ERROR_DEP_RESOLUTION_FAILED = "dep-resolution-failed"
+
+STATE_DOWNLOAD = "download"
+STATE_INSTALL = "install"
+STATE_UPDATE = "update"
+STATE_REMOVE = "remove"
+
+RESTART_SYSTEM = "system"
+RESTART_APPLICATION = "application"
+RESTART_SESSION = "session"
+
+# Classes
+
+class PackageKitBaseBackend:
+
+ def __init__(self,cmds):
+ self.cmds = cmds
+
+ def percentage(self,percent=None):
+ '''
+ Write progress percentage
+ @param percent: Progress percentage
+ '''
+ if percent != None:
+ print >> sys.stderr, "percentage\t%i" % (percent)
+ else:
+ print >> sys.stderr, "no-percentage-updates"
+
+ def sub_percentage(self,percent=None):
+ '''
+ send 'subpercentage' signal : subprogress percentage
+ @param percent: subprogress percentage
+ '''
+ print >> sys.stderr, "subpercentage\t%i" % (percent)
+
+ def error(self,err,description,exit=True):
+ '''
+ send 'error'
+ @param err: Error Type (ERROR_NO_NETWORK, ERROR_NOT_SUPPORTED, ERROR_INTERNAL_ERROR)
+ @param description: Error description
+ @param exit: exit application with rc=1, if true
+ '''
+ print >> sys.stderr,"error\t%s\t%s" % (err,description)
+ if exit:
+ sys.exit(1)
+
+ def package(self,id,status,summary):
+ '''
+ send 'package' signal
+ @param status: 1 = Installed, 0 = not
+ @param id: The package ID name, e.g. openoffice-clipart;2.6.22;ppc64;fedora
+ @param summary: The package Summary
+ '''
+ print >> sys.stdout,"package\t%s\t%s\t%s" % (status,id,summary)
+
+ def status(self,state):
+ '''
+ send 'status' signal
+ @param state: STATE_DOWNLOAD, STATE_INSTALL, STATE_UPDATE, STATE_REMOVE
+ '''
+ print >> sys.stderr,"status\t%s" % (state)
+
+ def data(self,data):
+ '''
+ send 'data' signal:
+ @param data: The current worked on package
+ '''
+ print >> sys.stderr,"data\t%s" % (data)
+
+ def description(self,id,group,desc,url):
+ '''
+ Send 'description' signal
+ @param id: The package ID name, e.g. openoffice-clipart;2.6.22;ppc64;fedora
+ @param group: The enumerated group
+ @param desc: The multi line package description
+ @param url: The upstream project homepage
+ '''
+ print >> sys.stdout,"description\t%s\t%s\t%s\t%s" % (id,group,desc,url)
+
+ def require_restart(self,restart_type,details):
+ '''
+ Send 'requirerestart' signal
+ @param restart_type: RESTART_SYSTEM, RESTART_APPLICATION,RESTART_SESSION
+ @param details: Optional details about the restart
+ '''
+ print >> sys.stderr,"requirerestart\t%s\t%s" % (restart_type,details)
+
+ def allow_interrupt(self,allow):
+ '''
+ send 'allow-interrupt' signal:
+ @param allow: Allow the current process to be aborted.
+ '''
+ if allow:
+ data = 'true'
+ else:
+ data = 'false'
+ print >> sys.stderr,"allow-interrupt\t%s" % (data)
+
+ def get_package_id(self,name,version,arch,data):
+ return "%s;%s;%s;%s" % (name,version,arch,data)
+
+ def get_package_from_id(self,id):
+ ''' split up a package id name;ver;arch;data into a tuple
+ containing (name,ver,arch,data)
+ '''
+ return tuple(id.split(';'))
+#
+# Backend Action Methods
+#
+
+ def search_name(self,filters,key):
+ '''
+ Implement the {backend}-search-name functionality
+ Needed to be implemented in a sub class
+ '''
+ self.error(ERROR_NOT_SUPPORTED,"This function is not implemented in this backend")
+
+ def search_details(self,filters,key):
+ '''
+ Implement the {backend}-search-details functionality
+ Needed to be implemented in a sub class
+ '''
+ self.error(ERROR_NOT_SUPPORTED,"This function is not implemented in this backend")
+
+ def search_group(self,filters,key):
+ '''
+ Implement the {backend}-search-group functionality
+ Needed to be implemented in a sub class
+ '''
+ self.error(ERROR_NOT_SUPPORTED,"This function is not implemented in this backend")
+
+ def search_file(self,filters,key):
+ '''
+ Implement the {backend}-search-file functionality
+ Needed to be implemented in a sub class
+ '''
+ self.error(ERROR_NOT_SUPPORTED,"This function is not implemented in this backend")
+
+
+ def get_deps(self,package):
+ '''
+ Implement the {backend}-get-deps functionality
+ Needed to be implemented in a sub class
+ '''
+ self.error(ERROR_NOT_SUPPORTED,"This function is not implemented in this backend")
+
+ def update_system(self):
+ '''
+ Implement the {backend}-update-system functionality
+ Needed to be implemented in a sub class
+ '''
+ self.error(ERROR_NOT_SUPPORTED,"This function is not implemented in this backend")
+
+
+ def refresh_cache(self):
+ '''
+ Implement the {backend}-refresh_cache functionality
+ Needed to be implemented in a sub class
+ '''
+ self.error(ERROR_NOT_SUPPORTED,"This function is not implemented in this backend")
+
+ def install(self, package):
+ '''
+ Implement the {backend}-install functionality
+ Needed to be implemented in a sub class
+ '''
+ self.error(ERROR_NOT_SUPPORTED,"This function is not implemented in this backend")
+
+ def remove(self, allowdep, package):
+ '''
+ Implement the {backend}-remove functionality
+ Needed to be implemented in a sub class
+ '''
+ self.error(ERROR_NOT_SUPPORTED,"This function is not implemented in this backend")
+
+ def update(self, package):
+ '''
+ Implement the {backend}-update functionality
+ Needed to be implemented in a sub class
+ '''
+ self.error(ERROR_NOT_SUPPORTED,"This function is not implemented in this backend")
+
+ def get_description(self, package):
+ '''
+ Implement the {backend}-get-description functionality
+ Needed to be implemented in a sub class
+ '''
+ self.error(ERROR_NOT_SUPPORTED,"This function is not implemented in this backend")
+
+ def get_updates(self, package):
+ '''
+ Implement the {backend}-get-updates functionality
+ Needed to be implemented in a sub class
+ '''
+ self.error(ERROR_NOT_SUPPORTED,"This function is not implemented in this backend")
+
diff --git a/helpers/yum/refresh-cache.py b/helpers/yum/refresh-cache.py
new file mode 100755
index 0000000..4c1aca1
--- /dev/null
+++ b/helpers/yum/refresh-cache.py
@@ -0,0 +1,19 @@
+#!/usr/bin/python
+#
+# Copyright (C) 2007 Richard Hughes <richard at hughsie.com>
+# Copyright (C) 2007 Red Hat Inc, Seth Vidal <skvidal at fedoraproject.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.
+
+import sys
+
+from yumBackend import PackageKitYumBackend
+
+backend = PackageKitYumBackend(sys.argv[1:])
+backend.refresh_cache()
+sys.exit(0)
diff --git a/helpers/yum/remove.py b/helpers/yum/remove.py
new file mode 100755
index 0000000..7536d05
--- /dev/null
+++ b/helpers/yum/remove.py
@@ -0,0 +1,22 @@
+#!/usr/bin/python
+#
+# 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.
+
+
+import sys
+
+from yumBackend import PackageKitYumBackend
+
+allowdeps = sys.argv[1]
+package = sys.argv[2]
+
+backend = PackageKitYumBackend(sys.argv[1:])
+backend.remove(allowdeps, package)
+sys.exit(0)
diff --git a/helpers/yum/search-details.py b/helpers/yum/search-details.py
new file mode 100755
index 0000000..e5e5ec1
--- /dev/null
+++ b/helpers/yum/search-details.py
@@ -0,0 +1,23 @@
+#!/usr/bin/python
+#
+# Copyright (C) 2007 Richard Hughes <richard at hughsie.com>
+# Copyright (C) 2007 Red Hat Inc, Seth Vidal <skvidal at fedoraproject.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.
+
+import sys
+
+options = sys.argv[1]
+searchterms = sys.argv[2]
+
+from yumBackend import PackageKitYumBackend
+
+backend = PackageKitYumBackend(sys.argv[1:])
+backend.search_details(options,searchterms)
+sys.exit(0)
+
diff --git a/helpers/yum/search-file.py b/helpers/yum/search-file.py
new file mode 100755
index 0000000..2066526
--- /dev/null
+++ b/helpers/yum/search-file.py
@@ -0,0 +1,23 @@
+#!/usr/bin/python
+#
+# Copyright (C) 2007 Richard Hughes <richard at hughsie.com>
+# Copyright (C) 2007 Red Hat Inc, Seth Vidal <skvidal at fedoraproject.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.
+
+import sys
+
+options = sys.argv[1]
+searchterms = sys.argv[2]
+
+from yumBackend import PackageKitYumBackend
+
+backend = PackageKitYumBackend(sys.argv[1:])
+backend.search_group(options,searchterms)
+sys.exit(0)
+
diff --git a/helpers/yum/search-group.py b/helpers/yum/search-group.py
new file mode 100755
index 0000000..2066526
--- /dev/null
+++ b/helpers/yum/search-group.py
@@ -0,0 +1,23 @@
+#!/usr/bin/python
+#
+# Copyright (C) 2007 Richard Hughes <richard at hughsie.com>
+# Copyright (C) 2007 Red Hat Inc, Seth Vidal <skvidal at fedoraproject.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.
+
+import sys
+
+options = sys.argv[1]
+searchterms = sys.argv[2]
+
+from yumBackend import PackageKitYumBackend
+
+backend = PackageKitYumBackend(sys.argv[1:])
+backend.search_group(options,searchterms)
+sys.exit(0)
+
diff --git a/helpers/yum/search-name.py b/helpers/yum/search-name.py
new file mode 100755
index 0000000..c1cc342
--- /dev/null
+++ b/helpers/yum/search-name.py
@@ -0,0 +1,23 @@
+#!/usr/bin/python
+#
+# Copyright (C) 2007 Richard Hughes <richard at hughsie.com>
+# Copyright (C) 2007 Red Hat Inc, Seth Vidal <skvidal at fedoraproject.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.
+
+import sys
+
+options = sys.argv[1]
+searchterms = sys.argv[2]
+
+from yumBackend import PackageKitYumBackend
+
+backend = PackageKitYumBackend(sys.argv[1:])
+backend.search_name(options,searchterms)
+sys.exit(0)
+
diff --git a/helpers/yum/update-system.py b/helpers/yum/update-system.py
new file mode 100755
index 0000000..243a5f6
--- /dev/null
+++ b/helpers/yum/update-system.py
@@ -0,0 +1,20 @@
+#!/usr/bin/python
+#
+# Copyright (C) 2007 Richard Hughes <richard at hughsie.com>
+# Copyright (C) 2007 Tim Lauridsen <timlau at fedoraproject.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.
+
+import sys
+
+from yumBackend import PackageKitYumBackend
+
+backend = PackageKitYumBackend(sys.argv[1:])
+backend.update_system()
+sys.exit(0)
+
diff --git a/helpers/yum/update.py b/helpers/yum/update.py
new file mode 100755
index 0000000..3bc9d42
--- /dev/null
+++ b/helpers/yum/update.py
@@ -0,0 +1,20 @@
+#!/usr/bin/python
+#
+# Copyright (C) 2007 Richard Hughes <richard at hughsie.com>
+# Copyright (C) 2007 Red Hat Inc, Seth Vidal <skvidal at fedoraproject.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.
+
+import sys
+
+from yumBackend import PackageKitYumBackend
+
+package = sys.argv[1]
+backend = PackageKitYumBackend(sys.argv[1:])
+backend.update(package)
+sys.exit(0)
\ No newline at end of file
diff --git a/helpers/yum/yumBackend.py b/helpers/yum/yumBackend.py
new file mode 100644
index 0000000..9140ae5
--- /dev/null
+++ b/helpers/yum/yumBackend.py
@@ -0,0 +1,566 @@
+#!/usr/bin/python -tt
+# 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 filtersion) 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 Library General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+#
+# Copyright (C) 2007 Tim Lauridsen <timlau at fedoraproject.org>
+# Copyright (C) 2007 Red Hat Inc, Seth Vidal <skvidal at fedoraproject.org>
+# Copyright (C) 2007 Luke Macken <lmacken at redhat.com>
+
+
+# imports
+
+import sys
+import re
+
+from packagekit import *
+import yum
+from urlgrabber.progress import BaseMeter,format_time,format_number
+from yum.rpmtrans import RPMBaseCallback
+from yum.constants import *
+from yum.update_md import UpdateMetadata
+from yum.callbacks import *
+
+
+class PackageKitYumBackend(PackageKitBaseBackend):
+
+ def __init__(self,args):
+ PackageKitBaseBackend.__init__(self,args)
+ self.yumbase = yum.YumBase()
+
+ def _get_package_ver(self,po):
+ ''' return the a ver as epoch:version-release or version-release, if epoch=0'''
+ if po.epoch != '0':
+ ver = "%s:%s-%s" % (po.epoch,po.version,po.release)
+ else:
+ ver = "%s-%s" % (po.version,po.release)
+ return ver
+
+ def _do_search(self,searchlist,filters,key):
+ '''
+ Search for yum packages
+ @param searchlist: The yum package fields to search in
+ @param filters: package types to search (all,installed,available)
+ @param key: key to seach for
+ '''
+ self.yumbase.doConfigSetup(errorlevel=0,debuglevel=0)# Setup Yum Config
+ self.yumbase.conf.cache = 1 # Only look in cache.
+ res = self.yumbase.searchGenerator(searchlist, [key])
+ fltlist = filters.split(';')
+
+ count = 1
+ for (pkg,values) in res:
+ if count > 100:
+ break
+ count+=1
+ # are we installed?
+ if self.yumbase.rpmdb.installed(pkg.name):
+ installed = '1'
+ else:
+ installed = '0'
+
+ if self._do_filtering(pkg,fltlist,installed):
+ self._show_package(pkg, installed)
+
+ def _do_filtering(self,pkg,filterList,installed):
+ ''' Filter the package, based on the filter in filterList '''
+
+ # do we print to stdout?
+ do_print = False;
+ if filterList == ['none']: # 'none' = all packages.
+ return True
+ elif 'installed' in filterList and installed == '1':
+ do_print = True
+ elif '~installed' in filterList and installed == '0':
+ do_print = True
+
+ if len(filterList) == 1: # Only one filter, return
+ return do_print
+
+ if do_print:
+ return self._do_extra_filtering(pkg,filterList)
+ else:
+ return do_print
+
+ def _do_extra_filtering(self,pkg,filterList):
+ ''' do extra filtering (gui,devel etc) '''
+
+ for flt in filterList:
+ if flt == 'installed' or flt =='~installed':
+ continue
+ elif flt == 'gui' or flt =='~gui':
+ if not self._do_gui_filtering(flt,pkg):
+ return False
+ elif flt =='devel' or flt=='~devel':
+ if not self._do_devel_filtering(flt,pkg):
+ return False
+ return True
+
+ def _do_gui_filtering(self,flt,pkg):
+ isGUI = False
+ if flt == 'gui':
+ wantGUI = True
+ else:
+ wantGUI = False
+ #
+ # TODO: Add GUI detection Code here.Set isGUI = True, if it is a GUI app
+ #
+ isGUI = wantGUI # Fake it for now
+ #
+ #
+ return isGUI == wantGUI
+
+ def _do_devel_filtering(self,flt,pkg):
+ isDevel = False
+ if flt == 'devel':
+ wantDevel = True
+ else:
+ wantDevel = False
+ #
+ # TODO: Add Devel detection Code here.Set isDevel = True, if it is a devel app
+ #
+ regex = re.compile(r'(-devel)|(-dgb)|(-static)')
+ if regex.search(pkg.name):
+ isDevel = True
+ #
+ #
+ return isDevel == wantDevel
+
+ def search_name(self,filters,key):
+ '''
+ Implement the {backend}-search-name functionality
+ '''
+ searchlist = ['name']
+ self._do_search(searchlist, filters, key)
+
+ def search_details(self,filters,key):
+ '''
+ Implement the {backend}-search-details functionality
+ '''
+ searchlist = ['name', 'summary', 'description', 'group']
+ self._do_search(searchlist, filters, key)
+
+ def search_group(self,filters,key):
+ '''
+ Implement the {backend}-search-group functionality
+ '''
+ self.error(ERROR_NOT_SUPPORTED,"This function is not implemented in this backend")
+
+ def search_file(self,filters,key):
+ '''
+ Implement the {backend}-search-file functionality
+ '''
+ self.error(ERROR_NOT_SUPPORTED,"This function is not implemented in this backend")
+
+ def _getEVR(self,idver):
+ '''
+ get the e,v,r from the package id version
+ '''
+ cpos = idver.find(':')
+ if cpos != -1:
+ epoch = idver[:cpos]
+ idver = idver[cpos:]
+ else:
+ epoch = '0'
+ (version,release) = tuple(idver.split('-'))
+ return epoch,version,release
+
+ def _findPackage(self,id):
+ '''
+ find a package based on a packahe id (name;version;arch;repoid)
+ '''
+ # Split up the id
+ (n,idver,a,d) = self.get_package_from_id(id)
+ # get e,v,r from package id version
+ e,v,r = self._getEVR(idver)
+ # search the rpmdb for the nevra
+ pkgs = self.yumbase.rpmdb.searchNevra(name=n,epoch=e,ver=v,rel=r,arch=a)
+ # if the package is found, then return it
+ if len(pkgs) != 0:
+ return pkgs[0],True
+ # search the pkgSack for the nevra
+ pkgs = self.yumbase.pkgSack.searchNevra(name=n,epoch=e,ver=v,rel=r,arch=a)
+ # if the package is found, then return it
+ if len(pkgs) != 0:
+ return pkgs[0],False
+ else:
+ return None,False
+
+
+ def get_deps(self,package):
+ '''
+ Print a list of dependencies for a given package
+ '''
+ self._setup_yum()
+ name = package.split(';')[0]
+ pkg,inst = self._findPackage(package)
+ results = {}
+ if pkg:
+ deps = self.yumbase.findDeps([pkg]).values()[0]
+ for deplist in deps.values():
+ for dep in deplist:
+ if not results.has_key(dep.name):
+ results[dep.name] = dep
+ else:
+ self.error(ERROR_INTERNAL_ERROR,'Package was not found')
+
+ for pkg in results.values():
+ if pkg.name != name:
+ pkgver = self._get_package_ver(pkg)
+ id = self.get_package_id(pkg.name, pkgver, pkg.arch, pkg.repo)
+ self.package(id, 1, pkg.summary)
+
+ def update_system(self):
+ '''
+ Implement the {backend}-update-system functionality
+ Needed to be implemented in a sub class
+ '''
+ self._setup_yum()
+ self.percentage(0)
+ txmbr = self.yumbase.update() # Add all updates to Transaction
+ if txmbr:
+ self._runYumTransaction()
+ else:
+ self.error(ERROR_INTERNAL_ERROR,"Nothing to do")
+
+ def refresh_cache(self):
+ '''
+ Implement the {backend}-refresh_cache functionality
+ Needed to be implemented in a sub class
+ '''
+ self._setup_yum()
+ pct = 0
+ self.percentage(pct)
+ try:
+ if len(self.yumbase.repos.listEnabled()) == 0:
+ self.percentage(100)
+ return
+
+ #work out the slice for each one
+ bump = (100/len(self.yumbase.repos.listEnabled()))/2
+
+ for repo in self.yumbase.repos.listEnabled():
+ repo.metadata_expire = 0
+ self.yumbase.repos.populateSack(which=[repo.id], mdtype='metadata', cacheonly=1)
+ pct+=bump
+ self.percentage(pct)
+ self.yumbase.repos.populateSack(which=[repo.id], mdtype='filelists', cacheonly=1)
+ pct+=bump
+ self.percentage(pct)
+
+ #we might have a rounding error
+ self.percentage(100)
+
+ except yum.Errors.YumBaseError, e:
+ self.error(ERROR_INTERNAL_ERROR,str(e))
+
+ def install(self, package):
+ '''
+ Implement the {backend}-install functionality
+ This will only work with yum 3.2.4 or higher
+ '''
+ self._setup_yum()
+ self.percentage(0)
+ pkg,inst = self._findPackage(package)
+ if pkg:
+ if inst:
+ self.error(ERROR_PACKAGE_ALREADY_INSTALLED,'Package already installed')
+ try:
+ txmbr = self.yumbase.install(name=pkg.name)
+ self._runYumTransaction()
+ except yum.Errors.InstallError,e:
+ print e
+ msgs = ';'.join(e)
+ self.error(ERROR_PACKAGE_ALREADY_INSTALLED,msgs)
+ else:
+ self.error(ERROR_PACKAGE_ALREADY_INSTALLED,"Package was not found")
+
+ def update(self, package):
+ '''
+ Implement the {backend}-install functionality
+ This will only work with yum 3.2.4 or higher
+ '''
+ self._setup_yum()
+ self.percentage(0)
+ pkg,inst = self._findPackage(package)
+ if pkg:
+ txmbr = self.yumbase.update(name=pkg.name)
+ if txmbr:
+ self._runYumTransaction()
+ else:
+ self.error(ERROR_PACKAGE_ALREADY_INSTALLED,"No available updates")
+ else:
+ self.error(ERROR_PACKAGE_ALREADY_INSTALLED,"No available updates")
+
+
+ def _runYumTransaction(self):
+ '''
+ Run the yum Transaction
+ This will only work with yum 3.2.4 or higher
+ '''
+ rc,msgs = self.yumbase.buildTransaction()
+ if rc !=2:
+ retmsg = "Error in Dependency Resolution;" +";".join(msgs)
+ self.error(ERROR_DEP_RESOLUTION_FAILED,retmsg)
+ else:
+ try:
+ rpmDisplay = PackageKitCallback(self)
+ callback = ProcessTransPackageKitCallback(self)
+ self.yumbase.processTransaction(callback=callback,
+ rpmDisplay=rpmDisplay)
+ except yum.Errors.YumDownloadError, msgs:
+ retmsg = "Error in Download;" +";".join(msgs)
+ self.error(ERROR_PACKAGE_DOWNLOAD_FAILED,retmsg)
+ except yum.Errors.YumGPGCheckError, msgs:
+ retmsg = "Error in Package Signatures;" +";".join(msgs)
+ self.error(ERROR_INTERNAL_ERROR,retmsg)
+ except yum.Errors.YumBaseError, msgs:
+ retmsg = "Error in Transaction Processing;" +";".join(msgs)
+ self.error(ERROR_INTERNAL_ERROR,retmsg)
+
+ def remove(self, allowdep, package):
+ '''
+ Implement the {backend}-remove functionality
+ Needed to be implemented in a sub class
+ '''
+ self._setup_yum()
+ self.percentage(0)
+ pkg,inst = self._findPackage( package)
+ if pkg and inst:
+ txmbr = self.yumbase.remove(name=pkg.name)
+ if txmbr:
+ self._runYumTransaction()
+ else:
+ self.error(ERROR_PACKAGE_NOT_INSTALLED,"Package is not installed")
+ else:
+ self.error(ERROR_PACKAGE_NOT_INSTALLED,"Package is not installed")
+
+
+ def get_description(self, package):
+ '''
+ Print a detailed description for a given package
+ '''
+ self._setup_yum()
+ pkg,inst = self._findPackage(package)
+ if pkg:
+ id = self.get_package_id(pkg.name, pkg.version,pkg.arch, pkg.repo)
+ desc = pkg.description
+ desc = desc.replace('\n\n',';')
+ desc = desc.replace('\n',' ')
+ self.description(id, "%s-%s" % (pkg.version, pkg.release),
+ desc, pkg.url)
+ else:
+ self.error(ERROR_INTERNAL_ERROR,'Package was not found')
+
+ def _show_package(self,pkg,status):
+ ''' Show info about package'''
+ pkgver = self._get_package_ver(pkg)
+ id = self.get_package_id(pkg.name, pkgver, pkg.arch, pkg.repo)
+ self.package(id,status, pkg.summary)
+
+ def _get_status(self,notice):
+ ut = notice['type']
+ # TODO : Add more types to check
+ if ut == 'security':
+ return 1
+ else:
+ return 0
+
+
+ def get_updates(self):
+ '''
+ Implement the {backend}-get-updates functionality
+ '''
+ self._setup_yum()
+ md = UpdateMetadata()
+ # Added extra Update Metadata
+ for repo in self.yumbase.repos.listEnabled():
+ try:
+ md.add(repo)
+ except:
+ pass # No updateinfo.xml.gz in repo
+
+ self.percentage(0)
+ ygl = self.yumbase.doPackageLists(pkgnarrow='updates')
+ for pkg in ygl.updates:
+ # Get info about package in updates info
+ notice = md.get_notice((pkg.name, pkg.version, pkg.release))
+ if notice:
+ status = self._get_status(notice)
+ self._show_package(pkg,status)
+ else:
+ self._show_package(pkg,0)
+
+
+ def _setup_yum(self):
+ self.yumbase.doConfigSetup(errorlevel=0,debuglevel=0) # Setup Yum Config
+ self.dnlCallback = DownloadCallback(self,showNames=True) # Download callback
+ self.yumbase.repos.setProgressBar( self.dnlCallback ) # Setup the download callback class
+
+class DownloadCallback( BaseMeter ):
+ """ Customized version of urlgrabber.progress.BaseMeter class """
+ def __init__(self,base,showNames = False):
+ BaseMeter.__init__( self )
+ self.totSize = ""
+ self.base = base
+ self.showNames = showNames
+ self.oldName = None
+ self.lastPct = 0
+ self.totalPct = 0
+ self.pkgs = None
+ self.numPkgs=0
+ self.bump = 0.0
+
+ def setPackages(self,pkgs,startPct,numPct):
+ self.pkgs = pkgs
+ self.numPkgs = len(self.pkgs)
+ self.bump = numPct/self.numPkgs
+ self.totalPct = startPct
+
+ def _getPackage(self,name):
+ name = name.split('-')[0]
+ if self.pkgs:
+ for pkg in self.pkgs:
+ if pkg.name == name:
+ return pkg
+ return None
+
+ def update( self, amount_read, now=None ):
+ BaseMeter.update( self, amount_read, now )
+
+ def _do_start( self, now=None ):
+ name = self._getName()
+ self.updateProgress(name,0.0,"","")
+ if not self.size is None:
+ self.totSize = format_number( self.size )
+
+ def _do_update( self, amount_read, now=None ):
+ fread = format_number( amount_read )
+ name = self._getName()
+ if self.size is None:
+ # Elapsed time
+ etime = self.re.elapsed_time()
+ fetime = format_time( etime )
+ frac = 0.0
+ self.updateProgress(name,frac,fread,fetime)
+ else:
+ # Remaining time
+ rtime = self.re.remaining_time()
+ frtime = format_time( rtime )
+ frac = self.re.fraction_read()
+ self.updateProgress(name,frac,fread,frtime)
+
+
+ def _do_end( self, amount_read, now=None ):
+ total_time = format_time( self.re.elapsed_time() )
+ total_size = format_number( amount_read )
+ name = self._getName()
+ self.updateProgress(name,1.0,total_size,total_time)
+
+ def _getName(self):
+ '''
+ Get the name of the package being downloaded
+ '''
+ if self.text and type( self.text ) == type( "" ):
+ name = self.text
+ else:
+ name = self.basename
+ return name
+
+ def updateProgress(self,name,frac,fread,ftime):
+ '''
+ Update the progressbar (Overload in child class)
+ @param name: filename
+ @param frac: Progress fracment (0 -> 1)
+ @param fread: formated string containing BytesRead
+ @param ftime : formated string containing remaining or elapsed time
+ '''
+ pct = int( frac*100 )
+ if self.lastPct != pct:
+ self.lastPct = pct
+ # bump the sub persentage for this package
+ self.base.sub_percentage(int( frac*100 ))
+ if name != self.oldName:
+ self.oldName = name
+ if self.bump > 0.0: # Bump the total download percentage
+ self.totalPct += self.bump
+ self.base.percentage(int(self.totalPct))
+ if self.showNames:
+ pkg = self._getPackage(name)
+ if pkg: # show package to download
+ self.base._show_package(pkg,1)
+ else:
+ id = self.base.get_package_id(name, '', '', '')
+ self.base.package(id,1, "Repository MetaData")
+
+
+class PackageKitCallback(RPMBaseCallback):
+ def __init__(self,base):
+ RPMBaseCallback.__init__(self)
+ self.base = base
+ self.pct = 0
+ self.curpkg = None
+ self.startPct = 50
+ self.numPct = 50
+
+ def _calcTotalPct(self,ts_current,ts_total):
+ bump = float(self.numPct)/ts_total
+ pct = int(self.startPct + (ts_current * bump))
+ return pct
+
+ def _showName(self):
+ id = self.base.get_package_id(self.curpkg, '', '', '')
+ self.base.package(id,1, "")
+
+
+ def event(self, package, action, te_current, te_total, ts_current, ts_total):
+ if str(package) != self.curpkg:
+ self.curpkg = str(package)
+ if action in TS_INSTALL_STATES:
+ self.base.status(STATE_INSTALL)
+ elif action in TS_REMOVE_STATES:
+ self.base.status(STATE_REMOVE)
+ self._showName()
+ pct = self._calcTotalPct(ts_current, ts_total)
+ self.base.percentage(pct)
+ val = (ts_current*100L)/ts_total
+ if val != self.pct:
+ self.pct = val
+ self.base.sub_percentage(val)
+
+ def errorlog(self, msg):
+ # grrrrrrrr
+ pass
+
+class ProcessTransPackageKitCallback:
+ def __init__(self,base):
+ self.base = base
+
+ def event(self,state,data=None):
+ if state == PT_DOWNLOAD: # Start Downloading
+ self.base.allow_interrupt(True)
+ self.base.percentage(10)
+ self.base.status(STATE_DOWNLOAD)
+ if state == PT_DOWNLOAD_PKGS: # Packages to download
+ self.base.dnlCallback.setPackages(data,10,30)
+ elif state == PT_GPGCHECK:
+ self.base.percentage(40)
+ pass
+ elif state == PT_TEST_TRANS:
+ self.base.allow_interrupt(False)
+ self.base.percentage(45)
+ pass
+ elif state == PT_TRANSACTION:
+ self.base.allow_interrupt(False)
+ self.base.percentage(50)
+ pass
diff --git a/helpers/yumBackend.py b/helpers/yumBackend.py
deleted file mode 100644
index 9140ae5..0000000
--- a/helpers/yumBackend.py
+++ /dev/null
@@ -1,566 +0,0 @@
-#!/usr/bin/python -tt
-# 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 filtersion) 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 Library General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License
-# along with this program; if not, write to the Free Software
-# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
-#
-# Copyright (C) 2007 Tim Lauridsen <timlau at fedoraproject.org>
-# Copyright (C) 2007 Red Hat Inc, Seth Vidal <skvidal at fedoraproject.org>
-# Copyright (C) 2007 Luke Macken <lmacken at redhat.com>
-
-
-# imports
-
-import sys
-import re
-
-from packagekit import *
-import yum
-from urlgrabber.progress import BaseMeter,format_time,format_number
-from yum.rpmtrans import RPMBaseCallback
-from yum.constants import *
-from yum.update_md import UpdateMetadata
-from yum.callbacks import *
-
-
-class PackageKitYumBackend(PackageKitBaseBackend):
-
- def __init__(self,args):
- PackageKitBaseBackend.__init__(self,args)
- self.yumbase = yum.YumBase()
-
- def _get_package_ver(self,po):
- ''' return the a ver as epoch:version-release or version-release, if epoch=0'''
- if po.epoch != '0':
- ver = "%s:%s-%s" % (po.epoch,po.version,po.release)
- else:
- ver = "%s-%s" % (po.version,po.release)
- return ver
-
- def _do_search(self,searchlist,filters,key):
- '''
- Search for yum packages
- @param searchlist: The yum package fields to search in
- @param filters: package types to search (all,installed,available)
- @param key: key to seach for
- '''
- self.yumbase.doConfigSetup(errorlevel=0,debuglevel=0)# Setup Yum Config
- self.yumbase.conf.cache = 1 # Only look in cache.
- res = self.yumbase.searchGenerator(searchlist, [key])
- fltlist = filters.split(';')
-
- count = 1
- for (pkg,values) in res:
- if count > 100:
- break
- count+=1
- # are we installed?
- if self.yumbase.rpmdb.installed(pkg.name):
- installed = '1'
- else:
- installed = '0'
-
- if self._do_filtering(pkg,fltlist,installed):
- self._show_package(pkg, installed)
-
- def _do_filtering(self,pkg,filterList,installed):
- ''' Filter the package, based on the filter in filterList '''
-
- # do we print to stdout?
- do_print = False;
- if filterList == ['none']: # 'none' = all packages.
- return True
- elif 'installed' in filterList and installed == '1':
- do_print = True
- elif '~installed' in filterList and installed == '0':
- do_print = True
-
- if len(filterList) == 1: # Only one filter, return
- return do_print
-
- if do_print:
- return self._do_extra_filtering(pkg,filterList)
- else:
- return do_print
-
- def _do_extra_filtering(self,pkg,filterList):
- ''' do extra filtering (gui,devel etc) '''
-
- for flt in filterList:
- if flt == 'installed' or flt =='~installed':
- continue
- elif flt == 'gui' or flt =='~gui':
- if not self._do_gui_filtering(flt,pkg):
- return False
- elif flt =='devel' or flt=='~devel':
- if not self._do_devel_filtering(flt,pkg):
- return False
- return True
-
- def _do_gui_filtering(self,flt,pkg):
- isGUI = False
- if flt == 'gui':
- wantGUI = True
- else:
- wantGUI = False
- #
- # TODO: Add GUI detection Code here.Set isGUI = True, if it is a GUI app
- #
- isGUI = wantGUI # Fake it for now
- #
- #
- return isGUI == wantGUI
-
- def _do_devel_filtering(self,flt,pkg):
- isDevel = False
- if flt == 'devel':
- wantDevel = True
- else:
- wantDevel = False
- #
- # TODO: Add Devel detection Code here.Set isDevel = True, if it is a devel app
- #
- regex = re.compile(r'(-devel)|(-dgb)|(-static)')
- if regex.search(pkg.name):
- isDevel = True
- #
- #
- return isDevel == wantDevel
-
- def search_name(self,filters,key):
- '''
- Implement the {backend}-search-name functionality
- '''
- searchlist = ['name']
- self._do_search(searchlist, filters, key)
-
- def search_details(self,filters,key):
- '''
- Implement the {backend}-search-details functionality
- '''
- searchlist = ['name', 'summary', 'description', 'group']
- self._do_search(searchlist, filters, key)
-
- def search_group(self,filters,key):
- '''
- Implement the {backend}-search-group functionality
- '''
- self.error(ERROR_NOT_SUPPORTED,"This function is not implemented in this backend")
-
- def search_file(self,filters,key):
- '''
- Implement the {backend}-search-file functionality
- '''
- self.error(ERROR_NOT_SUPPORTED,"This function is not implemented in this backend")
-
- def _getEVR(self,idver):
- '''
- get the e,v,r from the package id version
- '''
- cpos = idver.find(':')
- if cpos != -1:
- epoch = idver[:cpos]
- idver = idver[cpos:]
- else:
- epoch = '0'
- (version,release) = tuple(idver.split('-'))
- return epoch,version,release
-
- def _findPackage(self,id):
- '''
- find a package based on a packahe id (name;version;arch;repoid)
- '''
- # Split up the id
- (n,idver,a,d) = self.get_package_from_id(id)
- # get e,v,r from package id version
- e,v,r = self._getEVR(idver)
- # search the rpmdb for the nevra
- pkgs = self.yumbase.rpmdb.searchNevra(name=n,epoch=e,ver=v,rel=r,arch=a)
- # if the package is found, then return it
- if len(pkgs) != 0:
- return pkgs[0],True
- # search the pkgSack for the nevra
- pkgs = self.yumbase.pkgSack.searchNevra(name=n,epoch=e,ver=v,rel=r,arch=a)
- # if the package is found, then return it
- if len(pkgs) != 0:
- return pkgs[0],False
- else:
- return None,False
-
-
- def get_deps(self,package):
- '''
- Print a list of dependencies for a given package
- '''
- self._setup_yum()
- name = package.split(';')[0]
- pkg,inst = self._findPackage(package)
- results = {}
- if pkg:
- deps = self.yumbase.findDeps([pkg]).values()[0]
- for deplist in deps.values():
- for dep in deplist:
- if not results.has_key(dep.name):
- results[dep.name] = dep
- else:
- self.error(ERROR_INTERNAL_ERROR,'Package was not found')
-
- for pkg in results.values():
- if pkg.name != name:
- pkgver = self._get_package_ver(pkg)
- id = self.get_package_id(pkg.name, pkgver, pkg.arch, pkg.repo)
- self.package(id, 1, pkg.summary)
-
- def update_system(self):
- '''
- Implement the {backend}-update-system functionality
- Needed to be implemented in a sub class
- '''
- self._setup_yum()
- self.percentage(0)
- txmbr = self.yumbase.update() # Add all updates to Transaction
- if txmbr:
- self._runYumTransaction()
- else:
- self.error(ERROR_INTERNAL_ERROR,"Nothing to do")
-
- def refresh_cache(self):
- '''
- Implement the {backend}-refresh_cache functionality
- Needed to be implemented in a sub class
- '''
- self._setup_yum()
- pct = 0
- self.percentage(pct)
- try:
- if len(self.yumbase.repos.listEnabled()) == 0:
- self.percentage(100)
- return
-
- #work out the slice for each one
- bump = (100/len(self.yumbase.repos.listEnabled()))/2
-
- for repo in self.yumbase.repos.listEnabled():
- repo.metadata_expire = 0
- self.yumbase.repos.populateSack(which=[repo.id], mdtype='metadata', cacheonly=1)
- pct+=bump
- self.percentage(pct)
- self.yumbase.repos.populateSack(which=[repo.id], mdtype='filelists', cacheonly=1)
- pct+=bump
- self.percentage(pct)
-
- #we might have a rounding error
- self.percentage(100)
-
- except yum.Errors.YumBaseError, e:
- self.error(ERROR_INTERNAL_ERROR,str(e))
-
- def install(self, package):
- '''
- Implement the {backend}-install functionality
- This will only work with yum 3.2.4 or higher
- '''
- self._setup_yum()
- self.percentage(0)
- pkg,inst = self._findPackage(package)
- if pkg:
- if inst:
- self.error(ERROR_PACKAGE_ALREADY_INSTALLED,'Package already installed')
- try:
- txmbr = self.yumbase.install(name=pkg.name)
- self._runYumTransaction()
- except yum.Errors.InstallError,e:
- print e
- msgs = ';'.join(e)
- self.error(ERROR_PACKAGE_ALREADY_INSTALLED,msgs)
- else:
- self.error(ERROR_PACKAGE_ALREADY_INSTALLED,"Package was not found")
-
- def update(self, package):
- '''
- Implement the {backend}-install functionality
- This will only work with yum 3.2.4 or higher
- '''
- self._setup_yum()
- self.percentage(0)
- pkg,inst = self._findPackage(package)
- if pkg:
- txmbr = self.yumbase.update(name=pkg.name)
- if txmbr:
- self._runYumTransaction()
- else:
- self.error(ERROR_PACKAGE_ALREADY_INSTALLED,"No available updates")
- else:
- self.error(ERROR_PACKAGE_ALREADY_INSTALLED,"No available updates")
-
-
- def _runYumTransaction(self):
- '''
- Run the yum Transaction
- This will only work with yum 3.2.4 or higher
- '''
- rc,msgs = self.yumbase.buildTransaction()
- if rc !=2:
- retmsg = "Error in Dependency Resolution;" +";".join(msgs)
- self.error(ERROR_DEP_RESOLUTION_FAILED,retmsg)
- else:
- try:
- rpmDisplay = PackageKitCallback(self)
- callback = ProcessTransPackageKitCallback(self)
- self.yumbase.processTransaction(callback=callback,
- rpmDisplay=rpmDisplay)
- except yum.Errors.YumDownloadError, msgs:
- retmsg = "Error in Download;" +";".join(msgs)
- self.error(ERROR_PACKAGE_DOWNLOAD_FAILED,retmsg)
- except yum.Errors.YumGPGCheckError, msgs:
- retmsg = "Error in Package Signatures;" +";".join(msgs)
- self.error(ERROR_INTERNAL_ERROR,retmsg)
- except yum.Errors.YumBaseError, msgs:
- retmsg = "Error in Transaction Processing;" +";".join(msgs)
- self.error(ERROR_INTERNAL_ERROR,retmsg)
-
- def remove(self, allowdep, package):
- '''
- Implement the {backend}-remove functionality
- Needed to be implemented in a sub class
- '''
- self._setup_yum()
- self.percentage(0)
- pkg,inst = self._findPackage( package)
- if pkg and inst:
- txmbr = self.yumbase.remove(name=pkg.name)
- if txmbr:
- self._runYumTransaction()
- else:
- self.error(ERROR_PACKAGE_NOT_INSTALLED,"Package is not installed")
- else:
- self.error(ERROR_PACKAGE_NOT_INSTALLED,"Package is not installed")
-
-
- def get_description(self, package):
- '''
- Print a detailed description for a given package
- '''
- self._setup_yum()
- pkg,inst = self._findPackage(package)
- if pkg:
- id = self.get_package_id(pkg.name, pkg.version,pkg.arch, pkg.repo)
- desc = pkg.description
- desc = desc.replace('\n\n',';')
- desc = desc.replace('\n',' ')
- self.description(id, "%s-%s" % (pkg.version, pkg.release),
- desc, pkg.url)
- else:
- self.error(ERROR_INTERNAL_ERROR,'Package was not found')
-
- def _show_package(self,pkg,status):
- ''' Show info about package'''
- pkgver = self._get_package_ver(pkg)
- id = self.get_package_id(pkg.name, pkgver, pkg.arch, pkg.repo)
- self.package(id,status, pkg.summary)
-
- def _get_status(self,notice):
- ut = notice['type']
- # TODO : Add more types to check
- if ut == 'security':
- return 1
- else:
- return 0
-
-
- def get_updates(self):
- '''
- Implement the {backend}-get-updates functionality
- '''
- self._setup_yum()
- md = UpdateMetadata()
- # Added extra Update Metadata
- for repo in self.yumbase.repos.listEnabled():
- try:
- md.add(repo)
- except:
- pass # No updateinfo.xml.gz in repo
-
- self.percentage(0)
- ygl = self.yumbase.doPackageLists(pkgnarrow='updates')
- for pkg in ygl.updates:
- # Get info about package in updates info
- notice = md.get_notice((pkg.name, pkg.version, pkg.release))
- if notice:
- status = self._get_status(notice)
- self._show_package(pkg,status)
- else:
- self._show_package(pkg,0)
-
-
- def _setup_yum(self):
- self.yumbase.doConfigSetup(errorlevel=0,debuglevel=0) # Setup Yum Config
- self.dnlCallback = DownloadCallback(self,showNames=True) # Download callback
- self.yumbase.repos.setProgressBar( self.dnlCallback ) # Setup the download callback class
-
-class DownloadCallback( BaseMeter ):
- """ Customized version of urlgrabber.progress.BaseMeter class """
- def __init__(self,base,showNames = False):
- BaseMeter.__init__( self )
- self.totSize = ""
- self.base = base
- self.showNames = showNames
- self.oldName = None
- self.lastPct = 0
- self.totalPct = 0
- self.pkgs = None
- self.numPkgs=0
- self.bump = 0.0
-
- def setPackages(self,pkgs,startPct,numPct):
- self.pkgs = pkgs
- self.numPkgs = len(self.pkgs)
- self.bump = numPct/self.numPkgs
- self.totalPct = startPct
-
- def _getPackage(self,name):
- name = name.split('-')[0]
- if self.pkgs:
- for pkg in self.pkgs:
- if pkg.name == name:
- return pkg
- return None
-
- def update( self, amount_read, now=None ):
- BaseMeter.update( self, amount_read, now )
-
- def _do_start( self, now=None ):
- name = self._getName()
- self.updateProgress(name,0.0,"","")
- if not self.size is None:
- self.totSize = format_number( self.size )
-
- def _do_update( self, amount_read, now=None ):
- fread = format_number( amount_read )
- name = self._getName()
- if self.size is None:
- # Elapsed time
- etime = self.re.elapsed_time()
- fetime = format_time( etime )
- frac = 0.0
- self.updateProgress(name,frac,fread,fetime)
- else:
- # Remaining time
- rtime = self.re.remaining_time()
- frtime = format_time( rtime )
- frac = self.re.fraction_read()
- self.updateProgress(name,frac,fread,frtime)
-
-
- def _do_end( self, amount_read, now=None ):
- total_time = format_time( self.re.elapsed_time() )
- total_size = format_number( amount_read )
- name = self._getName()
- self.updateProgress(name,1.0,total_size,total_time)
-
- def _getName(self):
- '''
- Get the name of the package being downloaded
- '''
- if self.text and type( self.text ) == type( "" ):
- name = self.text
- else:
- name = self.basename
- return name
-
- def updateProgress(self,name,frac,fread,ftime):
- '''
- Update the progressbar (Overload in child class)
- @param name: filename
- @param frac: Progress fracment (0 -> 1)
- @param fread: formated string containing BytesRead
- @param ftime : formated string containing remaining or elapsed time
- '''
- pct = int( frac*100 )
- if self.lastPct != pct:
- self.lastPct = pct
- # bump the sub persentage for this package
- self.base.sub_percentage(int( frac*100 ))
- if name != self.oldName:
- self.oldName = name
- if self.bump > 0.0: # Bump the total download percentage
- self.totalPct += self.bump
- self.base.percentage(int(self.totalPct))
- if self.showNames:
- pkg = self._getPackage(name)
- if pkg: # show package to download
- self.base._show_package(pkg,1)
- else:
- id = self.base.get_package_id(name, '', '', '')
- self.base.package(id,1, "Repository MetaData")
-
-
-class PackageKitCallback(RPMBaseCallback):
- def __init__(self,base):
- RPMBaseCallback.__init__(self)
- self.base = base
- self.pct = 0
- self.curpkg = None
- self.startPct = 50
- self.numPct = 50
-
- def _calcTotalPct(self,ts_current,ts_total):
- bump = float(self.numPct)/ts_total
- pct = int(self.startPct + (ts_current * bump))
- return pct
-
- def _showName(self):
- id = self.base.get_package_id(self.curpkg, '', '', '')
- self.base.package(id,1, "")
-
-
- def event(self, package, action, te_current, te_total, ts_current, ts_total):
- if str(package) != self.curpkg:
- self.curpkg = str(package)
- if action in TS_INSTALL_STATES:
- self.base.status(STATE_INSTALL)
- elif action in TS_REMOVE_STATES:
- self.base.status(STATE_REMOVE)
- self._showName()
- pct = self._calcTotalPct(ts_current, ts_total)
- self.base.percentage(pct)
- val = (ts_current*100L)/ts_total
- if val != self.pct:
- self.pct = val
- self.base.sub_percentage(val)
-
- def errorlog(self, msg):
- # grrrrrrrr
- pass
-
-class ProcessTransPackageKitCallback:
- def __init__(self,base):
- self.base = base
-
- def event(self,state,data=None):
- if state == PT_DOWNLOAD: # Start Downloading
- self.base.allow_interrupt(True)
- self.base.percentage(10)
- self.base.status(STATE_DOWNLOAD)
- if state == PT_DOWNLOAD_PKGS: # Packages to download
- self.base.dnlCallback.setPackages(data,10,30)
- elif state == PT_GPGCHECK:
- self.base.percentage(40)
- pass
- elif state == PT_TEST_TRANS:
- self.base.allow_interrupt(False)
- self.base.percentage(45)
- pass
- elif state == PT_TRANSACTION:
- self.base.allow_interrupt(False)
- self.base.percentage(50)
- pass
diff --git a/src/pk-task-common.c b/src/pk-task-common.c
index 193ba2d..419375b 100644
--- a/src/pk-task-common.c
+++ b/src/pk-task-common.c
@@ -291,15 +291,13 @@ pk_task_spawn_stderr_cb (PkSpawn *spawn,
* pk_task_spawn_helper_internal:
**/
static gboolean
-pk_task_spawn_helper_internal (PkTask *task, const gchar *script_part, const gchar *argument)
+pk_task_spawn_helper_internal (PkTask *task, const gchar *script, const gchar *argument)
{
gboolean ret;
gchar *filename;
gchar *command;
- gchar *script;
/* build script */
- script = g_strdup_printf ("%s-%s", BACKEND_PREFIX, script_part);
filename = g_build_filename (DATADIR, "PackageKit", "helpers", script, NULL);
if (argument != NULL) {
@@ -321,7 +319,6 @@ pk_task_spawn_helper_internal (PkTask *t
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 (script);
g_free (filename);
g_free (command);
return ret;
diff-tree f7869a403ad9996bbd0c3a56bf4543cd4c84f94b (from 688830938d545d23da6f90914073503b1712dfe7)
Author: Richard Hughes <richard at hughsie.com>
Date: Sat Sep 1 00:50:57 2007 +0100
package_id's have four fields, not three.
diff --git a/helpers/README b/helpers/README
index 3a2be4a..409acc0 100644
--- a/helpers/README
+++ b/helpers/README
@@ -257,7 +257,6 @@ STDERR error<tab>$enum<tab>description
STDOUT package<tab>$status<tab>$package_id<tab>$summary
$status: "0" if downloading, "1" if installing or updating
$package_id: The package ID name, e.g. openoffice;2.6.22;ppc64;fedora
- A package_id always has to have three sections.
$summary: The one line package summary, e.g. "Clipart for OpenOffice"
NOTE: As packages are downloaded or installed then emit them to the screen.
This allows a summary to be presented after and during the transaction.
@@ -296,7 +295,6 @@ STDERR error<tab>$enum<tab>description
STDOUT package<tab>$status<tab>$package_id<tab>$summary
$status: "0" if downloading, "1" if updating
$package_id: The package ID name, e.g. openoffice;2.6.22;ppc64;fedora
- A package_id always has to have three sections.
$summary: The one line package summary, e.g. "Clipart for OpenOffice"
NOTE: As packages are downloaded or updated then emit them to the screen.
This allows a summary to be presented after and during the transaction.
diff-tree 688830938d545d23da6f90914073503b1712dfe7 (from 7b7253a8716331fb8a5f847188dff70c126f1f2c)
Author: Grzegorz Dabrowski <gdx at o2.pl>
Date: Fri Aug 31 21:42:23 2007 +0000
fixed coding standard -> use tabs instead of spaces
diff --git a/src/pk-task-box.c b/src/pk-task-box.c
index 10e9c45..2ecd352 100644
--- a/src/pk-task-box.c
+++ b/src/pk-task-box.c
@@ -83,7 +83,7 @@ add_packages_from_list (PkTask *task, GL
/* 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)
+ gboolean *nondevel, gboolean *gui, gboolean *text)
{
gchar **sections = NULL;
gint i = 0;
@@ -240,11 +240,11 @@ find_packages (PkTask *task, const gchar
}
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;
- }
+ 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);
diff-tree 7b7253a8716331fb8a5f847188dff70c126f1f2c (from 65cb0cbc6bc266da20c973191d22e5d531101850)
Author: Grzegorz Dabrowski <gdx at o2.pl>
Date: Fri Aug 31 21:19:31 2007 +0000
added initial support for 'box' package maangement, currently only searching is supported
diff --git a/configure.ac b/configure.ac
index 6aaefd2..74985d5 100644
--- a/configure.ac
+++ b/configure.ac
@@ -165,6 +165,8 @@ if test x$with_backend = x; then
with_backend=apt
elif test -f /usr/bin/conary ; then
with_backend=conary
+ elif test -f /usr/bin/box-repos ; then
+ with_backend=box
else
with_backend=dummy
fi
@@ -175,6 +177,8 @@ if test x$with_backend = xyum; then
AC_DEFINE(BACKEND_PREFIX, "yum", [backend prefix])
elif test x$with_backend = xconary; then
AC_DEFINE(BACKEND_PREFIX, "conary", [backend prefix])
+elif test x$with_backend = xbox; then
+ AC_DEFINE(BACKEND_PREFIX, "box", [backend prefix])
else
AC_DEFINE(IGNORE_POLKIT, "err...", [if we should disable polkit])
AC_DEFINE(BACKEND_PREFIX, "dummy", [backend prefix])
@@ -289,10 +293,17 @@ if test x$with_backend = xapt; then
AC_SUBST(APT_PKG_TYPE)
fi
+if test x$with_backend = xbox; then
+ PKG_CHECK_MODULES(BOX, libbox)
+ AC_SUBST(BOX_CFLAGS)
+ AC_SUBST(BOX_LIBS)
+fi
+
AM_CONDITIONAL(BACKEND_TYPE_DUMMY, [test x$with_backend = xdummy], [using dummy backend])
AM_CONDITIONAL(BACKEND_TYPE_APT, [test x$with_backend = xapt], [using APT backend])
AM_CONDITIONAL(BACKEND_TYPE_YUM, [test x$with_backend = xyum], [using YUM backend])
AM_CONDITIONAL(BACKEND_TYPE_CONARY, [test x$with_backend = xconary], [using CONARY backend])
+AM_CONDITIONAL(BACKEND_TYPE_BOX, [test x$with_backend = xbox], [using BOX backend])
dnl ---------------------------------------------------------------------------
diff --git a/helpers/BACKENDS b/helpers/BACKENDS
index 25e6b70..78ad949 100644
--- a/helpers/BACKENDS
+++ b/helpers/BACKENDS
@@ -1,14 +1,14 @@
Current status of the backends
- | conary | yum | apt |
----------------------------------------------
-refresh-cache | X | X | |
-search-name | X | X | |
-search-details | | X | |
-get-updates | X | X | |
-update-system | | X | |
-install | | X | |
-remove | | X | |
-get-deps | | X | |
-get-description | | | |
-search-file | | | |
+ | conary | yum | apt | box |
+-----------------------------------------------------
+refresh-cache | X | X | | X |
+search-name | X | X | | X |
+search-details | | X | | |
+get-updates | X | X | | X |
+update-system | | X | | |
+install | | X | | |
+remove | | X | | |
+get-deps | | X | | |
+get-description | | | | |
+search-file | | | | X |
diff --git a/helpers/Makefile.am b/helpers/Makefile.am
index e12b0a6..84e0a33 100644
--- a/helpers/Makefile.am
+++ b/helpers/Makefile.am
@@ -38,6 +38,12 @@ dist_helper_DATA = \
$(NULL)
endif
+if BACKEND_TYPE_BOX
+dist_helper_DATA = \
+ box-refresh-cache.sh \
+ $(NULL)
+endif
+
if BACKEND_TYPE_YUM
install-data-hook:
chmod a+rx $(DESTDIR)$(helperdir)/yum*.py
@@ -48,6 +54,11 @@ install-data-hook:
chmod a+rx $(DESTDIR)$(helperdir)/conary*.py
endif
+if BACKEND_TYPE_BOX
+install-data-hook:
+ chmod a+rx $(DESTDIR)$(helperdir)/box*.sh
+endif
+
clean-local :
rm -f *~
diff --git a/helpers/box-refresh-cache.sh b/helpers/box-refresh-cache.sh
new file mode 100644
index 0000000..c236369
--- /dev/null
+++ b/helpers/box-refresh-cache.sh
@@ -0,0 +1,12 @@
+#!/bin/sh
+#
+# Copyright (C) 2007 Grzegorz Dabrowski <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.
+
+box --sync-repos
diff --git a/src/Makefile.am b/src/Makefile.am
index e608601..deb9bb0 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -80,6 +80,11 @@ packagekitd_SOURCES += \
pk-task-conary.c
endif
+if BACKEND_TYPE_BOX
+packagekitd_SOURCES += \
+ pk-task-box.c
+endif
+
packagekitd_LDADD = \
$(GLIB_LIBS) \
$(DBUS_LIBS) \
@@ -88,6 +93,13 @@ packagekitd_LDADD = \
$(POLKIT_LIBS) \
$(NULL)
+if BACKEND_TYPE_BOX
+packagekitd_INCLUDES = \
+ $(BOX_CFLAGS)
+packagekitd_LDADD += \
+ $(BOX_LIBS)
+endif
+
if BACKEND_TYPE_APT
INCLUDES += \
$(APT_CFLAGS)
diff --git a/src/pk-task-box.c b/src/pk-task-box.c
new file mode 100644
index 0000000..10e9c45
--- /dev/null
+++ b/src/pk-task-box.c
@@ -0,0 +1,525 @@
+/* -*- 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.
+ */
+
+#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, "");
+
+ 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_DEPS,*/
+ /*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;
+}
+
+
+/**
+ * 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_deps:
+ **/
+gboolean
+pk_task_get_deps (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, "GetDeps");
+ 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_not_implemented_yet (task, "GetDescription");
+ 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);
+}
+
More information about the PackageKit
mailing list