lib/jkr/cli.rb in jkr-0.1.0 vs lib/jkr/cli.rb in jkr-0.2.1

- old
+ new

@@ -41,17 +41,11 @@ puts "... done" end desc "list", "List executable plans" def list() - begin - @jkr_env = Jkr::Env.new(options[:directory]) - rescue Errno::ENOENT - puts(red("[ERROR] jkr dir not found at #{@options[:directory]}")) - puts(red(" Maybe you are in a wrong directory.")) - exit(false) - end + @jkr_env = create_env() plans = Dir.glob("#{@jkr_env.jkr_plan_dir}/*.plan").map do |plan_file_path| plan = Jkr::Plan.create_by_name(@jkr_env, File.basename(plan_file_path, ".plan")) [File.basename(plan_file_path, ".plan"), plan.title] end @@ -72,11 +66,11 @@ puts end desc "execute <plan> [<plan> ...]", "Execute plans" def execute(*plan_names) - @jkr_env = Jkr::Env.new(options[:directory]) + @jkr_env = create_env() if options[:debug] delete_files_on_error = false else delete_files_on_error = true @@ -87,23 +81,86 @@ plan = Jkr::Plan.create_by_name(@jkr_env, plan_name) Jkr::Trial.run(@jkr_env, plan, delete_files_on_error) end end - desc "analyze <result> [<result> ...]", "Run analysis script for executed results" + desc "resume [<result> ...]", "Resume in-progress execution" + def resume(*result_ids) + @jkr_env = create_env() + cur_result_id = Jkr::Env.find_result(Dir.pwd) + if cur_result_id + result_ids.push(cur_result_id) + end + + result_ids.each do |rid| + plan = Plan.create_by_result_id(@jkr_env, rid) + Jkr::Trial.resume(@jkr_env, plan) + end + end + + desc "analyze [<result> ...]", "Run analysis script for executed results" def analyze(*result_ids) - @jkr_env = Jkr::Env.new(options[:directory]) + @jkr_env = create_env() + # check if current dir is a result dir + cur_result_id = Jkr::Env.find_result(Dir.pwd) + if cur_result_id + result_ids.push(cur_result_id) + end + result_ids.each do |arg| Jkr::Analysis.analyze(@jkr_env, arg) end end + desc "query <result>", "Query interesting result" + def query(result_id = nil) + @jkr_env = create_env() + + if result_id == nil + # check if current dir is a result dir + cur_result_id = Jkr::Env.find_result(Dir.pwd) + if cur_result_id + result_id = cur_result_id + else + raise ArgumentError.new("Result ID must be specified.") + end + end + + result_dir = Dir.glob(sprintf("#{@jkr_env.jkr_result_dir}/%05d*", result_id.to_i)).first + + Dir.glob("#{result_dir}/[0-9][0-9][0-9][0-9][0-9]/metastore.msh").sort.each do |m| + metastore = Marshal.load(File.open(m)) + params = Marshal.load(File.open(File.expand_path("../params.msh", m))) + + disp = metastore[:vars].map do |var| + "#{var}: #{params[var].inspect}" + end.join(", ") + + puts "#{File.basename(File.dirname(m))} | #{disp}" + end + end + no_commands do def find_plan_file(plan_name) @jkr_env.plans.find do |plan_file_path| File.basename(plan_file_path) == plan_name + ".plan" end + end + + def create_env() + begin + if options[:directory] + return Jkr::Env.new(options[:directory]) + else + return Jkr::Env.new(Jkr::Env.find(Dir.pwd)) + end + rescue Errno::ENOENT + $stderr.puts(red("[ERROR] jkr dir not found at #{@options[:directory]}")) + $stderr.puts(red(" Maybe you are in a wrong directory.")) + exit(false) + end + end end end end # Jkr