File: pk-using.html

package info (click to toggle)
packagekit 1.3.3-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 14,704 kB
  • sloc: ansic: 56,209; cpp: 13,919; python: 4,970; xml: 4,945; sh: 313; perl: 60; makefile: 57
file content (165 lines) | stat: -rw-r--r-- 6,000 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>PackageKit - How do I use PackageKit?</title>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8"/>
<link rel="stylesheet" href="style.css" type="text/css" media="screen"/>
</head>
<body>

<table align="center" class="title">
<tr>
 <td><img src="img/packagekit.png" alt=""/></td>
 <td width="95%" valign="middle"><p class="title">How do I use PackageKit?</p></td>
 <td><img src="img/packagekit.png" alt=""/></td>
</tr>
</table>

<p>Back to the <a href="index.html">main page</a></p>

<h1>How do I use PackageKit?</h1>

<p style="background-color:#ffdddd; padding:25px;">
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
<a href="pk-faq.html#session-methods">session helper API</a>
that you should use.
It's much simpler than using PackageKit directly.
</p>

<h2>Using the command line</h2>
<p>
The <code>pkcon</code> text-mode program allows you to interact with
PackageKit on the command line. For example:
</p>
<pre>
[hughsie@laptop ~]$ pkcon get-updates
[hughsie@hughsie-work PackageKit]$ pkcon get-updates
security    	bluez-utils-3.35-3.fc9                  	Bluetooth utilities
bugfix      	xterm-236-1.fc9                         	Terminal emulator for the X Window System
bugfix      	kernel-devel-2.6.25.14-108.fc9          	Development package for building kernel modules to match the kernel
enhancement 	kde-filesystem-4-17.fc9                 	KDE filesystem layout
enhancement 	subversion-1.5.1-1.fc9                  	Modern Version Control System designed to replace CVS
</pre>
<p>or</p>
<pre>
[hughsie@hughsie-work PackageKit]$ pkcon --filter=~devel search name power
installed   	DeviceKit-power-001-0.8.20080811git.fc9 	Power Management Service
installed   	gnome-power-manager-2.23.4-1.118.20080801svn.fc9.hughsie	GNOME Power Manager
installed   	powerman-2.1-1.fc9                      	PowerMan - Power to the Cluster
installed   	powertop-1.9-3.fc9                      	Power consumption monitor
available   	gnome-power-manager-2.22.1-1.fc9        	GNOME Power Manager
available   	kadu-powerkadu-0.6.0-3.fc9              	PowerKadu
available   	kadu-powerkadu-0.6.0.1-1.fc9            	PowerKadu
available   	kpowersave-0.7.3-3.fc9                  	KPowersave is the KDE frontend for powermanagement
available   	powerman-1.0.32-5.fc9                   	PowerMan - Power to the Cluster
available   	powermanga-0.90-3                       	Arcade 2D shoot-them-up game
</pre>
<p>
The <code>pkmon</code> program allows you to monitor what PackageKit is
doing on the command line and is mainly used for debugging.
</p>
<p>
The <code>pkgenpack</code> program allows you to generate
<a href="pk-faq.html#service-pack">Service Packs</a> with a package and its dependencies.
</p>


<h2>Using graphical tools:</h2>
<p>
<code>gnome-software</code> and <code>gnome-packagekit</code> provide a rich
set of GTK tools for automatically updating your computer and installing software.
</p>
<a href="http://kde-apps.org/content/show.php/Apper?content=84745">
Apper</a> is the name of the KDE graphical tools designed
for PackageKit.
</p>

<h2>Using libpackagekit:</h2>
<p>
The <a href="gtk-doc/PkTask.html">libpackagekit gobject library</a>
wraps the DBus interface in a nice glib-style API.
This makes designing programs that use libpackagekit can concentrate on
core functionality rather that the DBus and PackageKit internals.
PkTask in libpackagekit can be used as easily as:
</p>
<pre>
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, &amp;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 &lt; 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, &amp;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);
</pre>

<h2>Using the raw DBus API:</h2>
<p>
Using the <a href="gtk-doc/api-reference.html">PackageKit DBus methods
and signals</a> directly means that no glib or gobject dependency is
needed, although this means you will have to manage the transaction_id
multiplexing in any client program.  This is not difficult, although
does require more code than just using libpackagekit.
</p>

<p>Back to the <a href="index.html">main page</a></p>

<p class="footer">
 Copyright <a href="mailto:richard@hughsie.com">Richard Hughes 2007-2013</a><br/>
 <a href="http://validator.w3.org/check/referer">Optimized</a>
 for <a href="http://www.w3.org/">standards</a>.
</p>

</body>
</html>