Mailinglist Archive: yast-commit (1771 mails)

< Previous Next >
[yast-commit] <rest-service> network : patches module: added policikit class, which is parent of package and patch model
  • From: Bjoern Geuken <bgeuken@xxxxxxx>
  • Date: Mon, 24 Aug 2009 13:31:19 +0200
  • Message-id: <E1MiTqI-0006Zu-Ca@xxxxxxxxxxxxxxxx>
ref: refs/heads/network
commit 10e502901ee5e98552aa1c701cf7d2d965587fa2
Author: Bjoern Geuken <bgeuken@xxxxxxx>
Date: Mon Aug 24 13:31:19 2009 +0200

patches module: added policikit class, which is parent of package and patch
model
---
.../patches/app/controllers/packages_controller.rb | 27 -----
.../patches/app/controllers/patches_controller.rb | 19 +++-
plugins/patches/app/models/package.rb | 90 ++++------------
plugins/patches/app/models/patch.rb | 70 ++-----------
plugins/patches/app/models/policykit.rb | 112 ++++++++++++++++++++
5 files changed, 159 insertions(+), 159 deletions(-)

diff --git a/plugins/patches/app/controllers/packages_controller.rb
b/plugins/patches/app/controllers/packages_controller.rb
deleted file mode 100644
index 29ee1f3..0000000
--- a/plugins/patches/app/controllers/packages_controller.rb
+++ /dev/null
@@ -1,27 +0,0 @@
-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/controllers/patches_controller.rb
b/plugins/patches/app/controllers/patches_controller.rb
index e2512ac..b1077e1 100644
--- a/plugins/patches/app/controllers/patches_controller.rb
+++ b/plugins/patches/app/controllers/patches_controller.rb
@@ -44,11 +44,20 @@ class PatchesController < ApplicationController
# GET /patch_updates.xml
def index
# note: permission check was performed in :before_filter
- @patch_updates = Patch.find(:available)
- if @patch_updates == -1
- logger.error "Patch Module: PackageKit is not available."
- render ErrorResult.error(423, 1, "PackageKit is not available. It might
"+\
- "be blocked by another process") and
return
+# @package_kit = Patch.find(:available)
+ @package_kit = Package.find(:installed)
+ #case params[:type]
+ # when "patch"
+ @package_kit = Patch.find(:available)
+ # when "package"
+ # @package_kit = Package.find(:installed)
+ # else
+ #error render ErrorResult.error(???, 1, "wrong parameter") and return
+ #end
+ respond_to do |format|
+ format.html { render :xml => @package_kit.to_xml( :root => "packagekit",
:dasherize => false ) }
+ format.xml { render :xml => @package_kit.to_xml( :root => "packagekit",
:dasherize => false ) }
+ format.json { render :json => @package_kit.to_json( :root =>
"packagekit", :dasherize => false ) }
end
end

diff --git a/plugins/patches/app/models/package.rb
b/plugins/patches/app/models/package.rb
index 3ccb3bf..dc5c2ae 100644
--- a/plugins/patches/app/models/package.rb
+++ b/plugins/patches/app/models/package.rb
@@ -1,88 +1,44 @@
-require "dbus"
-require 'socket'
-require 'thread'
+require 'policykit'

-# 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
+class Package < Policykit

attr_accessor :resolvable_id,
:name,
:version

- def initialize()
-
+=begin
+ def initialize(attributes)
+ attributes.each do |key, value|
+ instance_variable_set("@#{key}", value)
+ end
end
-
+=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.package do
+ xml.tag!(:resolvable_id, @resolvable_id )
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
+ def self.find(what)
+ if what == :installed
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|
+ self.execute("GetPackages", what.to_s, "Package") { |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 = Package.new(:resolvable_id => line2,
+ :name => columns[0],
+ :version => columns[1]
+ )
+ # :arch => columns[2],
+ # :repo => columns[3],
+ # :summary => line3 )
+ package_list << package
+ }
package_list
+ end
end
end
diff --git a/plugins/patches/app/models/patch.rb
b/plugins/patches/app/models/patch.rb
index c36711d..3659bbb 100644
--- a/plugins/patches/app/models/patch.rb
+++ b/plugins/patches/app/models/patch.rb
@@ -1,6 +1,7 @@
-require "dbus"
-require 'socket'
-require 'thread'
+#require "dbus"
+#require 'socket'
+#require 'thread'
+require 'policykit'

# Used to stop DBus::Main loop
class PKErrorException < Exception; end
@@ -8,7 +9,7 @@ class PKErrorException < Exception; end
class PKFinishedException < Exception; end

# Model for patches available via package kit
-class Patch
+class Patch < Policykit

attr_accessor :resolvable_id,
:kind,
@@ -35,13 +36,6 @@ class Patch
* 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_xml( options = {} )
xml = options[:builder] ||= Builder::XmlMarkup.new(options)
xml.instruct! unless options[:skip_instruct]
@@ -49,6 +43,7 @@ class Patch
xml.patch_update do
xml.tag!(:id, id )
xml.tag!(:resolvable_id, @resolvable_id, {:type => "integer"} )
+ # Patch.find(212)
xml.tag!(:kind, @kind )
xml.tag!(:name, @name )
xml.tag!(:arch, @arch )
@@ -57,31 +52,13 @@ class Patch
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.find(what)
if what == :available
- begin
- 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"
-
- obj_tid.on_signal("Package") do |line1,line2,line3|
+ patch_updates = Array.new
+ self.execute("GetUpdates", "NONE", "Package") { |line1,line2,line3|
columns = line2.split ";"
update = Patch.new(:resolvable_id => columns[1],
:kind => line1,
@@ -90,35 +67,8 @@ class Patch
:repo => columns[3],
:summary => line3 )
patch_updates << update
- end
-
- obj_tid.on_signal("Error") do |u1,u2|
- raise PKErrorException
- end
- obj_tid.on_signal("Finished") do |u1,u2|
- raise PKFinishedException
- end
-
- obj_tid_with_iface.GetUpdates("NONE")
-
- if patch_updates.empty?
- loop = DBus::Main.new
- loop << system_bus
- begin
- loop.run
- rescue PKErrorException
- rescue PKFinishedException
- end
- end
-
- obj_with_iface.SuggestDaemonQuit
- return patch_updates
- rescue Exception #packagekit blocked?
- return -1
- end
- else
- # try to find by id
- self.find(:available).find { |p| p.resolvable_id.to_s == what.to_s }
+ }
+ return patch_updates
end
end

diff --git a/plugins/patches/app/models/policykit.rb
b/plugins/patches/app/models/policykit.rb
new file mode 100644
index 0000000..f5bad05
--- /dev/null
+++ b/plugins/patches/app/models/policykit.rb
@@ -0,0 +1,112 @@
+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 Policykit
+
+ attr_accessor :resolvable_id,
+ :kind,
+ :name,
+ :arch,
+ :repo,
+ :summary
+ def id
+ @resolvable_id
+ end
+
+ def id=(id_val)
+ @resolvable_id = id_val
+ end
+
+ # returns the modification time of
+ # the patch status, which you can use
+ # for cache policy purposes
+ def self.mtime
+ # we look for the most recent (max) modification time
+ # of either the package database or libzypp cache files
+ [ File.stat("/var/lib/rpm/Packages").mtime,
+ File.stat("/var/cache/zypp/solv").mtime,
+ * 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"
+
+ obj_tid.on_signal(signal.to_s) do |line1,line2,line3|
block.call(line1,line2,line3) end
+
+ obj_tid.on_signal("Error") do |u1,u2|
+ raise PKErrorException
+ end
+ obj_tid.on_signal("Finished") do |u1,u2|
+ raise PKFinishedException
+ end
+
+ 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
+ rescue PKFinishedException
+ end
+ end
+
+ obj_with_iface.SuggestDaemonQuit
+ return patch_updates
+ end
+
+ # installs this
+ def install
+ self.class.install(id)
+ end
+
+ # Patch.install(patch)
+ # Patch.install(id)
+ def self.install(patch)
+ if patch.is_a?(Patch)
+ update_id =
"#{patch.name};#{patch.resolvable_id};#{patch.arch};#{@patch.repo}"
+ Rails.logger.debug "Install Update: #{update_id}"
+ self.package_kit_install(update_id)
+ else
+ # if is not an object, assume it is an id
+ patch_id = patch
+ patch = Patch.find(patch_id)
+ raise "Can't install update #{patch_id} because it does not exist" if
patch.nil? or not patch.is_a?(Patch)
+ self.install(patch)
+ end
+ 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