Class: WadrcBcpScripts::BasicTask
- Inherits:
-
Object
- Object
- WadrcBcpScripts::BasicTask
- Defined in:
- lib/wadrc-bcp-scripts/basic_task.rb
Overview
Enviornment and configuration checks common between processing streams.
Direct Known Subclasses
Instance Attribute Summary collapse
-
#config ⇒ Object
Task Configuration Options Hash.
Instance Method Summary collapse
-
#check_setup(input_directory = @input_directory, output_directory = @output_directory) ⇒ Object
Basic IO Directory Checks.
-
#config_requires(*args) ⇒ Object
Check for required keys in the @config hash.
- #ensure_file_exists(*args) ⇒ Object
-
#environment_requires(*args) ⇒ Object
Check for some required helper applications that must be installed on the system prior to use.
Instance Attribute Details
#config ⇒ Object
Task Configuration Options Hash
9 10 11 |
# File 'lib/wadrc-bcp-scripts/basic_task.rb', line 9 def config @config end |
Instance Method Details
#check_setup(input_directory = @input_directory, output_directory = @output_directory) ⇒ Object
Basic IO Directory Checks
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 |
# File 'lib/wadrc-bcp-scripts/basic_task.rb', line 64 def check_setup(input_directory = @input_directory, output_directory = @output_directory) # Check Input Directory raise(IOError, "#{input_directory}: not found.") unless File.directory?(input_directory) # Check Gradient Tensor Files ensure_file_exists @config[:bvectors_file], @config[:bvalues_file] unless @config[:dry_run] # Check Working Input Directory if @config[:force_sandbox] path = Pathname.new(input_directory) # @working_input_directory = path.sandbox(input_directory) @working_input_directory = path.prep_mise(input_directory + '/', Dir.mktmpdir + '/') @working_input_directory = File.join(@working_input_directory, File.basename(input_directory)) else @working_input_directory = input_directory end # Check Output Directory and force cleanup if necessary. colliding_files = Dir.glob(File.join(output_directory, @file_prefix) + '*') puts colliding_files if File.directory?(output_directory) && colliding_files.empty? == false if @config[:force_overwrite] then colliding_files.each {|file| puts "Removing #{file}..."; File.delete(file) } else raise(IOError, "#{output_directory} already exists. Set force_overwite in your spec file to overwrite the directory.") end end FileUtils.mkdir_p(output_directory) else # Use the real input directory if the working directory was not assigned # (ie during dry run) @working_input_directory = input_directory end # Setup Logging logfile = File.join(output_directory, "#{File.basename(input_directory)}_#{today}.log") if File.writable?(output_directory) && ! @config[:dry_run] $LOG = Logger.new(logfile) else $LOG = Logger.new(STDOUT) end # Switch CWD (default output location for rotbvecs script) @cwd = Dir.pwd Dir.chdir(output_directory) unless @config[:dry_run] end |
#config_requires(*args) ⇒ Object
Check for required keys in the @config hash.
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/wadrc-bcp-scripts/basic_task.rb', line 41 def config_requires(*args) missing_keys = [] args.each do |required_key| unless @config.has_key?(required_key) missing_keys << required_key end end unless missing_keys.size == 0 error = " Warning: Misconfiguration detected. You are missing the following keys from your spec file: - #{missing_keys.join(', ')} Please install the missing programs, run this script from a properly configured workstation, or use the dry_run option to output your script to the terminal.\n " puts error raise(ScriptError, "Missing Keys: #{missing_keys.join(", ")}") end end |
#ensure_file_exists(*args) ⇒ Object
110 111 112 113 114 115 |
# File 'lib/wadrc-bcp-scripts/basic_task.rb', line 110 def ensure_file_exists(*args) args.each do |file| raise(IOError, "#{file} not found.") unless File.exists?(file) end end |
#environment_requires(*args) ⇒ Object
Check for some required helper applications that must be installed on the system prior to use. It returns true if there are no missing processing program binaries, otherwise it puts them to the screen and raises a ScriptError.
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/wadrc-bcp-scripts/basic_task.rb', line 15 def environment_requires(*args) missing_binaries = [] args.each do |required_binary| if system("which #{required_binary.to_s} > /dev/null") == false missing_binaries << required_binary end end begin unless missing_binaries.size == 0 error = " Warning: The following processing tools weren't found on your system. - #{missing_binaries.join(', ')} Please install the missing programs, run this script from a properly configured workstation, or use the dry_run option to output your script to the terminal.\n " puts error raise(ScriptError, "Missing #{missing_binaries.join(", ")}") end end return end |