lib/advance.rb in advance-0.3.18 vs lib/advance.rb in advance-0.4.1
- old
+ new
@@ -78,12 +78,13 @@
if $step.nil?
raise "capture_column_names_from_csv cannot be the first step"
end
if File.exist?(".meta")
- read_column_names_from_meta
- return
+ if read_column_names_from_meta
+ return
+ end
end
previous_dir_path = get_previous_dir_path
input_file_path = previous_file_path(previous_dir_path)
CSV.foreach(input_file_path, :headers => true) do |row|
@@ -96,14 +97,15 @@
meta = JSON.parse(File.read(".meta"))
meta["runs"].each do |run|
run.each do |step|
if step["columns"]
$column_names = step["columns"].map(&:to_sym)
- return
+ return true
end
end
end
+ false
end
def advance(processing_mode, label, command)
$redo_mode ||= :checking
$step ||= 0
@@ -135,10 +137,15 @@
end
do_command_wo_log "rm -rf #{previous_dir_path}"
end
end
+ def pipeline(pipeline_path)
+ expanded_path = File.expand_path(pipeline_path)
+ load expanded_path
+ end
+
def count_files(dir)
file_count = 0
Find.find(dir) do |path|
next if File.directory?(path)
next if File.basename(path) == "log"
@@ -192,18 +199,19 @@
dirs.find { |d| d =~ /^#{dir_prefix}/ }
end
def single(command, previous_dir_path, dir_name)
work_in_sub_dir(dir_name) do
- input_file_path = previous_file_path(previous_dir_path)
- basename = File.basename(input_file_path)
- root_file_name = basename.gsub(%r(\.[^.]+$), '')
command.gsub!("{input_dir}", previous_dir_path)
- command.gsub!("{input_file}", input_file_path)
- command.gsub!("{file_name}", basename)
- command.gsub!("{file_name_without_extension}", root_file_name)
-
+ input_file_path = previous_file_path(previous_dir_path)
+ if input_file_path
+ basename = File.basename(input_file_path)
+ root_file_name = basename.gsub(%r(\.[^.]+$), '')
+ command.gsub!("{input_file}", input_file_path)
+ command.gsub!("{file_name}", basename)
+ command.gsub!("{file_name_without_extension}", root_file_name)
+ end
do_command command
end
end
def multi(command, previous_dir_path, dir_name)
@@ -299,10 +307,10 @@
File.join(dir_path, "{file}")
end
end
def do_command(command, feedback = true)
- puts "#{YELLOW}#{command}#{RESET} " if feedback
+ puts "#{YELLOW}#{command}#{RESET} " #if feedback
start_time = Time.now
stdout, stderr, status = Open3.capture3(command)
elapsed_time = Time.now - start_time
File.open("log", "w") do |f|
f.puts "%%% command: >#{command}<"