Skip to content
Browse files

+ Added homebrew dependency analyzer.

+ Added a gallery of examples and a rake task to run them all.
[git-p4: depot-paths = "//src/graph/dev/": change = 6085]
  • Loading branch information...
1 parent bc749df commit 6e8eb436da1f009e3c4060f38450f1687d7b9c05 @zenspider zenspider committed Dec 22, 2010
Showing with 333 additions and 18 deletions.
  1. +6 −0 Manifest.txt
  2. +21 −18 README.txt
  3. +18 −0 Rakefile
  4. +66 −0 gallery/cluster.rb
  5. +49 −0 gallery/fsm.rb
  6. +20 −0 gallery/ruby_exceptions.rb
  7. +19 −0 gallery/simple_example.rb
  8. +115 −0 gallery/unix.rb
  9. +19 −0 lib/homebrew_analyzer.rb
View
6 Manifest.txt
@@ -4,9 +4,15 @@ Manifest.txt
README.txt
Rakefile
bin/graph
+gallery/cluster.rb
+gallery/fsm.rb
+gallery/ruby_exceptions.rb
+gallery/simple_example.rb
+gallery/unix.rb
lib/dep_analyzer.rb
lib/freebsd_analyzer.rb
lib/graph.rb
+lib/homebrew_analyzer.rb
lib/macports_analyzer.rb
lib/rake_analyzer.rb
lib/rubygems/commands/graph_command.rb
View
39 README.txt
@@ -8,31 +8,34 @@ Graph is a type of hash that outputs in graphviz's dot format. It
comes with a command-line interface that is easily pluggable.
It ships with plugins to graph dependencies and status of installed
-rubygems, mac ports, and freebsd ports, coloring leaf nodes blue,
-outdated nodes red, and outdated leaf nodes purple (red+blue).
+rubygems, rake tasks, homebrew ports, mac ports, and freebsd ports,
+coloring leaf nodes blue, outdated nodes red, and outdated leaf nodes
+purple (red+blue).
== FEATURES/PROBLEMS:
-* Very easy hash interface.
-* Saves to dot and automatically converts to png (or whatever).
-* edge and node attributes are easy to set.
+* Very clean DSL interface and API.
+* Saves to dot and can automatically convert to png (or whatever).
+* graph, edge, and node attributes are easy to set.
* bin/graph includes a caching mechanism for slower fairly static data.
== SYNOPSIS:
- deps = Graph.new
-
- ObjectSpace.each_object Class do |mod|
- next if mod.name =~ /Errno/
- next unless mod < Exception
- deps[mod.to_s] = mod.superclass.to_s
+ digraph do
+ # many ways to access/create edges and nodes
+ edge "a", "b"
+ self["b"]["c"]
+ node("c") >> "a"
+
+ square << node("a")
+ triangle << node("b")
+
+ red << node("a") << edge("a", "b")
+ green << node("b") << edge("b", "c")
+ blue << node("c") << edge("c", "a")
+
+ save "simple_example", "png"
end
-
- deps.attribs["StandardError"] << "color = blue"
- deps.attribs["RuntimeError"] << "color = red"
- deps.prefix << "rankdir = BT" # put Exception on top
-
- deps.save "exceptions"
== REQUIREMENTS:
@@ -46,7 +49,7 @@ outdated nodes red, and outdated leaf nodes purple (red+blue).
(The MIT License)
-Copyright (c) 2009 Ryan Davis, seattle.rb
+Copyright (c) Ryan Davis, seattle.rb
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
View
18 Rakefile
@@ -12,4 +12,22 @@ Hoe.spec 'graph' do
self.rubyforge_name = 'seattlerb'
end
+gallery = Dir["gallery/*.rb"]
+pngs = gallery.map { |f| f.sub(/\.rb$/, ".png") }
+dots = gallery.map { |f| f.sub(/\.rb$/, ".dot") }
+
+file pngs
+file dots
+task :gallery => pngs
+
+rule ".png" => ".rb" do |t|
+ Dir.chdir "gallery" do
+ ruby "-I../lib #{File.basename t.source}"
+ end
+end
+
+task :clean do
+ rm_f Dir[*pngs] + Dir[*dots]
+end
+
# vim: syntax=Ruby
View
66 gallery/cluster.rb
@@ -0,0 +1,66 @@
+#!/usr/bin/ruby -w
+
+# digraph G {
+#
+# subgraph cluster_0 {
+# style=filled;
+# color=lightgrey;
+# node [style=filled,color=white];
+# a0 -> a1 -> a2 -> a3;
+# label = "process #1";
+# }
+#
+# subgraph cluster_1 {
+# node [style=filled];
+# b0 -> b1 -> b2 -> b3;
+# label = "process #2";
+# color=blue
+# }
+# start -> a0;
+# start -> b0;
+# a1 -> b3;
+# b2 -> a3;
+# a3 -> a0;
+# a3 -> end;
+# b3 -> end;
+#
+# start [shape=Mdiamond];
+# end [shape=Msquare];
+# }
+
+require "graph"
+
+digraph do
+ # composite styles
+ leaf_node = white + filled
+
+ subgraph "cluster_0" do
+ label "process #1"
+ graph_attribs << filled << lightgray
+ node_attribs << leaf_node
+
+ edge "a0", "a1", "a2", "a3"
+ end
+
+ subgraph "cluster_1" do
+ label "process #2"
+ graph_attribs << blue
+ node_attribs << filled
+
+ edge "b0", "b1", "b2", "b3"
+ end
+
+ edge "start", "a0"
+ edge "start", "b0"
+ edge "a1", "b3"
+ edge "b2", "a3"
+ edge "a3", "a0"
+ edge "a3", "end"
+ edge "b3", "end"
+
+ mdiamond << node("start")
+ msquare << node("end")
+
+ save "cluster", "png"
+end
+
View
49 gallery/fsm.rb
@@ -0,0 +1,49 @@
+#!/usr/bin/ruby
+
+# digraph finite_state_machine {
+# rankdir=LR;
+# size="8,5"
+# node [shape = doublecircle]; LR_0 LR_3 LR_4 LR_8;
+# node [shape = circle];
+# LR_0 -> LR_2 [ label = "SS(B)" ];
+# LR_0 -> LR_1 [ label = "SS(S)" ];
+# LR_1 -> LR_3 [ label = "S($end)" ];
+# LR_2 -> LR_6 [ label = "SS(b)" ];
+# LR_2 -> LR_5 [ label = "SS(a)" ];
+# LR_2 -> LR_4 [ label = "S(A)" ];
+# LR_5 -> LR_7 [ label = "S(b)" ];
+# LR_5 -> LR_5 [ label = "S(a)" ];
+# LR_6 -> LR_6 [ label = "S(b)" ];
+# LR_6 -> LR_5 [ label = "S(a)" ];
+# LR_7 -> LR_8 [ label = "S(b)" ];
+# LR_7 -> LR_5 [ label = "S(a)" ];
+# LR_8 -> LR_6 [ label = "S(b)" ];
+# LR_8 -> LR_5 [ label = "S(a)" ];
+# }
+
+require "graph"
+
+digraph do
+ rotate
+ graph_attribs << 'size="8,5"'
+
+ node_attribs << circle
+ doublecircle << node("LR_0") << node("LR_3") << node("LR_4") << node("LR_8")
+
+ edge("LR_0", "LR_2").label "SS(B)"
+ edge("LR_0", "LR_1").label "SS(S)"
+ edge("LR_1", "LR_3").label "S($end)"
+ edge("LR_2", "LR_6").label "SS(b)"
+ edge("LR_2", "LR_5").label "SS(a)"
+ edge("LR_2", "LR_4").label "S(A)"
+ edge("LR_5", "LR_7").label "S(b)"
+ edge("LR_5", "LR_5").label "S(a)"
+ edge("LR_6", "LR_6").label "S(b)"
+ edge("LR_6", "LR_5").label "S(a)"
+ edge("LR_7", "LR_8").label "S(b)"
+ edge("LR_7", "LR_5").label "S(a)"
+ edge("LR_8", "LR_6").label "S(b)"
+ edge("LR_8", "LR_5").label "S(a)"
+
+ save "fsm", "png"
+end
View
20 gallery/ruby_exceptions.rb
@@ -0,0 +1,20 @@
+#!/usr/bin/ruby -w
+
+require "graph"
+
+digraph do
+ rotate
+ boxes
+
+ ObjectSpace.each_object Class do |mod|
+ next if mod.name =~ /Errno/
+ next unless mod < Exception
+
+ edge mod.superclass.to_s, mod.to_s
+ end
+
+ blue << node("StandardError")
+ red << node("RuntimeError")
+
+ save "ruby_exceptions", "png"
+end
View
19 gallery/simple_example.rb
@@ -0,0 +1,19 @@
+#!/usr/bin/ruby -w
+
+require 'graph'
+
+digraph do
+ # many ways to access/create edges and nodes
+ edge "a", "b"
+ self["b"]["c"]
+ node("c") >> "a"
+
+ square << node("a")
+ triangle << node("b")
+
+ red << node("a") << edge("a", "b")
+ green << node("b") << edge("b", "c")
+ blue << node("c") << edge("c", "a")
+
+ save "simple_example", "png"
+end
View
115 gallery/unix.rb
@@ -0,0 +1,115 @@
+#!/usr/bin/ruby -w
+
+# /* courtesy Ian Darwin and Geoff Collyer, Softquad Inc. */
+# digraph unix {
+# size="6,6";
+# node [color=lightblue2, style=filled];
+# "5th Edition" -> "6th Edition";
+# "5th Edition" -> "PWB 1.0";
+# "6th Edition" -> "LSX";
+# "6th Edition" -> "1 BSD";
+# "6th Edition" -> "Mini Unix";
+# "6th Edition" -> "Wollongong";
+# "6th Edition" -> "Interdata";
+# "Interdata" -> "Unix/TS 3.0";
+# "Interdata" -> "PWB 2.0";
+# "Interdata" -> "7th Edition";
+# "7th Edition" -> "8th Edition";
+# "7th Edition" -> "32V";
+# "7th Edition" -> "V7M";
+# "7th Edition" -> "Ultrix-11";
+# "7th Edition" -> "Xenix";
+# "7th Edition" -> "UniPlus+";
+# "V7M" -> "Ultrix-11";
+# "8th Edition" -> "9th Edition";
+# "1 BSD" -> "2 BSD";
+# "2 BSD" -> "2.8 BSD";
+# "2.8 BSD" -> "Ultrix-11";
+# "2.8 BSD" -> "2.9 BSD";
+# "32V" -> "3 BSD";
+# "3 BSD" -> "4 BSD";
+# "4 BSD" -> "4.1 BSD";
+# "4.1 BSD" -> "4.2 BSD";
+# "4.1 BSD" -> "2.8 BSD";
+# "4.1 BSD" -> "8th Edition";
+# "4.2 BSD" -> "4.3 BSD";
+# "4.2 BSD" -> "Ultrix-32";
+# "PWB 1.0" -> "PWB 1.2";
+# "PWB 1.0" -> "USG 1.0";
+# "PWB 1.2" -> "PWB 2.0";
+# "USG 1.0" -> "CB Unix 1";
+# "USG 1.0" -> "USG 2.0";
+# "CB Unix 1" -> "CB Unix 2";
+# "CB Unix 2" -> "CB Unix 3";
+# "CB Unix 3" -> "Unix/TS++";
+# "CB Unix 3" -> "PDP-11 Sys V";
+# "USG 2.0" -> "USG 3.0";
+# "USG 3.0" -> "Unix/TS 3.0";
+# "PWB 2.0" -> "Unix/TS 3.0";
+# "Unix/TS 1.0" -> "Unix/TS 3.0";
+# "Unix/TS 3.0" -> "TS 4.0";
+# "Unix/TS++" -> "TS 4.0";
+# "CB Unix 3" -> "TS 4.0";
+# "TS 4.0" -> "System V.0";
+# "System V.0" -> "System V.2";
+# "System V.2" -> "System V.3";
+# }
+
+require "graph"
+
+digraph "unix" do
+ graph_attribs << 'size="6,6"'
+ node_attribs << lightblue << filled
+
+ edge "5th Edition", "6th Edition"
+ edge "5th Edition", "PWB 1.0"
+ edge "6th Edition", "LSX"
+ edge "6th Edition", "1 BSD"
+ edge "6th Edition", "Mini Unix"
+ edge "6th Edition", "Wollongong"
+ edge "6th Edition", "Interdata"
+ edge "Interdata", "Unix/TS 3.0"
+ edge "Interdata", "PWB 2.0"
+ edge "Interdata", "7th Edition"
+ edge "7th Edition", "8th Edition"
+ edge "7th Edition", "32V"
+ edge "7th Edition", "V7M"
+ edge "7th Edition", "Ultrix-11"
+ edge "7th Edition", "Xenix"
+ edge "7th Edition", "UniPlus+"
+ edge "V7M", "Ultrix-11"
+ edge "8th Edition", "9th Edition"
+ edge "1 BSD", "2 BSD"
+ edge "2 BSD", "2.8 BSD"
+ edge "2.8 BSD", "Ultrix-11"
+ edge "2.8 BSD", "2.9 BSD"
+ edge "32V", "3 BSD"
+ edge "3 BSD", "4 BSD"
+ edge "4 BSD", "4.1 BSD"
+ edge "4.1 BSD", "4.2 BSD"
+ edge "4.1 BSD", "2.8 BSD"
+ edge "4.1 BSD", "8th Edition"
+ edge "4.2 BSD", "4.3 BSD"
+ edge "4.2 BSD", "Ultrix-32"
+ edge "PWB 1.0", "PWB 1.2"
+ edge "PWB 1.0", "USG 1.0"
+ edge "PWB 1.2", "PWB 2.0"
+ edge "USG 1.0", "CB Unix 1"
+ edge "USG 1.0", "USG 2.0"
+ edge "CB Unix 1", "CB Unix 2"
+ edge "CB Unix 2", "CB Unix 3"
+ edge "CB Unix 3", "Unix/TS++"
+ edge "CB Unix 3", "PDP-11 Sys V"
+ edge "USG 2.0", "USG 3.0"
+ edge "USG 3.0", "Unix/TS 3.0"
+ edge "PWB 2.0", "Unix/TS 3.0"
+ edge "Unix/TS 1.0", "Unix/TS 3.0"
+ edge "Unix/TS 3.0", "TS 4.0"
+ edge "Unix/TS++", "TS 4.0"
+ edge "CB Unix 3", "TS 4.0"
+ edge "TS 4.0", "System V.0"
+ edge "System V.0", "System V.2"
+ edge "System V.2", "System V.3"
+
+ save "unix", "png"
+end
View
19 lib/homebrew_analyzer.rb
@@ -0,0 +1,19 @@
+require 'dep_analyzer'
+
+class HomebrewAnalyzer < DepAnalyzer
+ def installed
+ # don't cache so it updates every delete
+ puts "scanning installed ports"
+ `brew list`.scan(/\S+/).map { |s| s.split.first }
+ end
+
+ def outdated
+ # don't cache so it updates every delete
+ puts "scanning outdated ports"
+ `brew outdated`.split(/\n/).map { |s| s.split.first }
+ end
+
+ def deps port
+ `brew deps #{port}`.scan(/\S+/)
+ end
+end

0 comments on commit 6e8eb43

Please sign in to comment.
Something went wrong with that request. Please try again.