bin/graphshaper in graphshaper-0.2.4 vs bin/graphshaper in graphshaper-0.3.0

- old
+ new

@@ -7,41 +7,45 @@ options = {} optparse = OptionParser.new do |opts| opts.banner = "Usage: graphshaper [options] size" - - opts.on("-a", "--avocado", "Store the graph in a local AvocadoDB instance") do |avocado| - options[:avocado] = avocado + + opts.on("-a", "--arango", "Store the graph in a local ArangoDB instance") do |arango| + options[:arango] = arango end - + opts.on("-l", "--log", "Store the graph in two CSV files for nodes and edges") do |log| options[:log] = log end - + opts.on("-d", "--dot", "Store the graph in the dot format") do |dot| options[:dot] = dot end - + opts.on("-s", "--sql", "Store the graph in sql format") do |sql| options[:sql] = sql end - + opts.on("-p", "--png", "Export the graph as a PNG (graphviz must be installed)") do |png| options[:dot] = png options[:png] = png end - + opts.on("-t", "--testdata", "Generate Test Data (for shortestpath)") do |sp| options[:t] = sp end - + + opts.on("-j", "--json", "Generate JSON files") do |j| + options[:json] = j + end + opts.on_tail("--version", "Show version") do puts Graphshaper::VERSION exit end - + opts.parse! end if ARGV.length == 0 puts "Please enter a size for your graph." @@ -52,30 +56,30 @@ if options[:png] and `which circo` == "" puts "graphviz is not installed, can't export to png. Please install graphviz or run without --png option." exit end -# check for running component: AvocadoDB -if options[:avocado] +# check for running component: ArangoDB +if options[:arango] begin HTTParty.get 'http://localhost:8529' rescue Errno::ECONNREFUSED, Errno::EHOSTUNREACH - puts "No AvocadoDB instance is running on port 8529. Please start AvocadoDB or run without --avocado option." + puts "No ArangoDB instance is running on port 8529. Please start ArangoDB or run without --arango option." exit end end adapters = [] - + if options[:log] generated_vertices_csv_file = File.new("generated_vertices.csv", "w") generated_edges_csv_file = File.new("generated_edges.csv", "w") adapters << Graphshaper::LoggingAdapter.new(generated_vertices_csv_file, generated_edges_csv_file) end -if options[:avocado] - adapters << Graphshaper::AvocadoDbAdapter.new("vertices", "edges") +if options[:arango] + adapters << Graphshaper::ArangoDbAdapter.new("vertices", "edges") end if options[:dot] generated_graph_dot_file = File.new("generated_graph.dot", "w") adapters << Graphshaper::DotAdapter.new(generated_graph_dot_file) @@ -83,14 +87,20 @@ if options[:sql] generated_graph_sql_file = File.new("generated_graph.sql", "w") generated_vertices_sql_file = File.new("generated_vertices.sql", "w") generated_edges_sql_file = File.new("generated_edges.sql", "w") - + adapters << Graphshaper::SqlAdapter.new(generated_graph_sql_file, generated_vertices_sql_file, generated_edges_sql_file) end +if options[:json] + `rm -r generated_edges` + Dir.mkdir("generated_edges") + adapters << Graphshaper::JsonAdapter.new("generated_edges") +end + number_of_vertices = ARGV.first.to_i inner_vertices = 20 outer_vertices = number_of_vertices - inner_vertices graph = Graphshaper::UndirectedGraph.new inner_vertices, adapters: adapters @@ -114,15 +124,16 @@ end end print "#{graph.order} vertices and #{graph.size} edges generated" -print " and saved into AvocadoDB" if options[:avocado] +print " and saved into ArangoDB" if options[:arango] print " and logged" if options[:log] print " and generated as a dot" if options[:dot] print " and saved in sql format" if options[:sql] print " and generated test cases" if options[:t] +print " and generated JSON files" if options[:json] if options[:png] system('circo -Tpng generated_graph.dot -o generated_graph.png') end @@ -132,6 +143,6 @@ puts " in about one second" elsif ellapsed_time < 60 puts " in about #{ellapsed_time.round} seconds" else puts " in about #{ellapsed_time.round / 60} minutes and #{ellapsed_time.round % 60} seconds" -end \ No newline at end of file +end