Mailinglist Archive: yast-commit (1771 mails)

< Previous Next >
[yast-commit] <rest-service> network : services plugin - code cleanup
  • From: Ladislav Slezak <lslezak@xxxxxxxxxx>
  • Date: Fri, 21 Aug 2009 09:48:03 +0200
  • Message-id: <E1MiTqG-0006X8-52@xxxxxxxxxxxxxxxx>
ref: refs/heads/network
commit 9937f40584afdc939a8948845d8fb9da78bb423d
Author: Ladislav Slezak <lslezak@xxxxxxxxxx>
Date: Fri Aug 21 09:48:03 2009 +0200

services plugin - code cleanup
---
.../app/controllers/services_controller.rb | 1 -
plugins/services/app/models/service.rb | 28 +++++++------------
.../test/functional/services_controller_test.rb | 6 +---
3 files changed, 12 insertions(+), 23 deletions(-)

diff --git a/plugins/services/app/controllers/services_controller.rb
b/plugins/services/app/controllers/services_controller.rb
index 5b1b79e..c3d5b51 100644
--- a/plugins/services/app/controllers/services_controller.rb
+++ b/plugins/services/app/controllers/services_controller.rb
@@ -26,7 +26,6 @@ class ServicesController < ApplicationController
render ErrorResult.error(404, 106, "no such service") and return
end

- ret = {}
begin
ret = @service.save(params[:execute])
rescue Exception => e
diff --git a/plugins/services/app/models/service.rb
b/plugins/services/app/models/service.rb
index 2796314..8e70ceb 100644
--- a/plugins/services/app/models/service.rb
+++ b/plugins/services/app/models/service.rb
@@ -7,9 +7,9 @@ class Service
attr_accessor :name
attr_accessor_with_default :status, 0

- def initialize
+ def initialize(name)
+ @name = name
end
-

# services = Service.find_all
def self.find_all(params)
@@ -19,8 +19,7 @@ class Service
begin
cfg = YaST::ConfigFile.new(:custom_services)
cfg.each do |name, s|
- service = Service.new
- service.name = name
+ service = Service.new(name)
Rails.logger.debug "custom service: #{service.inspect}"
services << service
end
@@ -35,8 +34,7 @@ class Service
raise "Can't get services list"
else
yapi_ret.each do |s|
- service = Service.new
- service.name = s
+ service = Service.new(s)
# read status on demand, it takes much time
Rails.logger.debug "service: #{service.inspect}"
services << service
@@ -48,33 +46,27 @@ class Service

# load the status of the service
def self.find(id)
-
# actually we do not need to read the real status now
- service = Service.new
- service.name = id
- service
+ Service.new(id)
end


# execute a service command (start, stop, ...)
def save(cmd)

- custom_service = {}
begin
cfg = YaST::ConfigFile.new(:custom_services)
- custom_service = cfg[self.name] if cfg.has_key?(self.name)
+ custom_service = cfg[self.name]
rescue Exception => e
Rails.logger.error "looking for service #{self.name}: #{e}"
return { :stderr => e }
end

- command = ""
- command = custom_service[cmd] unless custom_service.nil?
-
- if command.nil? or command.empty?
+ if custom_service.blank?
Rails.logger.debug "no custom command found, calling YaPI..."
ret = YastService.Call("YaPI::SERVICES::Execute", self.name, cmd)
else
+ command = custom_service[cmd]
Rails.logger.debug "Service commmand #{command}"
ret = Scr.instance.execute([command])
end
@@ -89,8 +81,8 @@ class Service
xml.instruct! unless options[:skip_instruct]

xml.service do
- xml.tag!(:name, name )
- xml.tag!(:status, status, {:type => "integer"} )
+ xml.name name
+ xml.status status, {:type => "integer"}
end
end

diff --git a/plugins/services/test/functional/services_controller_test.rb
b/plugins/services/test/functional/services_controller_test.rb
index 4d430ab..cfc04ff 100644
--- a/plugins/services/test/functional/services_controller_test.rb
+++ b/plugins/services/test/functional/services_controller_test.rb
@@ -13,12 +13,10 @@ class ServicesControllerTest < ActionController::TestCase
# http://railsforum.com/viewtopic.php?id=1719
@request.session[:account_id] = 1 # defined in fixtures

- s1 = Service.new
- s1.name = "foo"
+ s1 = Service.new("foo")
s1.status = 0

- s2 = Service.new
- s2.name = "cron"
+ s2 = Service.new("cron")
s2.status = 1

Service.stubs(:find_all).returns([s1, s2])
--
To unsubscribe, e-mail: yast-commit+unsubscribe@xxxxxxxxxxxx
For additional commands, e-mail: yast-commit+help@xxxxxxxxxxxx

< Previous Next >
This Thread
  • No further messages