#!/usr/bin/env ruby # encoding: utf-8 # Version = '20190425-141759' require 'sushi_fabric' opt = OptionParser.new do |o| o.banner = <<-EOT Usage: #{File.basename(__FILE__)} --class [SushiApp class] [options] \t(Either --dataset_id or --dataset_tsv is \e[31mrequired\e[0m) EOT o.on(:class_name, '-c class_name', '--class', "SushiApp class name (\e[31mrequired\e[0m)") o.on(:dataset_id, '-i dataset_id', '--dataset_id', Integer, 'DataSet ID in Sushi DB') o.on(:dataset_tsv, '-d dataset_tsv', '--dataset', String, 'DataSet file (.tsv) (This option is prior to dataset_id option)') o.on(:dataset_name, '-s dataset_name', '--dataset_name', String, 'DataSet name in Sushi (This will be used with --dataset option, default: tsv file base name)') o.on(:parameterset_tsv, '-m parameterset_tsv', '--parameterset', String, 'Parameterset file (.tsv)') o.on(:run_mode, '-r', '--run', 'Real run mode. without this option, it runs with test run mode which checks only DataSet and Parameters and no submittion') o.on(:project, '1001', '-p project', '--project', String, 'Project Number (default: 1001)') o.on(:user, 'sushi_lover', '-u user', '--user', String, 'Submit user (default: sushi_lover)') o.on(:load_path, '-I load_path', '--load_path', 'Add path where SushiApp class is located (default: ./lib)') o.on(:next_dataset_name, '-n next_dataset_name', '--next_dataset_name', 'Next DataSet Name (default: Analysis_Category+ID+Date )') o.on(:off_bfab, '-f', '--off_bfab', 'Do NOT register the dataset in BFabric (default: false, namely register in BFabric)') o.on(:mango_run_name, '-g mango_run_name', '--mango_run_name', 'ManGO RunName_oBFabricID') o.on(:input_dataset_application, '-a bfabric_application_number', '--input_dataset_application', 'BFabric Application Number for input DataSet') o.on(:next_dataset_application, '-A bfabric_application_number', '--next_dataset_application', 'BFabric Application Number for next DataSet') o.parse!(ARGV) end opt.project = 'p' + opt.project if File.exist?('lib') $: << 'lib' end if opt.load_path opt.load_path.split(':').each do |path| $: << path end end unless opt.class_name puts warn "\e[31mERROR\e[0m: --class is required" puts warn opt.help exit end unless opt.dataset_id or opt.dataset_tsv puts warn "\e[31mERROR\e[0m: Either --dataset_id or --dataset_tsv is required" puts print opt.help exit end begin require opt.class_name klass = eval(opt.class_name) usecase = klass.new rescue #NameError, LoadError # uninitialized constant warn "" warn "\e[31mERROR\e[0m: The class #{opt.class_name} cannot be loaded. Add path with -I option." warn "" warn "Current library load path(s):" puts $:.map{|dir| "\t"+dir} end usecase.project = opt.project usecase.user = opt.user usecase.dataset_sushi_id = opt.dataset_id usecase.dataset_tsv_file = opt.dataset_tsv usecase.parameterset_tsv_file = opt.parameterset_tsv if opt.off_bfab usecase.off_bfabric_registration = opt.off_bfab end if opt.dataset_name usecase.dataset_name = opt.dataset_name end if opt.next_dataset_name usecase.next_dataset_name = opt.next_dataset_name end if opt.mango_run_name usecase.mango_run_name = opt.mango_run_name end if opt.input_dataset_application usecase.input_dataset_bfabric_application_number = opt.input_dataset_application end if opt.next_dataset_application usecase.next_dataset_bfabric_application_number = opt.next_dataset_application end if opt.run_mode usecase.run else usecase.test_run end