lib/advance.rb in advance-0.2.1 vs lib/advance.rb in advance-0.3.0
- old
+ new
@@ -29,15 +29,27 @@
$step += 1
dir_prefix = step_dir_prefix($step)
dir_name = "#{dir_prefix}_#{label}"
puts "#{CYAN}advance #{$step} #{label}#{WHITE}... #{RESET}"
- return if $redo_mode == :checking && Dir.exist?(dir_name)
- clean_previous_step_dirs(dir_prefix)
+ if $redo_mode != :checking || !(File.exist?(dir_name) || File.exist?(dir_name + '.tgz'))
+ clean_previous_step_dirs(dir_prefix)
- send(processing_mode, command, previous_dir_path, dir_name)
+ if previous_dir_path =~ /\.tgz$/
+ do_command_wo_log "tar xzf #{previous_dir_path}"
+ end
+ previous_dir_path = previous_dir_path.gsub(/\.tgz$/, "")
+ send(processing_mode, command, previous_dir_path, dir_name)
+ end
+ previous_dir_path = previous_dir_path.gsub(/\.tgz$/, "")
+ if File.basename(previous_dir_path) =~ /^step_/
+ if !File.exist?("#{previous_dir_path}.tgz")
+ do_command_wo_log "tar czf #{previous_dir_path}.tgz #{File.basename(previous_dir_path)}"
+ end
+ do_command_wo_log "rm -rf #{previous_dir_path}"
+ end
end
def static(processing_mode, label, command)
$redo_mode ||= :checking
$step ||= 0
@@ -170,11 +182,11 @@
end
changed_dir_name
end
def previous_file_path(previous_dir_path)
- Find.find(previous_dir_path).reject { |p| FileTest.directory?(p) || File.basename(p) == "log" }.first
+ Find.find(previous_dir_path).reject {|p| File.basename(p) =~ %r(^\.) || FileTest.directory?(p) || File.basename(p) == "log"}.first
end
def file_path_template(dir_path, files)
file = files.first
file_path = File.join(dir_path, file)
@@ -199,9 +211,27 @@
f.puts "%%% stderr:"
f.puts stderr
end
if !status.success?
raise "step #{$step} failed with #{status}\n#{stderr}"
+ end
+ end
+
+ def do_command_wo_log(command, feedback = true)
+ puts "#{YELLOW}#{command}#{RESET} " if feedback
+ stdout, stderr, status = Open3.capture3(command)
+ if !status.success?
+ error_msg = [
+ "step #{$step} failed",
+ "%%% command: >#{command}<",
+ "%%% returned status: >#{status}<",
+ "%%% stdout:",
+ stdout,
+ "%%% stderr:",
+ stderr
+ ].join("\n")
+
+ raise error_msg
end
end
def ensure_bin_on_path
advance_path = File.dirname(__FILE__)