ruby-graphviz_c 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gemrc +0 -0
- data/.gitignore +9 -0
- data/.travis.yml +7 -0
- data/AUTHORS.rdoc +33 -0
- data/CHANGELOG.rdoc +287 -0
- data/COPYING.rdoc +133 -0
- data/Gemfile +4 -0
- data/README.rdoc +206 -0
- data/Rakefile +71 -0
- data/bin/dot2ruby +91 -0
- data/bin/gem2gv +165 -0
- data/bin/git2gv +167 -0
- data/bin/ruby2gv +234 -0
- data/bin/xml2gv +96 -0
- data/examples/dot/JSP.dot +52 -0
- data/examples/dot/balanced.dot +36 -0
- data/examples/dot/cluster.dot +30 -0
- data/examples/dot/dotgraph.dot +28 -0
- data/examples/dot/fsm.dot +20 -0
- data/examples/dot/genetic.dot +118 -0
- data/examples/dot/hello.dot +1 -0
- data/examples/dot/hello_test.rb +33 -0
- data/examples/dot/lion_share.dot +103 -0
- data/examples/dot/prof.dot +150 -0
- data/examples/dot/psg.dot +28 -0
- data/examples/dot/rank.dot +6 -0
- data/examples/dot/sdh.dot +284 -0
- data/examples/dot/siblings.dot +492 -0
- data/examples/dot/so-sample001.gv +30 -0
- data/examples/dot/so-sample002.gv +33 -0
- data/examples/dot/so-sample003.gv +45 -0
- data/examples/dot/test.dot +17 -0
- data/examples/dot/test_parse.rb +13 -0
- data/examples/dot/this_crach_with_dot_2.20.dot +24 -0
- data/examples/dot/unix.dot +104 -0
- data/examples/graphml/attributes.ext.graphml +12 -0
- data/examples/graphml/attributes.graphml +40 -0
- data/examples/graphml/cluster.graphml +75 -0
- data/examples/graphml/failed_graph.graphml +461 -0
- data/examples/graphml/hyper.graphml +29 -0
- data/examples/graphml/nested.graphml +54 -0
- data/examples/graphml/port.graphml +32 -0
- data/examples/graphml/simple.graphml +30 -0
- data/examples/hello.png +0 -0
- data/examples/rgv/rgv.ps +125 -0
- data/examples/rgv/test_rgv.rb +12 -0
- data/examples/sample01.rb +32 -0
- data/examples/sample02.rb +42 -0
- data/examples/sample03.rb +31 -0
- data/examples/sample04.rb +22 -0
- data/examples/sample05.rb +32 -0
- data/examples/sample06.rb +46 -0
- data/examples/sample07.rb +23 -0
- data/examples/sample08.rb +34 -0
- data/examples/sample09.rb +50 -0
- data/examples/sample10.rb +50 -0
- data/examples/sample11.rb +42 -0
- data/examples/sample12.rb +55 -0
- data/examples/sample13.rb +48 -0
- data/examples/sample14.rb +44 -0
- data/examples/sample15.rb +25 -0
- data/examples/sample16.rb +8 -0
- data/examples/sample17.rb +92 -0
- data/examples/sample18.rb +24 -0
- data/examples/sample19.rb +59 -0
- data/examples/sample20.rb +47 -0
- data/examples/sample21.rb +12 -0
- data/examples/sample22.rb +10 -0
- data/examples/sample23.rb +11 -0
- data/examples/sample24.rb +11 -0
- data/examples/sample25.rb +11 -0
- data/examples/sample26.rb +8 -0
- data/examples/sample27.rb +8 -0
- data/examples/sample28.rb +12 -0
- data/examples/sample29.rb +8 -0
- data/examples/sample30.rb +12 -0
- data/examples/sample31.rb +10 -0
- data/examples/sample32.rb +14 -0
- data/examples/sample33.rb +43 -0
- data/examples/sample34.rb +29 -0
- data/examples/sample35.rb +43 -0
- data/examples/sample36.rb +35 -0
- data/examples/sample37.rb +87 -0
- data/examples/sample38.rb +12 -0
- data/examples/sample39.rb +11 -0
- data/examples/sample40.rb +17 -0
- data/examples/sample41.rb +8 -0
- data/examples/sample42.rb +35 -0
- data/examples/sample43.rb +26 -0
- data/examples/sample44.rb +97 -0
- data/examples/sample45.rb +24 -0
- data/examples/sample46.rb +43 -0
- data/examples/sample47.rb +7 -0
- data/examples/sample48.rb +62 -0
- data/examples/sample49.rb +10 -0
- data/examples/sample50.rb +215 -0
- data/examples/sample51.rb +37 -0
- data/examples/sample52.rb +62 -0
- data/examples/sample53.rb +26 -0
- data/examples/sample54.rb +26 -0
- data/examples/sample55.rb +9 -0
- data/examples/sample56.rb +10 -0
- data/examples/sample57.rb +8 -0
- data/examples/sample58.rb +33 -0
- data/examples/sample59.rb +14 -0
- data/examples/sample60.rb +12 -0
- data/examples/sample61.rb +12 -0
- data/examples/sample62.rb +24 -0
- data/examples/sample63.rb +32 -0
- data/examples/sample64.rb +31 -0
- data/examples/sample65.rb +9 -0
- data/examples/sample66.rb +4 -0
- data/examples/sample67.rb +10 -0
- data/examples/sample68.rb +27 -0
- data/examples/sample69.rb +23 -0
- data/examples/sample70.rb +9 -0
- data/examples/sample99.rb +70 -0
- data/examples/sdlshapes/README +2 -0
- data/examples/sdlshapes/sdl.ps +655 -0
- data/examples/sdlshapes/sdlshapes.dot +78 -0
- data/examples/test.xml +26 -0
- data/examples/theory/pert.rb +47 -0
- data/examples/theory/tests.rb +87 -0
- data/lib/ext/gvpr/dot2ruby.g +185 -0
- data/lib/graphviz/attrs.rb +73 -0
- data/lib/graphviz/constants.rb +294 -0
- data/lib/graphviz/core_ext.rb +64 -0
- data/lib/graphviz/dot2ruby.rb +59 -0
- data/lib/graphviz/dot_script.rb +109 -0
- data/lib/graphviz/dsl.rb +67 -0
- data/lib/graphviz/edge.rb +197 -0
- data/lib/graphviz/elements.rb +39 -0
- data/lib/graphviz/ext.rb +17 -0
- data/lib/graphviz/family_tree/couple.rb +63 -0
- data/lib/graphviz/family_tree/generation.rb +39 -0
- data/lib/graphviz/family_tree/person.rb +120 -0
- data/lib/graphviz/family_tree/sibling.rb +13 -0
- data/lib/graphviz/family_tree.rb +118 -0
- data/lib/graphviz/graphml.rb +268 -0
- data/lib/graphviz/math/matrix.rb +221 -0
- data/lib/graphviz/node.rb +160 -0
- data/lib/graphviz/nothugly/nothugly.xsl +321 -0
- data/lib/graphviz/nothugly.rb +63 -0
- data/lib/graphviz/theory.rb +321 -0
- data/lib/graphviz/types/arrow_type.rb +32 -0
- data/lib/graphviz/types/color.rb +58 -0
- data/lib/graphviz/types/color_list.rb +24 -0
- data/lib/graphviz/types/esc_string.rb +20 -0
- data/lib/graphviz/types/gv_bool.rb +49 -0
- data/lib/graphviz/types/gv_double.rb +32 -0
- data/lib/graphviz/types/html_string.rb +18 -0
- data/lib/graphviz/types/lbl_string.rb +22 -0
- data/lib/graphviz/types/rect.rb +35 -0
- data/lib/graphviz/types/spline_type.rb +77 -0
- data/lib/graphviz/types.rb +22 -0
- data/lib/graphviz/utils/colors.rb +1018 -0
- data/lib/graphviz/utils.rb +70 -0
- data/lib/graphviz/xml.rb +119 -0
- data/lib/graphviz.rb +967 -0
- data/lib/ruby-graphviz.rb +1 -0
- data/man/dot2ruby.1 +66 -0
- data/man/dot2ruby.1.ronn +55 -0
- data/man/gem2gv.1 +60 -0
- data/man/gem2gv.1.ronn +47 -0
- data/man/git2gv.1 +48 -0
- data/man/git2gv.1.ronn +40 -0
- data/man/ruby2gv.1 +60 -0
- data/man/ruby2gv.1.ronn +47 -0
- data/man/xml2gv.1 +48 -0
- data/man/xml2gv.1.ronn +39 -0
- data/ruby-graphviz.gemspec +47 -0
- data/setup.rb +1585 -0
- data/test/helper.rb +13 -0
- data/test/support.rb +95 -0
- data/test/test_dot_script.rb +47 -0
- data/test/test_examples.rb +151 -0
- data/test/test_graph.rb +115 -0
- data/test/test_search.rb +29 -0
- data/test/test_subgraph.rb +27 -0
- data/test/test_theory.rb +98 -0
- data/test/test_types.rb +65 -0
- data/test/test_utils_colors.rb +52 -0
- metadata +301 -0
data/bin/git2gv
ADDED
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
# Copyright (C) 2010 Gregoire Lejeune <gregoire.lejeune@free.fr>
|
|
3
|
+
#
|
|
4
|
+
# This program is free software; you can redistribute it and/or modify
|
|
5
|
+
# it under the terms of the GNU General Public License as published by
|
|
6
|
+
# the Free Software Foundation; either version 2 of the License, or
|
|
7
|
+
# (at your option) any later version.
|
|
8
|
+
#
|
|
9
|
+
# This program is distributed in the hope that it will be useful,
|
|
10
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
11
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
12
|
+
# GNU General Public License for more details.
|
|
13
|
+
#
|
|
14
|
+
# You should have received a copy of the GNU General Public License
|
|
15
|
+
# along with this program; if not, write to the Free Software
|
|
16
|
+
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
17
|
+
|
|
18
|
+
require 'rubygems'
|
|
19
|
+
require 'getoptlong'
|
|
20
|
+
require 'graphviz'
|
|
21
|
+
|
|
22
|
+
class Git2Gv
|
|
23
|
+
def initialize( xGVPath, xOutFile, xOutFormat, bNothugly )
|
|
24
|
+
@xGVPath, @xOutFile, @xOutFormat, @bNothugly = xGVPath, xOutFile, xOutFormat.to_sym, bNothugly
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
def run
|
|
28
|
+
git = GraphViz.new( :G, :path => @xGVPath )
|
|
29
|
+
|
|
30
|
+
git.node[:shape => "record"]
|
|
31
|
+
|
|
32
|
+
branches.each do |branch|
|
|
33
|
+
git.add_nodes( branch, :style => "filled", :fillcolor => :lightgrey )
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
commits.each do |commit|
|
|
37
|
+
git.add_nodes(
|
|
38
|
+
commit[:short],
|
|
39
|
+
:style => "filled",
|
|
40
|
+
:fillcolor => :lightblue,
|
|
41
|
+
:label => "{ #{commit[:long]} |{ #{commit[:comment].gsub(/\{/, "\\{").gsub(/\}/, "\\}").gsub(/\|/, "\\|").gsub(/</, "\\<").gsub(/>/, "\\>")}}| { #{commit[:commiter]} | #{commit[:date]} } }"
|
|
42
|
+
)
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
refs.each do |from, to|
|
|
46
|
+
git.add_edges( from, to )
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
relations.each do |from, to|
|
|
50
|
+
git.add_edges( to, from, :dir => "back" )
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
git.output( @xOutFormat => @xOutFile, :nothugly => @bNothugly )
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
# private
|
|
57
|
+
def cmd(c, &blk)
|
|
58
|
+
`#{c}`.split($/).map(&blk || proc {|a| a })
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
def commits
|
|
62
|
+
@commits ||= begin
|
|
63
|
+
data = []
|
|
64
|
+
cmd('git log --pretty=format:"%h - %H - %s - %cn - %cd" --date=short').each do |commit|
|
|
65
|
+
x = commit.split( " - " )
|
|
66
|
+
data << {
|
|
67
|
+
:short => x[0],
|
|
68
|
+
:long => x[1],
|
|
69
|
+
:comment => x[2],
|
|
70
|
+
:commiter => x[3],
|
|
71
|
+
:date => x[4]
|
|
72
|
+
}
|
|
73
|
+
end
|
|
74
|
+
data
|
|
75
|
+
end
|
|
76
|
+
end
|
|
77
|
+
|
|
78
|
+
def relations
|
|
79
|
+
@rels ||= cmd("git log --pretty=format:\"%h %p\"") { |l|
|
|
80
|
+
c, *parents = l.split
|
|
81
|
+
parents.map {|p| [p, c] }
|
|
82
|
+
}.flatten(1)
|
|
83
|
+
end
|
|
84
|
+
|
|
85
|
+
def branches
|
|
86
|
+
@branches ||= cmd("git branch") {|b| b[2..-1] }
|
|
87
|
+
end
|
|
88
|
+
|
|
89
|
+
def refs
|
|
90
|
+
branches.inject({}) {|h,b|
|
|
91
|
+
h.tap { h[b] = `git log -1 #{b} --pretty=format:"%h"` }
|
|
92
|
+
}
|
|
93
|
+
end
|
|
94
|
+
|
|
95
|
+
def current_branch
|
|
96
|
+
cmd("git branch").select {|l| l =~ /^\*/ }.first.strip[2..-1]
|
|
97
|
+
end
|
|
98
|
+
end
|
|
99
|
+
|
|
100
|
+
def usage
|
|
101
|
+
puts "usage: git2gv [-Tformat] [-ofile] [-h] [-V]"
|
|
102
|
+
puts "-T, --output-format format Output format (default: png)"
|
|
103
|
+
puts " --nothugly Use nothugly if SVG output"
|
|
104
|
+
puts "-o, --output-file file Output file (default: STDOUT)"
|
|
105
|
+
puts "-p, --path Graphviz path"
|
|
106
|
+
puts "-V, --version Show version"
|
|
107
|
+
puts "-h, --help Show this usage message"
|
|
108
|
+
end
|
|
109
|
+
|
|
110
|
+
def version
|
|
111
|
+
puts "Git2GraphViz v#{GraphViz::Constants::RGV_VERSION}, (c)2010 Gregoire Lejeune <gregoire.lejeune@free.fr>"
|
|
112
|
+
puts ""
|
|
113
|
+
puts "This program is free software; you can redistribute it and/or modify"
|
|
114
|
+
puts "it under the terms of the GNU General Public License as published by"
|
|
115
|
+
puts "the Free Software Foundation; either version 2 of the License, or"
|
|
116
|
+
puts "(at your option) any later version."
|
|
117
|
+
puts ""
|
|
118
|
+
puts "This program is distributed in the hope that it will be useful,"
|
|
119
|
+
puts "but WITHOUT ANY WARRANTY; without even the implied warranty of"
|
|
120
|
+
puts "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the"
|
|
121
|
+
puts "GNU General Public License for more details."
|
|
122
|
+
puts ""
|
|
123
|
+
puts "You should have received a copy of the GNU General Public License"
|
|
124
|
+
puts "along with this program; if not, write to the Free Software"
|
|
125
|
+
puts "Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA"
|
|
126
|
+
end
|
|
127
|
+
|
|
128
|
+
oOpt = GetoptLong.new(
|
|
129
|
+
['--output-format', '-T', GetoptLong::REQUIRED_ARGUMENT],
|
|
130
|
+
['--output-file', '-o', GetoptLong::REQUIRED_ARGUMENT],
|
|
131
|
+
['--path', '-p', GetoptLong::REQUIRED_ARGUMENT],
|
|
132
|
+
['--nothugly', GetoptLong::NO_ARGUMENT],
|
|
133
|
+
['--help', '-h', GetoptLong::NO_ARGUMENT],
|
|
134
|
+
['--version', '-V', GetoptLong::NO_ARGUMENT]
|
|
135
|
+
)
|
|
136
|
+
|
|
137
|
+
xOutFormat = "png"
|
|
138
|
+
xOutFile = nil
|
|
139
|
+
xGVPath = ""
|
|
140
|
+
bNothugly = false
|
|
141
|
+
|
|
142
|
+
begin
|
|
143
|
+
oOpt.each_option do |xOpt, xValue|
|
|
144
|
+
case xOpt
|
|
145
|
+
when '--output-format'
|
|
146
|
+
xOutFormat = xValue
|
|
147
|
+
when '--output-file'
|
|
148
|
+
xOutFile = xValue
|
|
149
|
+
when '--path'
|
|
150
|
+
xGVPath = xValue
|
|
151
|
+
when '--nothugly'
|
|
152
|
+
bNothugly = true
|
|
153
|
+
when '--help'
|
|
154
|
+
usage( )
|
|
155
|
+
exit
|
|
156
|
+
when '--version'
|
|
157
|
+
version( )
|
|
158
|
+
exit
|
|
159
|
+
end
|
|
160
|
+
end
|
|
161
|
+
rescue GetoptLong::InvalidOption
|
|
162
|
+
usage( )
|
|
163
|
+
exit
|
|
164
|
+
end
|
|
165
|
+
|
|
166
|
+
Git2Gv.new( xGVPath, xOutFile, xOutFormat, bNothugly ).run
|
|
167
|
+
|
data/bin/ruby2gv
ADDED
|
@@ -0,0 +1,234 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
# Copyright (C) 2005 - 2012 Gregoire Lejeune <gregoire.lejeune@free.fr>
|
|
3
|
+
#
|
|
4
|
+
# This program is free software; you can redistribute it and/or modify
|
|
5
|
+
# it under the terms of the GNU General Public License as published by
|
|
6
|
+
# the Free Software Foundation; either version 2 of the License, or
|
|
7
|
+
# (at your option) any later version.
|
|
8
|
+
#
|
|
9
|
+
# This program is distributed in the hope that it will be useful,
|
|
10
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
11
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
12
|
+
# GNU General Public License for more details.
|
|
13
|
+
#
|
|
14
|
+
# You should have received a copy of the GNU General Public License
|
|
15
|
+
# along with this program; if not, write to the Free Software
|
|
16
|
+
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
17
|
+
|
|
18
|
+
require 'rubygems'
|
|
19
|
+
require 'getoptlong'
|
|
20
|
+
require 'graphviz'
|
|
21
|
+
require 'graphviz/constants'
|
|
22
|
+
require 'rbconfig'
|
|
23
|
+
require 'mkmf'
|
|
24
|
+
|
|
25
|
+
DEBUG = false
|
|
26
|
+
|
|
27
|
+
class Rb2Gv
|
|
28
|
+
REQUIRE = /^\s*require\s*("|')([^\1\s]*)(\1)/
|
|
29
|
+
|
|
30
|
+
def initialize( xGVPath, xUse = "dot", xStops = [] )
|
|
31
|
+
@oGraph = GraphViz::new( "G", :path => xGVPath, :use => xUse )
|
|
32
|
+
# @oGraph['size'] = '10,10'
|
|
33
|
+
@hxNodes = Hash::new( )
|
|
34
|
+
@hxEdge = Array::new( )
|
|
35
|
+
@lxStops = xStops
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
public
|
|
39
|
+
def parse( xFile )
|
|
40
|
+
@hxNodes[xFile] = gv_newNode( xFile, "box", "forestgreen" )
|
|
41
|
+
puts "+ Node #{xFile}" if DEBUG
|
|
42
|
+
|
|
43
|
+
parseFile( xFile, nil, xFile )
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
def out( xFormat = "dot", xFile = nil )
|
|
47
|
+
if xFile.nil?
|
|
48
|
+
@oGraph.output( xFormat => String )
|
|
49
|
+
else
|
|
50
|
+
@oGraph.output( xFormat => xFile )
|
|
51
|
+
end
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
private
|
|
55
|
+
def gv_newNode( xNode, xShape = "box", xColor = nil )
|
|
56
|
+
xNodeName = xNode.gsub( /[^a-zA-Z0-9]/, "_" )
|
|
57
|
+
if xColor.nil?
|
|
58
|
+
@oGraph.add_nodes( xNodeName, "label" => xNode, "shape" => xShape )
|
|
59
|
+
else
|
|
60
|
+
@oGraph.add_nodes( xNodeName, "label" => xNode, "shape" => xShape, "style" => "filled", "color" => xColor )
|
|
61
|
+
end
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
def getLibraryPath( xLib, xExt = ["rb"] )
|
|
65
|
+
|
|
66
|
+
xPath = [ "libexecdir", "libdir", "sitedir", "rubylibdir", "sitelibdir", "archdir", "sitedir", "sitearchdir" ]
|
|
67
|
+
xRbLib = with_config( xLib+'lib', xLib)
|
|
68
|
+
|
|
69
|
+
if /\.(rb|so|bundle|dll)$/.match( xRbLib )
|
|
70
|
+
match = /^(.*)\.([^\.]*)$/.match(xRbLib)
|
|
71
|
+
xRbFile, xExt = match[1], [match[2]]
|
|
72
|
+
else
|
|
73
|
+
xRbFile = xRbLib
|
|
74
|
+
end
|
|
75
|
+
|
|
76
|
+
xExt.each do |e|
|
|
77
|
+
xRbFileWithExt = xRbFile + "." + e
|
|
78
|
+
|
|
79
|
+
# Search in "standard" paths
|
|
80
|
+
xPath.each do |xDir|
|
|
81
|
+
xCurrentPath = RbConfig::expand( RbConfig::CONFIG[xDir] )
|
|
82
|
+
xFileFound = File.join( xCurrentPath, xRbFileWithExt )
|
|
83
|
+
if File.exist?( xFileFound )
|
|
84
|
+
return xFileFound
|
|
85
|
+
end
|
|
86
|
+
end
|
|
87
|
+
|
|
88
|
+
# Search in "rubygems" :: This is not utile but...
|
|
89
|
+
Gem::Specification.find_all do |spec|
|
|
90
|
+
if spec == xLib
|
|
91
|
+
spec.require_paths.unshift spec.bindir if spec.bindir
|
|
92
|
+
xPath = spec.require_paths.map do |path|
|
|
93
|
+
File.join spec.full_gem_path, path
|
|
94
|
+
end
|
|
95
|
+
xPath.each do |xCurrentPath|
|
|
96
|
+
xFileFound = File.join( xCurrentPath, xRbFileWithExt )
|
|
97
|
+
if File.exist?( xFileFound )
|
|
98
|
+
return xFileFound
|
|
99
|
+
end
|
|
100
|
+
end
|
|
101
|
+
end
|
|
102
|
+
end
|
|
103
|
+
end
|
|
104
|
+
|
|
105
|
+
return nil
|
|
106
|
+
end
|
|
107
|
+
|
|
108
|
+
def parseFile( xFile, xFromFile = nil, xLib = nil )
|
|
109
|
+
|
|
110
|
+
if xFromFile
|
|
111
|
+
puts "Parse #{xFile} required in #{xFromFile} :" if DEBUG
|
|
112
|
+
else
|
|
113
|
+
puts "Parse #{xFile} :" if DEBUG
|
|
114
|
+
end
|
|
115
|
+
|
|
116
|
+
File.open(xFile, 'r').each_line do |xLine|
|
|
117
|
+
if lxLineMatch = REQUIRE.match( xLine )
|
|
118
|
+
xRequiredLib = lxLineMatch[2].gsub( /\.(rb|so)$/, "" )
|
|
119
|
+
|
|
120
|
+
if not @hxNodes.has_key?( xRequiredLib )
|
|
121
|
+
puts " + Node #{xRequiredLib}" if DEBUG
|
|
122
|
+
|
|
123
|
+
xRequiredFile = getLibraryPath( xRequiredLib )
|
|
124
|
+
if xRequiredFile
|
|
125
|
+
unless @lxStops.include?(xRequiredLib)
|
|
126
|
+
@hxNodes[xRequiredLib] = gv_newNode( xRequiredLib )
|
|
127
|
+
parseFile( xRequiredFile, xFile, xRequiredLib )
|
|
128
|
+
else
|
|
129
|
+
@hxNodes[xRequiredLib] = gv_newNode( xRequiredLib, "invhouse", "deepskyblue" )
|
|
130
|
+
end
|
|
131
|
+
else
|
|
132
|
+
if getLibraryPath( xRequiredLib, ["so", "bundle", "dll"] ) == nil
|
|
133
|
+
@hxNodes[xRequiredLib] = gv_newNode( xRequiredLib, "box", "red" )
|
|
134
|
+
else
|
|
135
|
+
@hxNodes[xRequiredLib] = gv_newNode( xRequiredLib, "box", "grey" )
|
|
136
|
+
end
|
|
137
|
+
end
|
|
138
|
+
|
|
139
|
+
end
|
|
140
|
+
|
|
141
|
+
puts " + Edge #{xLib} -> #{xRequiredLib}" if DEBUG
|
|
142
|
+
unless @hxEdge.include?( "#{@hxNodes[xLib].id}-#{@hxNodes[xRequiredLib].id}" )
|
|
143
|
+
@oGraph.add_edges( @hxNodes[xLib], @hxNodes[xRequiredLib] )
|
|
144
|
+
@hxEdge << "#{@hxNodes[xLib].id}-#{@hxNodes[xRequiredLib].id}"
|
|
145
|
+
end
|
|
146
|
+
end
|
|
147
|
+
end
|
|
148
|
+
|
|
149
|
+
end
|
|
150
|
+
|
|
151
|
+
end
|
|
152
|
+
|
|
153
|
+
def usage
|
|
154
|
+
puts "usage: ruby2gv [-Tformat] [-ofile] [-h] [-V] script"
|
|
155
|
+
puts "-T, --output-format format Output format (default: PNG)"
|
|
156
|
+
puts "-o, --output-file file Output file (default: STDOUT)"
|
|
157
|
+
puts "-p, --path Graphviz path"
|
|
158
|
+
puts "-u, --use PROGRAM Program to use (default: dot)"
|
|
159
|
+
puts "-s, --stop LIB[,LIB, ...] Stop on libs"
|
|
160
|
+
puts "-V, --version Show version"
|
|
161
|
+
puts "-h, --help Show this usage message"
|
|
162
|
+
end
|
|
163
|
+
|
|
164
|
+
def version
|
|
165
|
+
puts "Ruby2GraphViz v#{GraphViz::Constants::RGV_VERSION}, (c)2005, 2009, 2010 Gregoire Lejeune <gregoire.lejeune@free.fr>"
|
|
166
|
+
puts ""
|
|
167
|
+
puts "This program is free software; you can redistribute it and/or modify"
|
|
168
|
+
puts "it under the terms of the GNU General Public License as published by"
|
|
169
|
+
puts "the Free Software Foundation; either version 2 of the License, or"
|
|
170
|
+
puts "(at your option) any later version."
|
|
171
|
+
puts ""
|
|
172
|
+
puts "This program is distributed in the hope that it will be useful,"
|
|
173
|
+
puts "but WITHOUT ANY WARRANTY; without even the implied warranty of"
|
|
174
|
+
puts "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the"
|
|
175
|
+
puts "GNU General Public License for more details."
|
|
176
|
+
puts ""
|
|
177
|
+
puts "You should have received a copy of the GNU General Public License"
|
|
178
|
+
puts "along with this program; if not, write to the Free Software"
|
|
179
|
+
puts "Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA"
|
|
180
|
+
end
|
|
181
|
+
|
|
182
|
+
xOutFormat = "png"
|
|
183
|
+
xOutFile = nil
|
|
184
|
+
xGVPath = ""
|
|
185
|
+
xUse = "dot"
|
|
186
|
+
xStops = []
|
|
187
|
+
|
|
188
|
+
oOpt = GetoptLong.new(
|
|
189
|
+
['--output-format', '-T', GetoptLong::REQUIRED_ARGUMENT],
|
|
190
|
+
['--output-file', '-o', GetoptLong::REQUIRED_ARGUMENT],
|
|
191
|
+
['--path', '-p', GetoptLong::REQUIRED_ARGUMENT],
|
|
192
|
+
['--use', '-u', GetoptLong::REQUIRED_ARGUMENT],
|
|
193
|
+
['--stop', '-s', GetoptLong::REQUIRED_ARGUMENT],
|
|
194
|
+
['--help', '-h', GetoptLong::NO_ARGUMENT],
|
|
195
|
+
['--version', '-V', GetoptLong::NO_ARGUMENT]
|
|
196
|
+
)
|
|
197
|
+
|
|
198
|
+
begin
|
|
199
|
+
oOpt.each_option do |xOpt, xValue|
|
|
200
|
+
case xOpt
|
|
201
|
+
when '--output-format'
|
|
202
|
+
xOutFormat = xValue
|
|
203
|
+
when '--output-file'
|
|
204
|
+
xOutFile = xValue
|
|
205
|
+
when '--path'
|
|
206
|
+
xGVPath = xValue
|
|
207
|
+
when '--use'
|
|
208
|
+
xUse = xValue
|
|
209
|
+
when '--stop'
|
|
210
|
+
xStops = xValue.split( "," ).map{ |x| x.strip }
|
|
211
|
+
when '--help'
|
|
212
|
+
usage( )
|
|
213
|
+
exit
|
|
214
|
+
when '--version'
|
|
215
|
+
version( )
|
|
216
|
+
exit
|
|
217
|
+
end
|
|
218
|
+
end
|
|
219
|
+
rescue GetoptLong::InvalidOption
|
|
220
|
+
usage( )
|
|
221
|
+
exit
|
|
222
|
+
end
|
|
223
|
+
|
|
224
|
+
xFile = ARGV[0]
|
|
225
|
+
|
|
226
|
+
if xFile.nil?
|
|
227
|
+
usage( )
|
|
228
|
+
exit
|
|
229
|
+
end
|
|
230
|
+
|
|
231
|
+
o = Rb2Gv::new( xGVPath, xUse, xStops )
|
|
232
|
+
o.parse( xFile )
|
|
233
|
+
result = o.out( xOutFormat, xOutFile )
|
|
234
|
+
puts result unless result.nil?
|
data/bin/xml2gv
ADDED
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
# Copyright (C) 2005 - 2012 Gregoire Lejeune <gregoire.lejeune@free.fr>
|
|
3
|
+
#
|
|
4
|
+
# This program is free software; you can redistribute it and/or modify
|
|
5
|
+
# it under the terms of the GNU General Public License as published by
|
|
6
|
+
# the Free Software Foundation; either version 2 of the License, or
|
|
7
|
+
# (at your option) any later version.
|
|
8
|
+
#
|
|
9
|
+
# This program is distributed in the hope that it will be useful,
|
|
10
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
11
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
12
|
+
# GNU General Public License for more details.
|
|
13
|
+
#
|
|
14
|
+
# You should have received a copy of the GNU General Public License
|
|
15
|
+
# along with this program; if not, write to the Free Software
|
|
16
|
+
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
17
|
+
|
|
18
|
+
require 'rubygems'
|
|
19
|
+
require 'getoptlong'
|
|
20
|
+
require 'graphviz/xml'
|
|
21
|
+
|
|
22
|
+
def usage
|
|
23
|
+
puts "usage: xml2gv [-Tformat] [-ofile] [-h] [-V] script"
|
|
24
|
+
puts "-T, --output-format format Output format (default: PNG)"
|
|
25
|
+
puts "-o, --output-file file Output file (default: STDOUT)"
|
|
26
|
+
puts "-p, --path Graphviz path"
|
|
27
|
+
puts "-u, --use PROGRAM Program to use (default: dot)"
|
|
28
|
+
puts "-V, --version Show version"
|
|
29
|
+
puts "-h, --help Show this usage message"
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
def version
|
|
33
|
+
puts "XML2GraphViz v#{GraphViz::Constants::RGV_VERSION}, (c)2010 Gregoire Lejeune <gregoire.lejeune@free.fr>"
|
|
34
|
+
puts ""
|
|
35
|
+
puts "This program is free software; you can redistribute it and/or modify"
|
|
36
|
+
puts "it under the terms of the GNU General Public License as published by"
|
|
37
|
+
puts "the Free Software Foundation; either version 2 of the License, or"
|
|
38
|
+
puts "(at your option) any later version."
|
|
39
|
+
puts ""
|
|
40
|
+
puts "This program is distributed in the hope that it will be useful,"
|
|
41
|
+
puts "but WITHOUT ANY WARRANTY; without even the implied warranty of"
|
|
42
|
+
puts "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the"
|
|
43
|
+
puts "GNU General Public License for more details."
|
|
44
|
+
puts ""
|
|
45
|
+
puts "You should have received a copy of the GNU General Public License"
|
|
46
|
+
puts "along with this program; if not, write to the Free Software"
|
|
47
|
+
puts "Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA"
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
xOutFormat = "png"
|
|
51
|
+
xOutFile = nil
|
|
52
|
+
xGVPath = ""
|
|
53
|
+
xUse = "dot"
|
|
54
|
+
|
|
55
|
+
oOpt = GetoptLong.new(
|
|
56
|
+
['--output-format', '-T', GetoptLong::REQUIRED_ARGUMENT],
|
|
57
|
+
['--output-file', '-o', GetoptLong::REQUIRED_ARGUMENT],
|
|
58
|
+
['--path', '-p', GetoptLong::REQUIRED_ARGUMENT],
|
|
59
|
+
['--use', '-u', GetoptLong::REQUIRED_ARGUMENT],
|
|
60
|
+
['--help', '-h', GetoptLong::NO_ARGUMENT],
|
|
61
|
+
['--version', '-V', GetoptLong::NO_ARGUMENT]
|
|
62
|
+
)
|
|
63
|
+
|
|
64
|
+
begin
|
|
65
|
+
oOpt.each_option do |xOpt, xValue|
|
|
66
|
+
case xOpt
|
|
67
|
+
when '--output-format'
|
|
68
|
+
xOutFormat = xValue
|
|
69
|
+
when '--output-file'
|
|
70
|
+
xOutFile = xValue
|
|
71
|
+
when '--path'
|
|
72
|
+
xGVPath = xValue
|
|
73
|
+
when '--use'
|
|
74
|
+
xUse = xValue
|
|
75
|
+
when '--help'
|
|
76
|
+
usage( )
|
|
77
|
+
exit
|
|
78
|
+
when '--version'
|
|
79
|
+
version( )
|
|
80
|
+
exit
|
|
81
|
+
end
|
|
82
|
+
end
|
|
83
|
+
rescue GetoptLong::InvalidOption
|
|
84
|
+
usage( )
|
|
85
|
+
exit
|
|
86
|
+
end
|
|
87
|
+
|
|
88
|
+
xFile = ARGV[0]
|
|
89
|
+
|
|
90
|
+
if xFile.nil?
|
|
91
|
+
usage( )
|
|
92
|
+
exit
|
|
93
|
+
end
|
|
94
|
+
|
|
95
|
+
gvxml = GraphViz::XML::new( xFile, :text => true, :attrs => true )
|
|
96
|
+
gvxml.graph.output( xOutFormat => xOutFile, :path => xGVPath )
|