Sha256: 477f667c7bb866c2560131f42ec49493b5107b1463cb55234d8a7e6bfb48ffd6

Contents?: true

Size: 1.96 KB

Versions: 17

Compression:

Stored size: 1.96 KB

Contents

#!/usr/bin/env ruby

require 'rbbt/workflow'

require 'rbbt-util'
require 'fileutils'
require 'rbbt/util/simpleopt'
require 'rbbt/workflow/step'
require 'rbbt/util/misc'

require 'rbbt-util'
require 'rbbt/util/simpleopt'

$0 = "rbbt #{$previous_commands*""} #{ File.basename(__FILE__) }" if $previous_commands

options = SOPT.setup <<EOF
Examine the provenance of a job result

$ rbbt workflow prov <job-result>

-h--help Help
EOF

SOPT.usage if options[:help]

file = ARGV.shift

$seen = []
def get_step(file)
  file = file.sub(/\.(info|files)/,'')
  $seen << file
  Step.new file
end

def status_msg(status)
  color = case status
          when :error, :aborted, :missing
            :red
          when :streaming
            :yellow
          when :done
            :green
          end
  Log.color(color, status)
end

def report_msg(status, name, path)

  parts = path.sub(/\{.*/,'').sub(/#{Regexp.quote(name)}$/,'').split "/"

  task = Log.color(:yellow, parts.pop)
  workflow = Log.color(:magenta, parts.pop)

  if not Open.remote?(path) and $main_mtime and ($main_mtime - File.mtime(path)) < 0
    status_msg(status) << " " << [workflow, task, path] * " " << " (#{Log.color(:red, "Mtime out of sync") })\n"
  else
    status_msg(status) << " " << [workflow, task, path] * " " << "\n"
  end
end

def report(step, offset = 0)
  info = step.info || {}
  path  = step.path
  status = info[:status] || :missing
  status = :remote if Open.remote?(path)
  name = info[:name] || File.basename(path)
  status = :unsync if status == :done and not File.exist? path
  str = " " * offset
  str << report_msg(status, name, path)
  info[:dependencies].each do |task,name,path|
    new = ! $seen.include?(path)
    dep = get_step path
    if new
      str << report(dep, offset + 1)
    else
      str << Log.color(:blue, Log.uncolor(report(dep, offset+1)))
    end
  end if info[:dependencies]
  str
end

step = get_step file
$main_mtime = File.exist?(step.path) ? File.mtime(step.path) : nil

puts report(step).strip

Version data entries

17 entries across 17 versions & 1 rubygems

Version Path
rbbt-util-5.21.5 share/rbbt_commands/workflow/prov
rbbt-util-5.21.4 share/rbbt_commands/workflow/prov
rbbt-util-5.21.3 share/rbbt_commands/workflow/prov
rbbt-util-5.21.2 share/rbbt_commands/workflow/prov
rbbt-util-5.21.1 share/rbbt_commands/workflow/prov
rbbt-util-5.21.0 share/rbbt_commands/workflow/prov
rbbt-util-5.20.26 share/rbbt_commands/workflow/prov
rbbt-util-5.20.25 share/rbbt_commands/workflow/prov
rbbt-util-5.20.24 share/rbbt_commands/workflow/prov
rbbt-util-5.20.23 share/rbbt_commands/workflow/prov
rbbt-util-5.20.22 share/rbbt_commands/workflow/prov
rbbt-util-5.20.21 share/rbbt_commands/workflow/prov
rbbt-util-5.20.20 share/rbbt_commands/workflow/prov
rbbt-util-5.20.18 share/rbbt_commands/workflow/prov
rbbt-util-5.20.17 share/rbbt_commands/workflow/prov
rbbt-util-5.20.16 share/rbbt_commands/workflow/prov
rbbt-util-5.20.15 share/rbbt_commands/workflow/prov