Created
January 25, 2011 09:33
-
-
Save mro/794713 to your computer and use it in GitHub Desktop.
turn MacPorts dependencies into dot file for graphviz
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/ruby -w | |
# visualize macports dependencies: http://blog.mro.name/2010/08/visualise-macports-dependencies/ | |
# pipe the result through graphviz, e.g. | |
# $ ./port-deps2dot.rb | dot -Tpdf -o port-deps.pdf ; open port-deps.pdf | |
def scan_deps | |
pat = /^([^:]+):(.+)$/ | |
name = '' | |
deps = [] | |
IO.popen('port info --name --pretty --depends installed') do |f| | |
f.each_line do |l| | |
case l | |
when /^--$/ | |
yield name, deps | |
name = '' | |
deps = [] | |
when /^([^:]+):(.+)$/ | |
if 'name' == "#$1" | |
name = "#$2".strip | |
else | |
deps.concat("#$2".split(/\s*,\s*/)) | |
end | |
else | |
raise "Fall-through for '#{l}'" | |
end | |
end | |
end | |
end | |
all = {} | |
scan_deps do |name,deps| | |
d = all[name] | |
all[name] = d = [] if d.nil? | |
deps.collect! {|i| i.strip} | |
d.concat deps | |
d.sort! | |
d.uniq! | |
end | |
head = <<END_OF_STRING | |
#!/usr/bin/dot -Tpdf -o port-deps.pdf | |
/* | |
See http://www.graphviz.org/Documentation.php | |
*/ | |
digraph "port deps" { | |
rankdir=LR; | |
label="port deps"; | |
node [style=filled,fillcolor=lightblue,shape=ellipse]; | |
top_level [shape=point]; | |
END_OF_STRING | |
puts head | |
all.keys.sort.each do |name| | |
deps = all[name] | |
if deps.count > 0 | |
deps.each {|d| puts "\t\"#{name}\" -> \"#{d}\";" } | |
else | |
puts "\t\"#{name}\";" | |
end | |
end | |
foot = <<END_OF_STRING | |
} | |
END_OF_STRING | |
puts foot |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment