Mailinglist Archive: yast-commit (2080 mails)

< Previous Next >
[yast-commit] <rest-service> network : Consolidate to_xml and d-bus access
  • From: Klaus Kämpf <kkaempf@xxxxxxx>
  • Date: Thu, 10 Sep 2009 12:11:27 +0200
  • Message-id: <E1Mm10t-0002Qg-SC@xxxxxxxxxxxxxxxx>
ref: refs/heads/network
commit c18ab71323a5fc9278e48e9b8917f4f9fc5ede0d
Author: Klaus Kämpf <kkaempf@xxxxxxx>
Date: Thu Sep 10 12:11:27 2009 +0200

Consolidate to_xml and d-bus access
---
plugins/patches/app/models/package.rb | 9 +--
plugins/patches/app/models/patch.rb | 48 +-------------
plugins/patches/app/models/resolvable.rb | 110 ++++++++++++++++++++++-------
3 files changed, 85 insertions(+), 82 deletions(-)

diff --git a/plugins/patches/app/models/package.rb
b/plugins/patches/app/models/package.rb
index 47a7511..9af723d 100644
--- a/plugins/patches/app/models/package.rb
+++ b/plugins/patches/app/models/package.rb
@@ -3,14 +3,7 @@ require 'resolvable'
class Package < Resolvable

def to_xml( options = {} )
- xml = options[:builder] ||= Builder::XmlMarkup.new(options)
- xml.instruct! unless options[:skip_instruct]
-
- xml.package do
- xml.tag!(:resolvable_id, @resolvable_id )
- xml.tag!(:name, @name )
- xml.tag!(:version, @version )
- end
+ super :package, options
end

def self.find(what)
diff --git a/plugins/patches/app/models/patch.rb
b/plugins/patches/app/models/patch.rb
index d53e900..eb73f63 100644
--- a/plugins/patches/app/models/patch.rb
+++ b/plugins/patches/app/models/patch.rb
@@ -4,17 +4,7 @@ require 'resolvable'
class Patch < Resolvable

def to_xml( options = {} )
- xml = options[:builder] ||= Builder::XmlMarkup.new(options)
- xml.instruct! unless options[:skip_instruct]
-
- xml.patch_update do
- xml.tag!(:resolvable_id, @resolvable_id, {:type => "integer"} )
- xml.tag!(:kind, @kind )
- xml.tag!(:name, @name )
- xml.tag!(:arch, @arch )
- xml.tag!(:repo, @repo )
- xml.tag!(:summary, @summary )
- end
+ super :patch_update, options
end

# find patches
@@ -58,40 +48,4 @@ class Patch < Resolvable
end
end

- # install an update, based on the PackageKit
- # id
- def self.package_kit_install(pkkit_id)
- ok = true
- system_bus = DBus::SystemBus.instance
- package_kit = system_bus.service("org.freedesktop.PackageKit")
- obj = package_kit.object("/org/freedesktop/PackageKit")
- obj.introspect
- obj_with_iface = obj["org.freedesktop.PackageKit"]
- tid = obj_with_iface.GetTid
- obj_tid = package_kit.object(tid[0])
- obj_tid.introspect
- obj_tid_with_iface = obj_tid["org.freedesktop.PackageKit.Transaction"]
- obj_tid.default_iface = "org.freedesktop.PackageKit.Transaction"
-
- 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|
- ok = false
- loop.quit
- end
- obj_tid_with_iface.UpdatePackages([pkkit_id])
-
- loop.run
- obj_with_iface.SuggestDaemonQuit
-
- return ok
- end
-
-
end
diff --git a/plugins/patches/app/models/resolvable.rb
b/plugins/patches/app/models/resolvable.rb
index 8aba62b..9710a48 100644
--- a/plugins/patches/app/models/resolvable.rb
+++ b/plugins/patches/app/models/resolvable.rb
@@ -13,6 +13,36 @@ class Resolvable
:repo,
:summary

+private
+ def self.packagekit_connect
+
+ system_bus = DBus::SystemBus.instance
+ package_kit = system_bus.service("org.freedesktop.PackageKit")
+ obj = package_kit.object("/org/freedesktop/PackageKit")
+ #logger.debug obj.inspect
+ obj.introspect
+ obj_with_iface = obj["org.freedesktop.PackageKit"]
+ tid = obj_with_iface.GetTid
+ obj_tid = package_kit.object(tid[0])
+ obj_tid.introspect
+ obj_tid_with_iface = obj_tid["org.freedesktop.PackageKit.Transaction"]
+ obj_tid.default_iface = "org.freedesktop.PackageKit.Transaction"
+
+ dbusloop = DBus::Main.new
+ dbusloop << system_bus
+
+ [dbusloop, obj_tid, obj_with_iface, obj_tid_with_iface]
+ end
+
+public
+
+ # default constructor
+ def initialize(attributes)
+ attributes.each do |key, value|
+ instance_variable_set("@#{key}", value)
+ end
+ end
+
def id
@resolvable_id
end
@@ -21,6 +51,30 @@ class Resolvable
@resolvable_id = id_val
end

+ # get xml representation of instance
+ # tag: name of toplevel tag (i.e. :package)
+ #
+ def to_xml( tag, options = {} )
+ xml = options[:builder] ||= Builder::XmlMarkup.new(options)
+ xml.instruct! unless options[:skip_instruct]
+
+ xml.send tag.to_sym do
+ xml.tag!(:resolvable_id, @resolvable_id, {:type => "integer"} )
+ xml.tag!(:kind, @kind )
+ xml.tag!(:name, @name )
+ xml.tag!(:version, @version )
+ xml.tag!(:arch, @arch )
+ xml.tag!(:repo, @repo )
+ xml.tag!(:summary, @summary )
+ end
+
+ end
+
+ def to_json( options = {} )
+ hash = Hash.from_xml(to_xml())
+ return hash.to_json
+ end
+
# returns the modification time of the resolvable
# which you can use for cache policy purposes
def self.mtime
@@ -31,49 +85,51 @@ class Resolvable
* Dir["/var/cache/zypp/solv/*/solv"].map{ |x| File.stat(x).mtime } ].max
end

- # default constructor
- def initialize(attributes)
- attributes.each do |key, value|
- instance_variable_set("@#{key}", value)
- end
- end
-
- def to_json( options = {} )
- hash = Hash.from_xml(to_xml())
- return hash.to_json
- end
-
# find patches
# Patch.find(:available)
# Patch.find(212)
def self.execute(method, args, signal, &block)
patch_updates = []
- system_bus = DBus::SystemBus.instance
- package_kit = system_bus.service("org.freedesktop.PackageKit")
- obj = package_kit.object("/org/freedesktop/PackageKit")
- #logger.debug obj.inspect
- obj.introspect
- obj_with_iface = obj["org.freedesktop.PackageKit"]
- tid = obj_with_iface.GetTid
- obj_tid = package_kit.object(tid[0])
- obj_tid.introspect
- obj_tid_with_iface = obj_tid["org.freedesktop.PackageKit.Transaction"]
- obj_tid.default_iface = "org.freedesktop.PackageKit.Transaction"
-
- loop = DBus::Main.new
- loop << system_bus

+ dbusloop, obj_tid, obj_with_iface, obj_tid_with_iface =
self.packagekit_connect
+
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)
- loop.run
+ dbusloop.run

obj_with_iface.SuggestDaemonQuit
return patch_updates
end

+ # install an update, based on the PackageKit
+ # id
+ def self.package_kit_install(pkkit_id)
+ ok = true
+ mainloop, obj_tid, obj_with_iface, obj_tid_with_iface =
self.packagekit_connect
+
+ obj_tid.on_signal("Package") do |line1,line2,line3|
+ Rails.logger.debug " update package: #{line2}"
+ end
+
+ dbusloop = DBus::Main.new
+ dbusloop << system_bus
+
+ obj_tid.on_signal("Finished") {|u1,u2| loop.quit }
+ obj_tid.on_signal("Error") do |u1,u2|
+ ok = false
+ dbusloop.quit
+ end
+ obj_tid_with_iface.UpdatePackages([pkkit_id])
+
+ dbusloop.run
+ obj_with_iface.SuggestDaemonQuit
+
+ return ok
+ end
+
# installs this
def install
self.class.install(id)
--
To unsubscribe, e-mail: yast-commit+unsubscribe@xxxxxxxxxxxx
For additional commands, e-mail: yast-commit+help@xxxxxxxxxxxx

< Previous Next >
This Thread
  • No further messages