lib/advance.rb in advance-0.3.3 vs lib/advance.rb in advance-0.3.4
- old
+ new
@@ -174,18 +174,22 @@
puts latest_progress if last_progress != latest_progress
last_progress = latest_progress
end
TeamEffort.work(file_paths, $cores, progress_proc: progress_proc) do |file_path|
begin
+ path_relative_to_step_dir = File.dirname(file_path.gsub(%r(^#{previous_dir_path}/?), ""))
+ path_relative_to_step_dir = path_relative_to_step_dir == "." ? "" : path_relative_to_step_dir
basename = File.basename(file_path)
+ new_dir_name = path_relative_to_step_dir == "" ? basename : File.join(path_relative_to_step_dir, basename)
root_file_name = basename.gsub(%r(\.[^.]+$), '')
+ command.gsub!("{input_dir}", File.dirname(file_path))
command.gsub!("{input_file}", file_path)
command.gsub!("{file_name}", basename)
command.gsub!("{file_name_without_extension}", root_file_name)
puts "#{YELLOW}#{command}#{RESET}"
- work_in_sub_dir(basename) do
+ work_in_sub_dir(new_dir_name) do
do_command command, no_feedback
end
rescue
puts "%%%% error while processing >>#{file_path}<<"
raise
@@ -193,25 +197,28 @@
end
end
end
def work_in_sub_dir(dir_name)
+ starting_dir = FileUtils.pwd
stripped_dir_name = strip_extensions(dir_name)
if $redo_mode == :checking && Dir.exist?(stripped_dir_name)
return
end
$redo_mode = :replacing
- tmp_dir_name = "tmp_#{stripped_dir_name}"
- FileUtils.rm_rf tmp_dir_name
- FileUtils.mkdir_p tmp_dir_name
- FileUtils.cd tmp_dir_name
+ dirs = File.split(stripped_dir_name)
+ dirs[-1] = "tmp_#{dirs[-1]}"
+ tmp_dir = File.join(dirs)
+ FileUtils.rm_rf tmp_dir
+ FileUtils.mkdir_p tmp_dir
+ FileUtils.cd tmp_dir
yield
- FileUtils.cd ".."
- FileUtils.mv tmp_dir_name, stripped_dir_name
+ FileUtils.cd starting_dir
+ FileUtils.mv tmp_dir, stripped_dir_name
end
def strip_extensions(dir_name)
extensions = %w(
csv