Bjoern Geuken napsal(a):
> ref: refs/heads/master
> commit cddddcc11c0d9e7f04d9f2fca0ded04e50a71a45
> Author: Bjoern Geuken <[email protected]>
> Date: Fri Aug 28 16:45:34 2009 +0200
>
> packages module: compare installed packages with vendor list (on
> rest-service)
> ---
> .../patches/app/controllers/packages_controller.rb | 25
> ++++++++++++++++++++
> 1 files changed, 25 insertions(+), 0 deletions(-)
>
> diff --git a/plugins/patches/app/controllers/packages_controller.rb
> b/plugins/patches/app/controllers/packages_controller.rb
> index e3e9718..e2b46ca 100644
> --- a/plugins/patches/app/controllers/packages_controller.rb
> +++ b/plugins/patches/app/controllers/packages_controller.rb
> @@ -40,11 +40,36 @@ class PackagesController < ApplicationController
>
> public
>
> + def compare_lists(packages)
> + vendor_packages = Hash.new
> + # yml datei auslesen: ["packages"] => ["yast-core", "ruby-dbus", ...]
Hi,
Please write comments in english
> + package_list = Array.new
> + package_list << ["yast2-users", "3ddiag", "foo"]
> +
> + package_list.each {|pk_name|
> + packages.each {|p|
> + # package installed?
> + if p.name == pk_name
> + # store version and name
> + vendor_packages["package"] = {:name => "#{p.name}", :version =>
> "#{p.version}"}
> + end
> + }
> + unless vendor_packages.has_key? pk_name
> + vendor_packages["package"] = {"#{pk_name}" => "not installed"}
> + end
I don't understand what it should do, especially condition at unless as
you notime insert key that is pk_name. You always insert key "package"
which you overwrite.
I think you want do this:
package_list.each {|pk_name|
package = packages.find { |pkg| pkg.name == pk_name }
vendor_packages[pk_name] = package ? {:name => "#{package.name}",
:version => "#{package.version}"} : {"#{pk_name}" => "not installed"}
}
But I am not sure what is your goal, so maybe it can be done better
(especially marking uninstalled packages look little strange)
> + }
> + # puts vendor_packages.inspect
> + vendor_packages
> + end
> +
> # GET /patch_updates
> # GET /patch_updates.xml
> def index
> # note: permission check was performed in :before_filter
> @packages = Package.find(:installed)
> + if params[:filter] == "custom"
> + @packages = compare_lists(@packages)
This is really confusing as you change type of field. It was array of
packages and result is another hash.
> + end
> respond_to do |format|
> format.html { render :xml => @packages.to_xml( :root => "packages",
> :dasherize => false ) }
> format.xml { render :xml => @packages.to_xml( :root => "packages",
> :dasherize => false ) }
--
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]