ref: refs/heads/jr_ntp commit f44635f0fd352a5bafbbf728c1e361c63c84a5d6 Author: Josef Reidinger <jreidinger@suse.cz> Date: Mon Aug 24 15:22:58 2009 +0200 update backend to new communication interface and use yaml config file --- .../app/controllers/basesystem_controller.rb | 5 +- plugins/basesystem/app/models/basesystem.rb | 84 +++----------------- plugins/basesystem/config/basesystemsteps.conf | 2 - plugins/basesystem/test/unit/basesystem_test.rb | 47 +++++------ 4 files changed, 38 insertions(+), 100 deletions(-) diff --git a/plugins/basesystem/app/controllers/basesystem_controller.rb b/plugins/basesystem/app/controllers/basesystem_controller.rb index dfee744..765d47b 100644 --- a/plugins/basesystem/app/controllers/basesystem_controller.rb +++ b/plugins/basesystem/app/controllers/basesystem_controller.rb @@ -7,11 +7,12 @@ class BasesystemController < ApplicationController def show @basesystem = Basesystem.find + logger.debug @basesystem.inspect end def update - @basesystem = Basesystem.find - @basesystem.finish + @basesystem = Basesystem.new + @basesystem.finish = params[:finish] @basesystem.save render :show end diff --git a/plugins/basesystem/app/models/basesystem.rb b/plugins/basesystem/app/models/basesystem.rb index 07b1b27..8ffd19e 100644 --- a/plugins/basesystem/app/models/basesystem.rb +++ b/plugins/basesystem/app/models/basesystem.rb @@ -1,97 +1,39 @@ # = Base system model # Provides access to basic system settings module queue. Provides and updates -# currently reached state in queue. +# if base system settings is already done. +require "yast/config_file" class Basesystem # steps needed by base system attr_accessor :steps - # current step to finish - attr_accessor :current + # Flag if base system configuration is finished + attr_accessor :finish # path to file which defines module queue - STEPS_FILE = File.join(File.dirname(__FILE__),"..","..","config","basesystemsteps.conf") + BASESYSTEM_CONF = :basesystem # path to file which store module then is next in queue or END_STRING if all steps is done - CURRENT_STEP_FILE = File.join(File.dirname(__FILE__),"..","..","var","currentstep") - # keyword that signalize finish of all steps - END_STRING = "FINISH" + FINISH_FILE = File.join(File.dirname(__FILE__),"..","..","var","finish") - def self.steps_file - STEPS_FILE - end - - def self.current_step_file - CURRENT_STEP_FILE - end - - def self.end_string - END_STRING - end #Gets instance of Basesystem with initialized steps queue. def initialize - @steps = Array.new - @current = "" - #load steps configuration - fh = File.new(STEPS_FILE, "r") - # file => read lines => remove line separators => only non-blank - @steps = fh.lines.collect { |line| line.chomp }.delete_if { |line| line.length == 0 } - fh.close + @steps = [] + @finish = false end #Gets instance of Basesystem with initialized steps queue and current step def Basesystem.find base = Basesystem.new - base.load_current_step - unless base.current_step_valid? - base.restart_setup - end - Rails.logger.info "Current step is set to #{base.current}" + base.finish = File.exist?(FINISH_FILE) + base.steps = YaST::ConfigFile.new(BASESYSTEM_CONF)["steps"] || [] return base end - def finish - @current = END_STRING - end - - def current_step_valid? - if @steps.include?(@current) or @current == END_STRING - true - else - Rails.logger.warn "Invalid step in current" - false - end - end - - def restart_setup - Rails.logger.warn "Restarting basic system setup" - # allow empty list of setup steps - @current = @steps[0] or END_STRING - end - - def load_current_step - if File.exist?(CURRENT_STEP_FILE) - fh = File.new(CURRENT_STEP_FILE,"r") - @current = fh.gets.chomp - fh.close - else - @current = @steps[0] - end - end - - def save_current_step - fh = File.new(CURRENT_STEP_FILE, "w") - fh << @current - fh.close - end - #stores to system Basesystem settings def save - #check if current is valid - if not current_step_valid? - #invalid current value - return false + if @finish + FileUtils.touch FINISH_FILE unless File.exist?(FINISH_FILE) end - save_current_step end #serialize part of Basesystem to xml @@ -100,7 +42,7 @@ class Basesystem xml.instruct! unless options[:skip_instruct] xml.basesystem do - xml.current @current + xml.finish(@finish,{:type => "boolean"}) xml.steps({:type => "array"}) do @steps.each do |step| diff --git a/plugins/basesystem/config/basesystemsteps.conf b/plugins/basesystem/config/basesystemsteps.conf deleted file mode 100644 index e55c710..0000000 --- a/plugins/basesystem/config/basesystemsteps.conf +++ /dev/null @@ -1,2 +0,0 @@ -systemtime -language diff --git a/plugins/basesystem/test/unit/basesystem_test.rb b/plugins/basesystem/test/unit/basesystem_test.rb index 62e0519..aa993a1 100644 --- a/plugins/basesystem/test/unit/basesystem_test.rb +++ b/plugins/basesystem/test/unit/basesystem_test.rb @@ -1,53 +1,50 @@ require File.expand_path(File.dirname(__FILE__) + "/../test_helper") +require "yast/config_file" class BasesystemTest < ActiveSupport::TestCase +YAML_CONTENT = <<EOF +steps: + - systemtime + - language +EOF + + TEST_STEPS = ["systemtime","language"] def setup - fh = File.new(Basesystem.steps_file, "r") - @test_steps = fh.lines.collect { |l| l.chomp}.delete_if{|l| l.length == 0} - fh.close + YaST::ConfigFile.stubs(:read_file).returns(YAML_CONTENT) @basesystem = Basesystem.find end def teardown - if File.exists?(Basesystem.current_step_file) - File.delete(Basesystem.current_step_file) + finish = Basesystem.const_get "FINISH_FILE" + if File.exist?(finish) + File.delete(finish) end end def test_steps @basesystem = Basesystem.find - assert_equal(@test_steps, @basesystem.steps) - end + assert_equal(TEST_STEPS, @basesystem.steps) + end - def test_current - assert_equal(@basesystem.current, @test_steps[0]) + def test_finish + @basesystem = Basesystem.find + assert !@basesystem.finish end def test_save - @basesystem.current = Basesystem.end_string + @basesystem.finish = true @basesystem.save @basesystem = Basesystem.find - assert_equal(Basesystem.end_string, @basesystem.current) - # test for save fail on invalid current step - @basesystem.current = "ridiculous" - assert !@basesystem.save - end - - def test_corrupted_current - fh = File.new(Basesystem.current_step_file, "w") - fh << "ridiculous" - fh.close - @basesystem = Basesystem.find - assert_equal(@test_steps[0], @basesystem.current) - end + assert @basesystem.finish + end def test_to_xml - assert_not_nil(@basesystem.to_xml) + assert_not_nil @basesystem.to_xml end def test_to_json - assert_not_nil(@basesystem.to_json) + assert_not_nil @basesystem.to_json end end -- To unsubscribe, e-mail: yast-commit+unsubscribe@opensuse.org For additional commands, e-mail: yast-commit+help@opensuse.org