|
How do I use PackageKit? |
|
Back to the main page
If you are writing an application that wants to install packages on demand,and don't care about the low level details, there's a session helper API that you should use.It's much simpler than using PackageKit directly.
The
pkcon
text-mode program allows you to interact withPackageKit on the command line. For example:
[hughsie@laptop ~]$ pkcon get-updates[ PackageKit]$ pkcon get-updatessecurity bluez-utils-3.35-3.fc9 Bluetooth utilitiesbugfix xterm-236-1.fc9 Terminal emulator for the X Window Systembugfix kernel-devel-2.6.25.14-108.fc9 Development package for building kernel modules to match the kernelenhancement kde-filesystem-4-17.fc9 KDE filesystem layoutenhancement subversion-1.5.1-1.fc9 Modern Version Control System designed to replace CVS
or
[ PackageKit]$ pkcon --filter=~devel search name powerinstalled DeviceKit-power-001-0.8.20080811git.fc9 Power Management Serviceinstalled gnome-power-manager-2.23.4-1.118.20080801svn.fc9.hughsieGNOME Power Managerinstalled powerman-2.1-1.fc9 PowerMan - Power to the Clusterinstalled powertop-1.9-3.fc9 Power consumption monitoravailable gnome-power-manager-2.22.1-1.fc9 GNOME Power Manageravailable kadu-powerkadu-0.6.0-3.fc9 PowerKaduavailable kadu-powerkadu-0.6.0.1-1.fc9 PowerKaduavailable kpowersave-0.7.3-3.fc9 KPowersave is the KDE frontend for powermanagementavailable powerman-1.0.32-5.fc9 PowerMan - Power to the Clusteravailable powermanga-0.90-3 Arcade 2D shoot-them-up game
The
pkmon
program allows you to monitor what PackageKit isdoing on the command line and is mainly used for debugging.
The
pkgenpack
program allows you to generate
Service Packs
with a package and its dependencies.
gnome-packagekit
provides a rich set of GTK tools forautomatically updating your computer and installing software.See the
screenshots page
for more details.
The libpackagekit gobject library wraps the DBus interface in a nice glib-style API.This makes designing programs that use libpackagekit can concentrate oncore functionality rather that the DBus and PackageKit internals.PkTask in libpackagekit can be used as easily as:
GError *error = NULL;PkError *error_code = NULL;PkResults *results = NULL;GPtrArray *array = NULL;PkPackage *item;gchar **values = NULL;gchar **package_ids = NULL;uint i;PkTask *task;task = pk_task_new ();/* resolve the package name */values = g_new0 (gchar*, 1 + 1);values[0] = g_strdup ("openoffice-clipart");values[1] = NULL;results = pk_task_resolve_sync (task, PK_FILTER_ENUM_NOT_INSTALLED, values, NULL, NULL, NULL, &error);/* check error code */error_code = pk_results_get_error_code (results);if (error_code != NULL) {g_printerr ("%s: %s, %s\n", "Resolving of packages failed", pk_error_enum_to_string (pk_error_get_code (error_code)), pk_error_get_details (error_code));goto out;}/* get the packages returned */array = pk_results_get_package_array (results);package_ids = g_new0 (gchar *, array->len+1);for (i = 0; i < array->len; i++) {item = g_ptr_array_index (array, i);package_ids[i] = g_strdup (pk_package_get_id (item));}/* install the packages */results = pk_task_install_packages_sync (task, package_ids , NULL, NULL, NULL, &error);/* check error code */error_code = pk_results_get_error_code (results);if (error_code != NULL) {g_printerr ("%s: %s, %s\n", _("Error installing package(s)!"),pk_error_enum_to_string (pk_error_get_code (error_code)),pk_error_get_details (error_code));goto out;}out:g_strfreev (values);g_object_unref (task);if (error_code != NULL)g_object_unref (error_code);if (array != NULL)g_ptr_array_unref (array);if (package_ids != NULL)g_strfreev (package_ids);if (results != NULL)g_object_unref (results);
Using the DBus methods and signals directly means that no glib orgobject dependency is needed, although this means you will have tomanage the transaction_id multiplexing in any client program.This is not difficult, although does require more code than just usinglibpackagekit.The latest interface is available in the source tree or on-line .
Back to the main page