Mailinglist Archive: yast-commit (1771 mails)

< Previous Next >
[yast-commit] <rest-service> network : patch module: some code review
  • From: Bjoern Geuken <bgeuken@xxxxxxx>
  • Date: Fri, 21 Aug 2009 10:40:35 +0200
  • Message-id: <E1MiTqG-0006XU-EE@xxxxxxxxxxxxxxxx>
ref: refs/heads/network
commit ee6bd08817a588bacb806e329fdb9cba25fcb5c1
Author: Bjoern Geuken <bgeuken@xxxxxxx>
Date: Fri Aug 21 10:40:35 2009 +0200

patch module: some code review
---
.../patches/app/controllers/patches_controller.rb | 12 ++-
plugins/patches/app/models/patch.rb | 98 ++++++++++----------
2 files changed, 55 insertions(+), 55 deletions(-)

diff --git a/plugins/patches/app/controllers/patches_controller.rb
b/plugins/patches/app/controllers/patches_controller.rb
index ae082fd..e2512ac 100644
--- a/plugins/patches/app/controllers/patches_controller.rb
+++ b/plugins/patches/app/controllers/patches_controller.rb
@@ -3,10 +3,10 @@ require 'singleton'
class PatchesController < ApplicationController

before_filter :login_required
-
+
# always check permissions and cache expiration
# even if the result is already created and cached
- before_filter :check_read_permissions, :only => :index
+ before_filter :check_read_permissions, :only => {:index, :show}
before_filter :check_cache_status, :only => :index

# cache 'index' method result
@@ -45,14 +45,16 @@ class PatchesController < ApplicationController
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
+ end
end

# GET /patch_updates/1
# GET /patch_updates/1.xml
def show
- unless permission_check( "org.opensuse.yast.system.patches.read")
- render ErrorResult.error(403, 1, "no permission") and return
- end
@patch_update = Patch.find(params[:id])
if @patch_update.nil?
logger.error "Patch: #{params[:id]} not found."
diff --git a/plugins/patches/app/models/patch.rb
b/plugins/patches/app/models/patch.rb
index a956f75..c36711d 100644
--- a/plugins/patches/app/models/patch.rb
+++ b/plugins/patches/app/models/patch.rb
@@ -54,7 +54,7 @@ class Patch
xml.tag!(:arch, @arch )
xml.tag!(:repo, @repo )
xml.tag!(:summary, @summary )
- end
+ end
end

def to_json( options = {} )
@@ -67,57 +67,55 @@ class Patch
# Patch.find(212)
def self.find(what)
if what == :available
- 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"
-
- finished = false
- obj_tid.on_signal("Package") do |line1,line2,line3|
- columns = line2.split ";"
- update = Patch.new(:resolvable_id => columns[1],
- :kind => line1,
- :name => columns[0],
- :arch => columns[2],
- :repo => columns[3],
- :summary => line3 )
- patch_updates << update
- finished = true
- end
+ 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|
+ columns = line2.split ";"
+ update = Patch.new(:resolvable_id => columns[1],
+ :kind => line1,
+ :name => columns[0],
+ :arch => columns[2],
+ :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.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")
-
- unless finished
- loop = DBus::Main.new
- loop << system_bus
- begin
- loop.run
- rescue PKErrorException
- finished = true
- ok = false
- rescue PKFinishedException
- finished = true
+ 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
- end
-
- obj_with_iface.SuggestDaemonQuit

- return patch_updates
+ 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 }
@@ -144,7 +142,7 @@ class Patch
self.install(patch)
end
end
-
+
# install an update, based on the PackageKit
# id
def self.package_kit_install(pkkit_id)
@@ -190,5 +188,5 @@ class Patch
return ok
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