Mailinglist Archive: yast-commit (1771 mails)

< Previous Next >
[yast-commit] <rest-service> network : initial checkin of package controller and model
  • From: Bjoern Geuken <bgeuken@xxxxxxx>
  • Date: Fri, 21 Aug 2009 15:11:07 +0200
  • Message-id: <E1MiTqH-0006Yz-KJ@xxxxxxxxxxxxxxxx>
ref: refs/heads/network
commit f2875ca0bf79a39d158e75b5b81e26f93b114a23
Author: Bjoern Geuken <bgeuken@xxxxxxx>
Date: Fri Aug 21 15:11:07 2009 +0200

initial checkin of package controller and model
---
.../patches/app/controllers/packages_controller.rb | 27 ++++++
plugins/patches/app/models/package.rb | 88 ++++++++++++++++++++
2 files changed, 115 insertions(+), 0 deletions(-)

diff --git a/plugins/patches/app/controllers/packages_controller.rb
b/plugins/patches/app/controllers/packages_controller.rb
new file mode 100644
index 0000000..29ee1f3
--- /dev/null
+++ b/plugins/patches/app/controllers/packages_controller.rb
@@ -0,0 +1,27 @@
+require 'singleton'
+
+class PackagesController < ApplicationController
+
+ before_filter :login_required
+
+ private
+
+ def check_read_permissions
+ unless permission_check( "org.opensuse.yast.system.patches.read")
+ render ErrorResult.error(403, 1, "no permission") and return
+ end
+ end
+
+ public
+
+ # GET /packages
+ # GET /packages.xml
+ def index
+ # note: permission check was performed in :before_filter
+ @installed_packages = Package.find()
+ if @installed_packages == -1
+ logger.error "Package Module: DBUS Resource is not available."
+ render ErrorResult.error(423, 1, "DBUS Resource is not available.") and
return
+ end
+ end
+end
diff --git a/plugins/patches/app/models/package.rb
b/plugins/patches/app/models/package.rb
new file mode 100644
index 0000000..3ccb3bf
--- /dev/null
+++ b/plugins/patches/app/models/package.rb
@@ -0,0 +1,88 @@
+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 packages available via package kit
+class Package
+
+ attr_accessor :resolvable_id,
+ :name,
+ :version
+
+ def initialize()
+
+ end
+
+ 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!(:name, @name )
+ xml.tag!(:version, @version )
+ end
+ end
+
+ def to_json( options = {} )
+ hash = Hash.from_xml(to_xml())
+ return hash.to_json
+ end
+
+ def self.find()
+ begin
+ package_list = Array.new
+ 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"
+
+ obj_tid_with_iface.GetPackages("installed")
+
+ obj_tid.on_signal("Package") do |line1,line2,line3|
+ columns = line2.split ";"
+ package_list << Package.new(:resolvable_id => line2,
+ :version => columns[1],
+ :name => columns[0]
+ )
+ end
+
+ obj_tid.on_signal("Error") do |u1,u2|
+ raise PKErrorException
+ end
+ obj_tid.on_signal("Finished") do |u1,u2|
+ raise PKFinishedException
+ end
+
+ if package_list.empty?
+ loop = DBus::Main.new
+ loop << system_bus
+ begin
+ loop.run
+ rescue PKErrorException
+ rescue PKFinishedException
+ end
+ end
+ rescue Exception
+ return -1
+ end
+
+ obj_with_iface.SuggestDaemonQuit
+
+ package_list
+ end
+end
--
To unsubscribe, e-mail: yast-commit+unsubscribe@xxxxxxxxxxxx
For additional commands, e-mail: yast-commit+help@xxxxxxxxxxxx

< Previous Next >
This Thread
  • No further messages