ref: refs/heads/master
commit 275f390301a0433a84ff95f3a7285d290f913ee2
Author: Martin Vidner
Date: Thu Aug 27 10:33:09 2009 +0200
Use DBus::Main.quit instead of throwing exceptions.
(ruby-dbus 0.2.9 is required)
Also removed useless conditions around the loop.
---
plugins/patches/app/models/packagekit.rb | 30 ++++----------------
plugins/patches/app/models/patch.rb | 29 ++++--------------
.../patches/package/yast2-webservice-patches.spec | 3 ++
3 files changed, 16 insertions(+), 46 deletions(-)
diff --git a/plugins/patches/app/models/packagekit.rb b/plugins/patches/app/models/packagekit.rb
index de85cf6..5f7c654 100644
--- a/plugins/patches/app/models/packagekit.rb
+++ b/plugins/patches/app/models/packagekit.rb
@@ -2,11 +2,6 @@ require "dbus"
require 'socket'
require 'thread'
-# Used to stop DBus::Main loop
-class PKErrorException < Exception; end
-# Used to stop DBus::Main loop
-class PKFinishedException < Exception; end
-
# Model for patches available via package kit
class PackageKitModule
@@ -58,28 +53,15 @@ class PackageKitModule
obj_tid_with_iface = obj_tid["org.freedesktop.PackageKit.Transaction"]
obj_tid.default_iface = "org.freedesktop.PackageKit.Transaction"
- obj_tid.on_signal(signal.to_s, &block)
+ loop = DBus::Main.new
+ loop << system_bus
- obj_tid.on_signal("Error") do |u1,u2|
- raise PKErrorException
- end
- obj_tid.on_signal("Finished") do |u1,u2|
- raise PKFinishedException
- end
+ obj_tid.on_signal(signal.to_s, &block)
+ obj_tid.on_signal("Error") {|u1,u2| loop.quit }
+ obj_tid.on_signal("Finished") {|u1,u2| loop.quit }
obj_tid_with_iface.send(method.to_sym, *args)
-
- if patch_updates.empty?
- loop = DBus::Main.new
- loop << system_bus
- begin
- loop.run
- rescue PKErrorException
- puts "PKErrorException"
- rescue PKFinishedException
- puts "PKFinished"
- end
- end
+ loop.run
obj_with_iface.SuggestDaemonQuit
return patch_updates
diff --git a/plugins/patches/app/models/patch.rb b/plugins/patches/app/models/patch.rb
index 2a5c856..eaf0e58 100644
--- a/plugins/patches/app/models/patch.rb
+++ b/plugins/patches/app/models/patch.rb
@@ -1,10 +1,5 @@
require 'packagekit'
-# Used to stop DBus::Main loop
-class PKErrorException < Exception; end
-# Used to stop DBus::Main loop
-class PKFinishedException < Exception; end
-
# Model for patches available via package kit
class Patch < PackageKitModule
@@ -104,31 +99,21 @@ class Patch < PackageKitModule
obj_tid_with_iface = obj_tid["org.freedesktop.PackageKit.Transaction"]
obj_tid.default_iface = "org.freedesktop.PackageKit.Transaction"
- finished = false
obj_tid.on_signal("Package") do |line1,line2,line3|
Rails.logger.debug " update package: #{line2}"
end
+ loop = DBus::Main.new
+ loop << system_bus
+
+ obj_tid.on_signal("Finished") {|u1,u2| loop.quit }
obj_tid.on_signal("Error") do |u1,u2|
- raise PKErrorException
- end
- obj_tid.on_signal("Finished") do |u1,u2|
- raise PKFinishedException
+ ok = false
+ loop.quit
end
obj_tid_with_iface.UpdatePackages([pkkit_id])
- unless finished
- loop = DBus::Main.new
- loop << system_bus
- begin
- loop.run
- rescue PKErrorException
- finished = true
- ok = false
- rescue PKFinishedException
- finished = true
- end
- end
+ loop.run
obj_with_iface.SuggestDaemonQuit
return ok
diff --git a/plugins/patches/package/yast2-webservice-patches.spec b/plugins/patches/package/yast2-webservice-patches.spec
index 75d6064..6b6355a 100644
--- a/plugins/patches/package/yast2-webservice-patches.spec
+++ b/plugins/patches/package/yast2-webservice-patches.spec
@@ -11,6 +11,9 @@
Name: yast2-webservice-patches
PreReq: yast2-webservice
+# ruby-dbus is required by yast2-webservice already
+# but here we use a recent feature of DBus::Main.quit
+Requires: ruby-dbus >= 0.2.9
Provides: yast2-webservice:/srv/www/yastws/app/controllers/patch_updates_controller.rb
License: MIT
Group: Productivity/Networking/Web/Utilities
--
To unsubscribe, e-mail: yast-commit+unsubscribe@opensuse.org
For additional commands, e-mail: yast-commit+help@opensuse.org