lib/advance.rb in advance-0.4.6 vs lib/advance.rb in advance-0.4.7

- old
+ new

@@ -19,10 +19,22 @@ MAGENTA="\e[35m" RED="\e[31m" WHITE="\e[1;37m" YELLOW="\e[33m" + def env_is?(env_var_name, default) + case ENV[env_var_name] + when "true"; true + when "false"; false + when nil; default + else + puts "env variable #{env_var_name} should be 'true', 'false', or not present (defaults to '#{default}')" + puts "currently set to >#{ENV[env_var_name]}<" + false + end + end + def self.included(pipeline_module) $pipeline = caller_locations.first.path meta = if File.exist?(".meta") JSON.parse(File.read(".meta")) @@ -31,29 +43,10 @@ end last_run_number = meta["last_run_number"] ||= -1 $run_number = last_run_number + 1 $cores=`nproc`.to_i puts "Multi steps will use #{$cores} cores" - - $verbose_logging = case ENV["ADVANCE_VERBOSE_LOGGING"] - when "true"; true - when "false"; false - when nil; false - else - puts "env variable ADVANCE_VERBOSE_LOGGING should be 'true', 'false', or not present (defaults to 'false')" - puts "currently set to >#{ENV["ADVANCE_VERBOSE_LOGGING"]}<" - false - end - $save_history = case ENV["ADVANCE_SAVE_HISTORY"] - when "true"; true - when "false"; false - when nil; true - else - puts "env variable ADVANCE_SAVE_HISTORY should be 'true', 'false', or not present (defaults to 'true')" - puts "currently set to >#{ENV["ADVANCE_SAVE_HISTORY"]}<" - true - end end def update_meta(step_number, processing_mode, label, command, start_time, duration, file_count) meta = if File.exist?(".meta") @@ -138,11 +131,11 @@ duration = Time.now - start_time update_meta($step, processing_mode, label, command, start_time, duration, file_count) end previous_dir_path = previous_dir_path.gsub(/\.tgz$/, "") if File.basename(previous_dir_path) =~ /^step_/ - if $save_history && !File.exist?("#{previous_dir_path}.tgz") + if env_is?("ADVANCE_SAVE_HISTORY", true) && !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 @@ -241,12 +234,12 @@ 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} " if $verbose_logging + puts "#{YELLOW}#{command}#{RESET} " if env_is?("ADVANCE_VERBOSE_LOGGING", false) work_in_sub_dir(new_dir_name) do - do_command command, $verbose_logging + do_command command, env_is?("ADVANCE_VERBOSE_LOGGING", false) end rescue puts "%%%% error while processing >>#{file_path}<<" raise end