ref: refs/heads/master
commit f0eb552e73a146c85e3328f55c2296ce0f6336ab
Author: Jiri Suchomel
Date: Wed Aug 19 16:40:19 2009 +0200
using YaST::ConfigFile
---
plugins/services/app/models/service.rb | 33 +++++++++++++++----------------
1 files changed, 16 insertions(+), 17 deletions(-)
diff --git a/plugins/services/app/models/service.rb b/plugins/services/app/models/service.rb
index 7ce21c9..40bc3b2 100644
--- a/plugins/services/app/models/service.rb
+++ b/plugins/services/app/models/service.rb
@@ -1,20 +1,7 @@
require "scr"
require 'yast_service'
+require 'yast/config_file'
-# FIXME move to helper? fill class variable on initialize?
-# -> use some generic library for accessing vendor specific data
-def get_custom_services
-
- file = '/etc/YaST2/custom_services.yml';
- custom = {}
- if File.exists?(file)
- custom = YAML::load (File.open('/etc/YaST2/custom_services.yml'));
- custom = {} unless custom.is_a? Hash
- end
- custom
-end
-
-
class Service
attr_accessor :name
@@ -29,12 +16,17 @@ class Service
services = []
if params.has_key?("custom")
- get_custom_services().each do |name, s|
+ begin
+ cfg = YaST::ConfigFile.new(:custom_services)
+ cfg.each do |name, s|
service = Service.new
service.name = name
# TODO read the service status?
Rails.logger.debug "custom service: #{service.inspect}"
- services << service
+ services << service
+ end
+ rescue Exception => e
+ Rails.logger.error e
end
else
yapi_ret = YastService.Call("YaPI::SERVICES::Read")
@@ -67,7 +59,14 @@ class Service
# execute a service command (start, stop, ...)
def save(cmd)
- custom_service = get_custom_services[self.name]
+ custom_service = {}
+ begin
+ cfg = YaST::ConfigFile.new(:custom_services)
+ custom_service = cfg[self.name] if cfg.has_key?(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?
--
To unsubscribe, e-mail: yast-commit+unsubscribe@opensuse.org
For additional commands, e-mail: yast-commit+help@opensuse.org