Sha256: aa1bfc7e538f6f24629fa5fcba475fe6a57430fa57d741cbafd772b357758f20

Contents?: true

Size: 1.39 KB

Versions: 23

Compression:

Stored size: 1.39 KB

Contents

#!/usr/bin/env ruby
require 'optparse'
require 'ostruct'
require 'cgi'

options = OpenStruct.new

OptionParser.new do |opts|
  opts.banner = "USAGE: mandy-local my_script.rb local_input_file local_output_folder [options]"
  
  opts.on("-v", '--variables name=value', "Pass additional parameters to jobs") do |config|
    options.cmdenv = config
  end
  
  opts.on("-j", '--json {"key":"1 value"}', "Pass JSON encoded parameters to jobs") do |config|
    options.cmdenv = "json=#{CGI.escape(config)}"
  end
  
  opts.on_tail("-h", "--help", "Show this message") do
    puts opts
    exit
  end
end.parse!

exec('mandy-local -h') unless ARGV.size >= 3

require "fileutils"

def absolute_path(path)
  path =~ /^\// ? path : File.join(Dir.pwd, path)
end

def set_env(opts_string)
  opts_string.split(' ').each do |pair|
    key, value = pair.split("=")
    ENV[key] = value
  end
end

set_env(options.cmdenv) if options.cmdenv 
file   = absolute_path(ARGV[0])
input  = absolute_path(ARGV[1])
output_folder = FileUtils.mkdir_p(absolute_path(ARGV[2]))
require file

out = nil
Mandy::Job.jobs.each_with_index do |job, i|
  out = File.join(output_folder, "#{i+1}-#{job.name.downcase.gsub(/\W/, '-')}")
  puts "Running #{job.name}..."
  reduce_phase = job.reducer_defined? ? %(| sort | mandy-reduce #{file} "#{job.name}") : ''
  `cat #{input} | mandy-map #{file} "#{job.name}" #{reduce_phase} > #{out}`
  input = out
end

puts out

Version data entries

23 entries across 23 versions & 1 rubygems

Version Path
mandy-0.4.991 bin/mandy-local
mandy-0.4.99 bin/mandy-local
mandy-0.4.98 bin/mandy-local
mandy-0.4.97 bin/mandy-local
mandy-0.4.96 bin/mandy-local
mandy-0.4.95 bin/mandy-local
mandy-0.4.94 bin/mandy-local
mandy-0.4.93 bin/mandy-local
mandy-0.4.92 bin/mandy-local
mandy-0.4.91 bin/mandy-local
mandy-0.4.90 bin/mandy-local
mandy-0.4.89 bin/mandy-local
mandy-0.4.88 bin/mandy-local
mandy-0.4.87 bin/mandy-local
mandy-0.4.86 bin/mandy-local
mandy-0.4.83 bin/mandy-local
mandy-0.4.10 bin/mandy-local
mandy-0.4.81 bin/mandy-local
mandy-0.4.8 bin/mandy-local
mandy-0.4.7 bin/mandy-local