| 1 |
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> |
| 2 |
<html xmlns="http://www.w3.org/1999/xhtml"> |
| 3 |
<head> |
| 4 |
<title>PackageKit - How do I use PackageKit?</title> |
| 5 |
<meta http-equiv="Content-Type" content="text/html;charset=utf-8"/> |
| 6 |
<link rel="stylesheet" href="style.css" type="text/css" media="screen"/> |
| 7 |
</head> |
| 8 |
<body> |
| 9 |
|
| 10 |
<table align="center" class="title"> |
| 11 |
<tr> |
| 12 |
<td><img src="img/packagekit.png" alt=""/></td> |
| 13 |
<td width="95%" valign="middle"><p class="title">How do I use PackageKit?</p></td> |
| 14 |
<td><img src="img/packagekit.png" alt=""/></td> |
| 15 |
</tr> |
| 16 |
</table> |
| 17 |
|
| 18 |
<p>Back to the <a href="index.html">main page</a></p> |
| 19 |
|
| 20 |
<h1>How do I use PackageKit?</h1> |
| 21 |
|
| 22 |
<p style="background-color:#ffdddd; padding:25px;"> |
| 23 |
If you are writing an application that wants to install packages on demand, |
| 24 |
and don't care about the low level details, there's a |
| 25 |
<a href="pk-faq.html#session-methods">session helper API</a> |
| 26 |
that you should use. |
| 27 |
It's much simpler than using PackageKit directly. |
| 28 |
</p> |
| 29 |
|
| 30 |
<h2>Using the command line</h2> |
| 31 |
<p> |
| 32 |
The <code>pkgcli</code> text-mode program allows you to interact with |
| 33 |
PackageKit on the command line. For example: |
| 34 |
</p> |
| 35 |
<pre> |
| 36 |
[hughsie@laptop ~]$ pkgcli list-updates |
| 37 |
[hughsie@hughsie-work PackageKit]$ pkgcli list-updates |
| 38 |
security bluez-utils-3.35-3.fc9 Bluetooth utilities |
| 39 |
bugfix xterm-236-1.fc9 Terminal emulator for the X Window System |
| 40 |
bugfix kernel-devel-2.6.25.14-108.fc9 Development package for building kernel modules to match the kernel |
| 41 |
enhancement kde-filesystem-4-17.fc9 KDE filesystem layout |
| 42 |
enhancement subversion-1.5.1-1.fc9 Modern Version Control System designed to replace CVS |
| 43 |
</pre> |
| 44 |
<p>or</p> |
| 45 |
<pre> |
| 46 |
[hughsie@hughsie-work PackageKit]$ pkgcli --filter=~devel search name power |
| 47 |
installed DeviceKit-power-001-0.8.20080811git.fc9 Power Management Service |
| 48 |
installed gnome-power-manager-2.23.4-1.118.20080801svn.fc9.hughsie GNOME Power Manager |
| 49 |
installed powerman-2.1-1.fc9 PowerMan - Power to the Cluster |
| 50 |
installed powertop-1.9-3.fc9 Power consumption monitor |
| 51 |
available gnome-power-manager-2.22.1-1.fc9 GNOME Power Manager |
| 52 |
available kadu-powerkadu-0.6.0-3.fc9 PowerKadu |
| 53 |
available kadu-powerkadu-0.6.0.1-1.fc9 PowerKadu |
| 54 |
available kpowersave-0.7.3-3.fc9 KPowersave is the KDE frontend for powermanagement |
| 55 |
available powerman-1.0.32-5.fc9 PowerMan - Power to the Cluster |
| 56 |
available powermanga-0.90-3 Arcade 2D shoot-them-up game |
| 57 |
</pre> |
| 58 |
<p> |
| 59 |
The <code>pkmon</code> program allows you to monitor what PackageKit is |
| 60 |
doing on the command line and is mainly used for debugging. |
| 61 |
</p> |
| 62 |
<p> |
| 63 |
The <code>pkgenpack</code> program allows you to generate |
| 64 |
<a href="pk-faq.html#service-pack">Service Packs</a> with a package and its dependencies. |
| 65 |
</p> |
| 66 |
|
| 67 |
|
| 68 |
<h2>Using graphical tools:</h2> |
| 69 |
<p> |
| 70 |
<code>gnome-software</code> and <code>gnome-packagekit</code> provide a rich |
| 71 |
set of GTK tools for automatically updating your computer and installing software. |
| 72 |
</p> |
| 73 |
<a href="http://kde-apps.org/content/show.php/Apper?content=84745"> |
| 74 |
Apper</a> is the name of the KDE graphical tools designed |
| 75 |
for PackageKit. |
| 76 |
</p> |
| 77 |
|
| 78 |
<h2>Using libpackagekit:</h2> |
| 79 |
<p> |
| 80 |
The <a href="gtk-doc/PkTask.html">libpackagekit GObject library</a> |
| 81 |
wraps the D-Bus interface in a nice GLib-style API. |
| 82 |
This makes designing programs that use libpackagekit can concentrate on |
| 83 |
core functionality rather that the D-Bus and PackageKit internals. |
| 84 |
PkTask in libpackagekit can be used as easily as: |
| 85 |
</p> |
| 86 |
<pre> |
| 87 |
GError *error = NULL; |
| 88 |
PkError *error_code = NULL; |
| 89 |
PkResults *results = NULL; |
| 90 |
GPtrArray *array = NULL; |
| 91 |
PkPackage *item; |
| 92 |
gchar **values = NULL; |
| 93 |
gchar **package_ids = NULL; |
| 94 |
uint i; |
| 95 |
PkTask *task; |
| 96 |
|
| 97 |
task = pk_task_new (); |
| 98 |
|
| 99 |
/* resolve the package name */ |
| 100 |
values = g_new0 (gchar*, 1 + 1); |
| 101 |
values[0] = g_strdup ("openclipart-libreoffice"); |
| 102 |
values[1] = NULL; |
| 103 |
|
| 104 |
results = pk_task_resolve_sync (task, PK_FILTER_ENUM_NOT_INSTALLED, values, NULL, NULL, NULL, &error); |
| 105 |
if (results == NULL) { |
| 106 |
/* the operation failed: results is NULL and error is set */ |
| 107 |
g_printerr ("%s: %s\n", "Resolving of packages failed", error->message); |
| 108 |
goto out; |
| 109 |
} |
| 110 |
|
| 111 |
/* check error code */ |
| 112 |
error_code = pk_results_get_error_code (results); |
| 113 |
if (error_code != NULL) { |
| 114 |
g_printerr ("%s: %s, %s\n", "Resolving of packages failed", |
| 115 |
pk_error_enum_to_string (pk_error_get_code (error_code)), |
| 116 |
pk_error_get_details (error_code)); |
| 117 |
goto out; |
| 118 |
} |
| 119 |
|
| 120 |
/* get the packages returned */ |
| 121 |
array = pk_results_get_package_array (results); |
| 122 |
package_ids = g_new0 (gchar *, array->len+1); |
| 123 |
for (i = 0; i < array->len; i++) { |
| 124 |
item = g_ptr_array_index (array, i); |
| 125 |
package_ids[i] = g_strdup (pk_package_get_id (item)); |
| 126 |
} |
| 127 |
|
| 128 |
/* install the packages */ |
| 129 |
g_clear_object (&results); |
| 130 |
results = pk_task_install_packages_sync (task, package_ids , NULL, NULL, NULL, &error); |
| 131 |
if (results == NULL) { |
| 132 |
/* the operation failed: results is NULL and error is set */ |
| 133 |
g_printerr ("%s: %s\n", _("Error installing package(s)!"), error->message); |
| 134 |
goto out; |
| 135 |
} |
| 136 |
|
| 137 |
/* check error code */ |
| 138 |
error_code = pk_results_get_error_code (results); |
| 139 |
if (error_code != NULL) { |
| 140 |
g_printerr ("%s: %s, %s\n", _("Error installing package(s)!"), |
| 141 |
pk_error_enum_to_string (pk_error_get_code (error_code)), |
| 142 |
pk_error_get_details (error_code)); |
| 143 |
goto out; |
| 144 |
} |
| 145 |
|
| 146 |
out: |
| 147 |
g_clear_error (&error); |
| 148 |
g_strfreev (values); |
| 149 |
g_object_unref (task); |
| 150 |
if (error_code != NULL) |
| 151 |
g_object_unref (error_code); |
| 152 |
if (array != NULL) |
| 153 |
g_ptr_array_unref (array); |
| 154 |
if (package_ids != NULL) |
| 155 |
g_strfreev (package_ids); |
| 156 |
if (results != NULL) |
| 157 |
g_object_unref (results); |
| 158 |
</pre> |
| 159 |
|
| 160 |
<h2>Using the raw D-Bus API:</h2> |
| 161 |
<p> |
| 162 |
Using the <a href="gtk-doc/api-reference.html">PackageKit D-Bus methods |
| 163 |
and signals</a> directly means that no GLib or GObject dependency is |
| 164 |
needed, although this means you will have to manage the transaction_id |
| 165 |
multiplexing in any client program. This is not difficult, although |
| 166 |
does require more code than just using libpackagekit. |
| 167 |
</p> |
| 168 |
|
| 169 |
<p>Back to the <a href="index.html">main page</a></p> |
| 170 |
|
| 171 |
<p class="footer"> |
| 172 |
Copyright <a href="mailto:[email protected]">Richard Hughes 2007-2013</a><br/> |
| 173 |
<a href="http://validator.w3.org/check/referer">Optimized</a> |
| 174 |
for <a href="http://www.w3.org/">standards</a>. |
| 175 |
</p> |
| 176 |
|
| 177 |
</body> |
| 178 |
</html> |