class Object

Public Instance Methods

main() click to toggle source
# File lib/sfp/sfw2graph.rb, line 131
def main
        if ARGV.length < 1
                puts "Usage: sfw2dot.rb <input-file> [output-file]\n\n"
                exit
        end
        
        fp = open(ARGV[0], "rb")
        json = JSON.parse(fp.read)
        fp.close
        
        dot = ""
        case json["type"]
        when 'partial-order', 'parallel'
                dot = Nuri::Planner::Graph::partial2dot(json)
        when 'sequential'
                dot = Nuri::Planner::Graph::sequential2dot(json)
        when 'stage'
                dot = Nuri::Planner::Graph::stage2dot(json)
        else
                throw Exception, "Unrecognised type of workflow: #{json['type']}"
        end
        
        outfile = "/tmp/#{ARGV[0]}.dot"
        fp = open(outfile, "w");
        fp.write(dot)
        fp.close
        
        cmd = 'dot -Tpng -o';
        if ARGV.length > 1
                cmd += "#{ARGV[1]} #{outfile}"
        else
                cmd += ARGV[0].sub(/\.[a-zA-Z]*/,'') + ".png < #{outfile}"
        end
        system(cmd)
        File.delete(outfile)
end