#!/usr/bin/env ruby class CmdStop < Exception attr_accessor :exit_status def initialize(exit_status = 0) @exit_status = exit_status end end dev_dir = nil if _i = ARGV.index("--dev") dev_dir = ARGV[_i+1] ARGV.delete "--dev" ARGV.delete dev_dir end if dev_dir.nil? _s = nil ARGV.each_with_index do |s,i| if s.match(/^--dev(?:=(.*))?/) dev_dir = $1 _s = s next end end ARGV.delete _s if _s end if dev_dir Dir.glob(File.join(File.expand_path(dev_dir),'rbbt-*/lib')).each do |f| $LOAD_PATH.unshift f end end require 'rbbt' require 'rbbt/util/simpleopt' require 'rbbt/util/config' Log.nocolor = true if ARGV.include? "--nocolor" options = SOPT.setup < ... -a --arg1 --arg2='value' --arg3 'another-value' --log* #{Log.color :yellow, "Log level from 0 (debug) 6 (errors)"} --log_file* #{Log.color :yellow, "Divert all Rbbt logs from STDERR to the file"} --dev* #{Log.color :yellow, "Find development libraries in the directory specified"} -cd--command_dir* #{Log.color :yellow, "Directory from where to load command scripts"} --profile #{Log.color :yellow, "Profile execution"} --nocolor #{Log.color :yellow, "Disable colored output"} --nobar #{Log.color :yellow, "Disable progress report"} --nostream #{Log.color :yellow, "Disable persistance/job streaming"} --update_persist #{Log.color :yellow, "Update persisted TSV files if source has been updated"} --locate_file #{Log.color :yellow, "Report the location of the script instead of executing it"} --dump_mem* #{Log.color :yellow, "Dump strings in memory each second into file"} -nolock--no_lock_id #{Log.color :yellow, "Do not track lockfiles with ids (prevent stale file handlers for high-througput and high-concurrency)"} -ji--jobname_show_inputs #{Log.color :yellow, "Show inputs as part of the jobname in workflows instead of digesting them"} -ck--config_keys* #{Log.color :yellow, "Override some config keys"} EOF if options[:jobname_show_inputs] ENV["RBBT_INPUT_JOBNAME"] = "true" end locate = options.delete :locate_file if options[:log_file] Log.logfile(options[:log_file]) end Log.ignore_stderr do begin require "nokogiri" rescue end end if options[:log] Log.severity = options[:log].to_i else global_severity = Log.get_level(Rbbt.etc.log_severity.read.strip) if Rbbt.etc.log_severity.exists? if ENV["RBBT_LOG"] Log.severity = ENV["RBBT_LOG"].to_i else global_severity = Log.get_level(Rbbt.etc.log_severity.read.strip) if Rbbt.etc.log_severity.exists? Log.severity = global_severity.to_i if global_severity end end if options.delete(:no_lock_id) Misc.use_lock_id = false end if mem_dump = options.delete(:dump_mem) require 'rbbt/monitor' Rbbt.dump_memory(mem_dump, String) end if options[:config_keys] options[:config_keys].split(",").each do |config| if Misc.is_filename?(config) && File.exists?(config) Rbbt::Config.load_file(config) elsif Rbbt.etc.config_profile[config].exists? Rbbt::Config.load_file(Rbbt.etc.config_profile[config].find) else key, value, *tokens = config.split(/\s/) tokens = ['key:' << key << '::0'] if tokens.empty? tokens = tokens.collect do |tok| tok, _sep, prio = tok.partition("::") prio = "0" if prio.nil? or prio.empty? [tok, prio] * "::" end Rbbt::Config.set({key => value}, *tokens) end end end if options.delete(:update_persist) ENV["RBBT_UPDATE_TSV_PERSIST"] = "true" end if options.delete :nostream ENV["RBBT_NO_STREAM"] = "true" end if options.delete :nobar ENV["RBBT_NO_PROGRESS"] = "true" end if options[:command_dir] $rbbt_command_dir = Path.setup(options[:command_dir].dup) else $rbbt_command_dir = Rbbt.share.rbbt_commands end SOPT.description =< 10) end end exit exit_status