lib/org-converge/command.rb in org-converge-0.0.11 vs lib/org-converge/command.rb in org-converge-0.0.12

- old
+ new

@@ -40,10 +40,11 @@ end true rescue => e @logger.error e + @logger.error e.backtrace.join("\n") false end def converge! tangle! @@ -79,11 +80,11 @@ results = babel.tangle! rescue Orgmode::Babel::TangleError logger.error "Cannot converge because there were errors during tangle step".fg 'red' end - def run_blocks_chain! + def run_blocks_chain! # Chain the blocks by defining them as Rake::Tasks dynamically tasks = { } babel.tangle_runnable_blocks!(@run_dir) babel.ob.scripts.each do |key, script| @@ -91,12 +92,13 @@ next unless task_name task = Rake::Task.define_task task_name do with_running_engine do |engine| file = File.expand_path("#{@run_dir}/#{key}") - cmd = "#{script[:lang]} #{file}" - engine.register task_name, cmd, { :cwd => @root_dir, :logger => logger } + bin = determine_lang_bin(script) + cmd = "#{bin} #{file}" + run_procs(script, cmd, engine) end end tasks[task_name] = { :task => task, :script => script @@ -144,27 +146,28 @@ next unless script[:header][:name] display_name = script[:header][:name] with_running_engine do |engine| file = File.expand_path("#{@run_dir}/#{key}") - cmd = "#{script[:lang]} #{file}" - engine.register display_name, cmd, { :cwd => @root_dir, :logger => logger } + bin = determine_lang_bin(script) + cmd = "#{bin} #{file}" + run_procs(script, cmd) end end logger.info "Run has completed successfully.".fg 'green' end def run_blocks_in_parallel! @engine = OrgConverge::Engine.new(:logger => @logger, :babel => @babel) babel.tangle_runnable_blocks!(@run_dir) babel.ob.scripts.each do |key, script| - file = File.expand_path("#{@run_dir}/#{key}") - cmd = "#{script[:lang]} #{file}" - # Decision: Only run blocks which have a name next unless script[:header][:name] + file = File.expand_path("#{@run_dir}/#{key}") + bin = determine_lang_bin(script) + cmd = "#{bin} #{file}" run_procs(script, cmd) end logger.info "Running code blocks now! (#{babel.ob.scripts.count} runnable blocks found in total)" @engine.start logger.info "Run has completed successfully.".fg 'green' @@ -174,11 +177,12 @@ @engine = OrgConverge::Engine.new(:logger => @logger, :babel => @babel) babel.tangle_runnable_blocks!(@run_dir, :filter => @options['--name']) scripts = babel.ob.scripts.select {|k, h| h[:header][:name] =~ Regexp.new(@options['--name']) } scripts.each do |key, script| file = File.expand_path("#{@run_dir}/#{key}") - cmd = "#{script[:lang]} #{file}" + bin = determine_lang_bin(script) + cmd = "#{bin} #{file}" run_procs(script, cmd) end logger.info "Running code blocks now! (#{scripts.count} runnable blocks found in total)" @engine.start @@ -201,11 +205,12 @@ next unless script[:header][:name] display_name = script[:header][:name] with_running_engine do |engine| file = File.expand_path("#{@run_dir}/#{key}") - cmd = "#{script[:lang]} #{file}" + bin = determine_lang_bin(script) + cmd = "#{bin} #{file}" engine.register display_name, cmd, { :cwd => @root_dir, :logger => logger } end end logger.info "Run has completed successfully.".fg 'green' end @@ -236,11 +241,12 @@ next unless script[:header][:name] display_name = script[:header][:name] script_file = File.expand_path("#{@run_dir}/#{key}") results_file = File.expand_path("#{@results_dir}/#{key}") - cmd = "#{script[:lang]} #{script_file}" + bin = determine_lang_bin(script) + cmd = "#{bin} #{script_file}" with_running_engine(:runmode => 'spec', :results_dir => @results_dir) \ do |engine| engine.register display_name, cmd, { :cwd => @root_dir, @@ -333,19 +339,28 @@ puts "---------- script: #{index} to be run with: #{block[:header][:shebang]} --------------".fg 'green' puts block[:lines] end end - def run_procs(script, cmd) + def run_procs(script, cmd, engine=nil) + engine ||= @engine display_name = script[:header][:name] if script[:header][:procs] procs = script[:header][:procs].to_i - procs.times do |i| - proc_name = "#{display_name}-#{i}" - @engine.register proc_name, cmd, { :cwd => @root_dir, :logger => logger } + 1.upto(procs) do |i| + proc_name = "#{display_name}:#{i}" + engine.register proc_name, cmd, { :cwd => @root_dir, :logger => logger, :header => script[:header] } end else - @engine.register display_name, cmd, { :cwd => @root_dir, :logger => logger } + engine.register display_name, cmd, { :cwd => @root_dir, :logger => logger, :header => script[:header] } + end + end + + def determine_lang_bin(script) + if script[:header][:shebang] + script[:header][:shebang].gsub('#!', '') + else + script[:lang] end end end end