Mailinglist Archive: yast-commit (2114 mails)

< Previous Next >
[yast-commit] <rest-service> jr_ntp : some test and refactored basesystem
  • From: Martin Kudlvasr <mkudlvasr@xxxxxxx>
  • Date: Thu, 20 Aug 2009 14:57:42 +0200
  • Message-id: <E1Mpkq3-0004gL-49@xxxxxxxxxxxxxxxx>
ref: refs/heads/jr_ntp
commit 00430905c303f799ece041b50dcecf7235e6db1c
Author: Martin Kudlvasr <mkudlvasr@xxxxxxx>
Date: Thu Aug 20 14:57:42 2009 +0200

some test and refactored basesystem
---
plugins/basesystem/app/models/basesystem.rb | 78 ++++++++++++++++-------
plugins/basesystem/test/unit/basesystem_test.rb | 2 +-
2 files changed, 56 insertions(+), 24 deletions(-)

diff --git a/plugins/basesystem/app/models/basesystem.rb
b/plugins/basesystem/app/models/basesystem.rb
index 8eb27f5..4d372a5 100644
--- a/plugins/basesystem/app/models/basesystem.rb
+++ b/plugins/basesystem/app/models/basesystem.rb
@@ -18,42 +18,69 @@ class Basesystem
#Gets instance of Basesystem with initialized steps queue.
def initialize
@steps = Array.new
+ @current = nil
#load steps configuration
fh = File.new(STEPS_FILE, "r")
- while (line = fh.gets)
- steps.push(line.chomp)
- end
+ # file => read lines => remove line separators => only non-blank
+ fh.lines.collect { |line| chomp line }.delete_if { |line| length line == 0
}
fh.close
end

- #Gets instance of Basesystem with initialized steps queue and current step
- def Basesystem.find
- ret = Basesystem.new
- unless File.exist?(CURRENT_STEP_FILE)
- ret.current = ret.steps.empty? ? END_STRING : ret.steps[0]
+ 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")
- ret.current = fh.gets
+ @current = fh.gets
fh.close
- if ret.steps.include(ret.current) #invalid step
- Rails.logger.warn "invalid step in current"
- ret.current = END_STRING
- end
+ else
+ @current = nil
+ end
+ end
+
+ def save_current_step
+ fh = File.new(CURRENT_STEP_FILE, "w")
+ fh << @current
+ fh.close
+ end
+
+ def next_step
+ if current_step_valid?
+ @current = @steps[@steps.index(@current)+1] or END_STRING
end
- Rails.logger.info "Current step is set to #{ret.current}"
- return ret
+ 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
+ base
end

#stores to system Basesystem settings
- def save
- #check if current is valid
- unless @steps.include?(@current) or @current == END_STRING
- #invalid current value
+ #goes to the next step
+ def step_completed
+ unless current_step_valid?
return false
end
- cur = File.new(CURRENT_STEP_FILE, "w")
- cur.puts @current
- cur.close
+ next_step
+ save_current_step
end

#serialize part of Basesystem to xml
@@ -62,7 +89,12 @@ class Basesystem
xml.instruct! unless options[:skip_instruct]

xml.basesystem do
- xml.tag!(:current, @current)
+ xml.current_step @current
+ xml.setup_steps({:type => "array"}) do
+ @steps.each do |step|
+ xml.setup_step step
+ end
+ end
end
end

diff --git a/plugins/basesystem/test/unit/basesystem_test.rb
b/plugins/basesystem/test/unit/basesystem_test.rb
index 5adf811..bbdf255 100644
--- a/plugins/basesystem/test/unit/basesystem_test.rb
+++ b/plugins/basesystem/test/unit/basesystem_test.rb
@@ -31,7 +31,7 @@ class BasesystemTest < Test::Unit::TestCase
@basesystem.current = @test_steps[0]
@basesystem.save
@basesystem = Basesystem.find
- assert_equal(@test_steps[0], @basesystem.current)
+ assert_equal((@test_steps[1] or END_STRING), @basesystem.current)
# test for save fail on invalid current step
@basesystem.current = "ridiculous"
assert(false, @basesystem.save)
--
To unsubscribe, e-mail: yast-commit+unsubscribe@xxxxxxxxxxxx
For additional commands, e-mail: yast-commit+help@xxxxxxxxxxxx

< Previous Next >
This Thread
  • No further messages