Module: Workflow::Data
- Defined in:
- lib/rbbt/workflow/util/data.rb
Defined Under Namespace
Classes: DataNotFound
Instance Method Summary collapse
- #data(name, options = {}, &block) ⇒ Object
- #data_dir(directory) ⇒ Object
- #data_task(name, workflow, oname, *rest, &block) ⇒ Object
- #get_datadir(clean_name) ⇒ Object
- #get_file(clean_name, type = nil, extension = nil) ⇒ Object
Instance Method Details
#data(name, options = {}, &block) ⇒ Object
99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 |
# File 'lib/rbbt/workflow/util/data.rb', line 99 def data(name, = {}, &block) dep do |jobname, , dependencies| if block_given? block.call jobname, .merge(), dependencies else begin path = get_file jobname, name, [:extension] job = Step.new path job.task_name = name job.result_type = [:result_type] || [:type] || [:extension] job rescue DataNotFound {:task => name, :options => , :jobname => jobname} end end end end |
#data_dir(directory) ⇒ Object
8 9 10 |
# File 'lib/rbbt/workflow/util/data.rb', line 8 def data_dir(directory) @@data_directory = directory end |
#data_task(name, workflow, oname, *rest, &block) ⇒ Object
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 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 |
# File 'lib/rbbt/workflow/util/data.rb', line 43 def data_task(name, workflow, oname, *rest, &block) dep_task(name, workflow, oname, *rest) do |jobname, ,dependencies| begin task_info = workflow.nil? ? nil : workflow.task_info(oname) [:extension] ||= task_info[:extension] path = get_file jobname, name, [:extension] job = Step.new path job.task_name = name job.result_type = [:result_type] || [:type] || [:extension] job rescue DataNotFound end next job if job = {} = .merge(Workflow.load_inputs(File.join(@@data_directory,"options"), task_info[:inputs], task_info[:input_types])) begin = .merge(Workflow.load_inputs(get_file(jobname, :options), task_info[:inputs], task_info[:input_types])) rescue DataNotFound end begin = .merge(Workflow.load_inputs(get_datadir(jobname)., task_info[:inputs], task_info[:input_types])) rescue DataNotFound end begin task_info = workflow.nil? ? nil : workflow.task_info(oname) = block.call get_datadir(jobname), , task_info rescue Log.exception $! end if block_given? case when Step next when Hash if .include?(:inputs) = .merge() workflow = [:workflow] if [:workflow] oname = [:task] if [:task] inputs = .merge([:inputs]) else inputs = .merge() end {:workflow => workflow, :task => oname, :jobname => jobname, :inputs => inputs} else raise "Cannot understand data_options: #{}" end end end |
#get_datadir(clean_name) ⇒ Object
12 13 14 15 16 17 18 19 20 |
# File 'lib/rbbt/workflow/util/data.rb', line 12 def get_datadir(clean_name) data_dir = File.join(@@data_directory, clean_name) raise DataNotFound, "Data dir not found for #{clean_name} in #{@@data_directory}" unless File.directory?(data_dir) if Path === @@data_directory @@data_directory.annotate data_dir else Path.setup(data_dir) end end |
#get_file(clean_name, type = nil, extension = nil) ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/rbbt/workflow/util/data.rb', line 22 def get_file(clean_name, type = nil, extension = nil) begin extension = nil if String === extension && extension.empty? file1 = File.join(@@data_directory, type.to_s, (extension.nil? ? clean_name.to_s : clean_name.to_s + ".#{extension}")) file2 = File.join(@@data_directory, clean_name.to_s, (extension.nil? ? type.to_s : type.to_s + ".#{extension}")) if Open.exists?(file1) data_file = file1 elsif Open.exists?(file2) data_file = file2 else raise DataNotFound, "Data type #{type} not found for #{clean_name} in #{@@data_directory}" end end if Path === @@data_directory @@data_directory.annotate data_file else Path.setup(data_file) end end |