Mailinglist Archive: yast-commit (2114 mails)

< Previous Next >
[yast-commit] <rest-service> master : Sample code to access PackageKit via D-Bus
  • From: Klaus Kämpf <kkaempf@xxxxxxx>
  • Date: Tue, 22 Sep 2009 15:42:59 +0200
  • Message-id: <E1MrZcQ-0005Yu-Rt@xxxxxxxxxxxxxxxx>
ref: refs/heads/master
commit f5e6e2fee9aa72009afe47417c8de8f394f61cfe
Author: Klaus Kämpf <kkaempf@xxxxxxx>
Date: Tue Sep 22 15:42:59 2009 +0200

Sample code to access PackageKit via D-Bus

This is meant to test availability of PackageKit on a running system.
---
plugins/patches/test/packagekit.rb | 78 ++++++++++++++++++++++++++++++++++++
1 files changed, 78 insertions(+), 0 deletions(-)

diff --git a/plugins/patches/test/packagekit.rb
b/plugins/patches/test/packagekit.rb
new file mode 100644
index 0000000..ebb50b9
--- /dev/null
+++ b/plugins/patches/test/packagekit.rb
@@ -0,0 +1,78 @@
+#
+# Testing PackageKit via D-Bus
+#
+# *** This test requires a 'live' system with D-Bus running ***
+#
+require "dbus"
+
+require File.join(File.dirname(__FILE__), "test_helper")
+
+class ResolvableTest < ActiveSupport::TestCase
+
+ SERVICE = "org.freedesktop.PackageKit"
+ PATH = "/org/freedesktop/PackageKit"
+ TRANSACTION = "#{SERVICE}.Transaction"
+ TID = 100 # transaction id
+
+ def test_packagekit
+ system_bus = DBus::SystemBus.instance
+ assert system_bus
+
+ # connect to PackageKit service via SystemBus
+ pk_service = system_bus.service SERVICE
+ assert pk_service
+
+ # Create PackageKit proxy object
+ packagekit_proxy = pk_service.object PATH
+ assert packagekit_proxy
+
+ # learn about object
+ packagekit_proxy.introspect
+
+ # use the (generic) 'PackageKit' interface
+ packagekit_iface = packagekit_proxy[SERVICE]
+ assert packagekit_iface
+
+ # get transaction id via this interface
+ tid = packagekit_iface.GetTid
+ assert tid
+
+ # retrieve transaction object
+ transaction_proxy = pk_service.object(tid[0])
+ assert transaction_proxy
+ transaction_proxy.introspect
+
+ # use the 'Transaction' interface
+ transaction_iface = transaction_proxy[TRANSACTION]
+ assert transaction_iface
+ transaction_proxy.default_iface = TRANSACTION
+
+ dbusloop = DBus::Main.new
+ assert dbusloop
+ puts "Found PackageKit via D-Bus"
+
+ dbusloop << DBus::SystemBus.instance
+ transaction_proxy.on_signal("Error") do |u1,u2|
+ puts "Error"
+ dbusloop.quit
+ end
+ transaction_proxy.on_signal("Finished") do |u1,u2|
+ puts "Finished"
+ dbusloop.quit
+ end
+ transaction_proxy.on_signal("Package") do |line1,line2,line3|
+ puts "Line1: #{line1}"
+ puts "Line2: #{line2}"
+ puts "Line3: #{line3}"
+ end
+
+ puts "-- Looking for yast packages --"
+ transaction_iface.SearchName "installed;~devel", "yast2"
+
+ puts "-- dbusloop run --"
+ dbusloop.run
+ puts "-- dbusloop quit --"
+
+ packagekit_iface.SuggestDaemonQuit
+ end
+end
\ No newline at end of file
--
To unsubscribe, e-mail: yast-commit+unsubscribe@xxxxxxxxxxxx
For additional commands, e-mail: yast-commit+help@xxxxxxxxxxxx

< Previous Next >
This Thread
  • No further messages