ruby-graphviz_c 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (184) hide show
  1. checksums.yaml +7 -0
  2. data/.gemrc +0 -0
  3. data/.gitignore +9 -0
  4. data/.travis.yml +7 -0
  5. data/AUTHORS.rdoc +33 -0
  6. data/CHANGELOG.rdoc +287 -0
  7. data/COPYING.rdoc +133 -0
  8. data/Gemfile +4 -0
  9. data/README.rdoc +206 -0
  10. data/Rakefile +71 -0
  11. data/bin/dot2ruby +91 -0
  12. data/bin/gem2gv +165 -0
  13. data/bin/git2gv +167 -0
  14. data/bin/ruby2gv +234 -0
  15. data/bin/xml2gv +96 -0
  16. data/examples/dot/JSP.dot +52 -0
  17. data/examples/dot/balanced.dot +36 -0
  18. data/examples/dot/cluster.dot +30 -0
  19. data/examples/dot/dotgraph.dot +28 -0
  20. data/examples/dot/fsm.dot +20 -0
  21. data/examples/dot/genetic.dot +118 -0
  22. data/examples/dot/hello.dot +1 -0
  23. data/examples/dot/hello_test.rb +33 -0
  24. data/examples/dot/lion_share.dot +103 -0
  25. data/examples/dot/prof.dot +150 -0
  26. data/examples/dot/psg.dot +28 -0
  27. data/examples/dot/rank.dot +6 -0
  28. data/examples/dot/sdh.dot +284 -0
  29. data/examples/dot/siblings.dot +492 -0
  30. data/examples/dot/so-sample001.gv +30 -0
  31. data/examples/dot/so-sample002.gv +33 -0
  32. data/examples/dot/so-sample003.gv +45 -0
  33. data/examples/dot/test.dot +17 -0
  34. data/examples/dot/test_parse.rb +13 -0
  35. data/examples/dot/this_crach_with_dot_2.20.dot +24 -0
  36. data/examples/dot/unix.dot +104 -0
  37. data/examples/graphml/attributes.ext.graphml +12 -0
  38. data/examples/graphml/attributes.graphml +40 -0
  39. data/examples/graphml/cluster.graphml +75 -0
  40. data/examples/graphml/failed_graph.graphml +461 -0
  41. data/examples/graphml/hyper.graphml +29 -0
  42. data/examples/graphml/nested.graphml +54 -0
  43. data/examples/graphml/port.graphml +32 -0
  44. data/examples/graphml/simple.graphml +30 -0
  45. data/examples/hello.png +0 -0
  46. data/examples/rgv/rgv.ps +125 -0
  47. data/examples/rgv/test_rgv.rb +12 -0
  48. data/examples/sample01.rb +32 -0
  49. data/examples/sample02.rb +42 -0
  50. data/examples/sample03.rb +31 -0
  51. data/examples/sample04.rb +22 -0
  52. data/examples/sample05.rb +32 -0
  53. data/examples/sample06.rb +46 -0
  54. data/examples/sample07.rb +23 -0
  55. data/examples/sample08.rb +34 -0
  56. data/examples/sample09.rb +50 -0
  57. data/examples/sample10.rb +50 -0
  58. data/examples/sample11.rb +42 -0
  59. data/examples/sample12.rb +55 -0
  60. data/examples/sample13.rb +48 -0
  61. data/examples/sample14.rb +44 -0
  62. data/examples/sample15.rb +25 -0
  63. data/examples/sample16.rb +8 -0
  64. data/examples/sample17.rb +92 -0
  65. data/examples/sample18.rb +24 -0
  66. data/examples/sample19.rb +59 -0
  67. data/examples/sample20.rb +47 -0
  68. data/examples/sample21.rb +12 -0
  69. data/examples/sample22.rb +10 -0
  70. data/examples/sample23.rb +11 -0
  71. data/examples/sample24.rb +11 -0
  72. data/examples/sample25.rb +11 -0
  73. data/examples/sample26.rb +8 -0
  74. data/examples/sample27.rb +8 -0
  75. data/examples/sample28.rb +12 -0
  76. data/examples/sample29.rb +8 -0
  77. data/examples/sample30.rb +12 -0
  78. data/examples/sample31.rb +10 -0
  79. data/examples/sample32.rb +14 -0
  80. data/examples/sample33.rb +43 -0
  81. data/examples/sample34.rb +29 -0
  82. data/examples/sample35.rb +43 -0
  83. data/examples/sample36.rb +35 -0
  84. data/examples/sample37.rb +87 -0
  85. data/examples/sample38.rb +12 -0
  86. data/examples/sample39.rb +11 -0
  87. data/examples/sample40.rb +17 -0
  88. data/examples/sample41.rb +8 -0
  89. data/examples/sample42.rb +35 -0
  90. data/examples/sample43.rb +26 -0
  91. data/examples/sample44.rb +97 -0
  92. data/examples/sample45.rb +24 -0
  93. data/examples/sample46.rb +43 -0
  94. data/examples/sample47.rb +7 -0
  95. data/examples/sample48.rb +62 -0
  96. data/examples/sample49.rb +10 -0
  97. data/examples/sample50.rb +215 -0
  98. data/examples/sample51.rb +37 -0
  99. data/examples/sample52.rb +62 -0
  100. data/examples/sample53.rb +26 -0
  101. data/examples/sample54.rb +26 -0
  102. data/examples/sample55.rb +9 -0
  103. data/examples/sample56.rb +10 -0
  104. data/examples/sample57.rb +8 -0
  105. data/examples/sample58.rb +33 -0
  106. data/examples/sample59.rb +14 -0
  107. data/examples/sample60.rb +12 -0
  108. data/examples/sample61.rb +12 -0
  109. data/examples/sample62.rb +24 -0
  110. data/examples/sample63.rb +32 -0
  111. data/examples/sample64.rb +31 -0
  112. data/examples/sample65.rb +9 -0
  113. data/examples/sample66.rb +4 -0
  114. data/examples/sample67.rb +10 -0
  115. data/examples/sample68.rb +27 -0
  116. data/examples/sample69.rb +23 -0
  117. data/examples/sample70.rb +9 -0
  118. data/examples/sample99.rb +70 -0
  119. data/examples/sdlshapes/README +2 -0
  120. data/examples/sdlshapes/sdl.ps +655 -0
  121. data/examples/sdlshapes/sdlshapes.dot +78 -0
  122. data/examples/test.xml +26 -0
  123. data/examples/theory/pert.rb +47 -0
  124. data/examples/theory/tests.rb +87 -0
  125. data/lib/ext/gvpr/dot2ruby.g +185 -0
  126. data/lib/graphviz/attrs.rb +73 -0
  127. data/lib/graphviz/constants.rb +294 -0
  128. data/lib/graphviz/core_ext.rb +64 -0
  129. data/lib/graphviz/dot2ruby.rb +59 -0
  130. data/lib/graphviz/dot_script.rb +109 -0
  131. data/lib/graphviz/dsl.rb +67 -0
  132. data/lib/graphviz/edge.rb +197 -0
  133. data/lib/graphviz/elements.rb +39 -0
  134. data/lib/graphviz/ext.rb +17 -0
  135. data/lib/graphviz/family_tree/couple.rb +63 -0
  136. data/lib/graphviz/family_tree/generation.rb +39 -0
  137. data/lib/graphviz/family_tree/person.rb +120 -0
  138. data/lib/graphviz/family_tree/sibling.rb +13 -0
  139. data/lib/graphviz/family_tree.rb +118 -0
  140. data/lib/graphviz/graphml.rb +268 -0
  141. data/lib/graphviz/math/matrix.rb +221 -0
  142. data/lib/graphviz/node.rb +160 -0
  143. data/lib/graphviz/nothugly/nothugly.xsl +321 -0
  144. data/lib/graphviz/nothugly.rb +63 -0
  145. data/lib/graphviz/theory.rb +321 -0
  146. data/lib/graphviz/types/arrow_type.rb +32 -0
  147. data/lib/graphviz/types/color.rb +58 -0
  148. data/lib/graphviz/types/color_list.rb +24 -0
  149. data/lib/graphviz/types/esc_string.rb +20 -0
  150. data/lib/graphviz/types/gv_bool.rb +49 -0
  151. data/lib/graphviz/types/gv_double.rb +32 -0
  152. data/lib/graphviz/types/html_string.rb +18 -0
  153. data/lib/graphviz/types/lbl_string.rb +22 -0
  154. data/lib/graphviz/types/rect.rb +35 -0
  155. data/lib/graphviz/types/spline_type.rb +77 -0
  156. data/lib/graphviz/types.rb +22 -0
  157. data/lib/graphviz/utils/colors.rb +1018 -0
  158. data/lib/graphviz/utils.rb +70 -0
  159. data/lib/graphviz/xml.rb +119 -0
  160. data/lib/graphviz.rb +967 -0
  161. data/lib/ruby-graphviz.rb +1 -0
  162. data/man/dot2ruby.1 +66 -0
  163. data/man/dot2ruby.1.ronn +55 -0
  164. data/man/gem2gv.1 +60 -0
  165. data/man/gem2gv.1.ronn +47 -0
  166. data/man/git2gv.1 +48 -0
  167. data/man/git2gv.1.ronn +40 -0
  168. data/man/ruby2gv.1 +60 -0
  169. data/man/ruby2gv.1.ronn +47 -0
  170. data/man/xml2gv.1 +48 -0
  171. data/man/xml2gv.1.ronn +39 -0
  172. data/ruby-graphviz.gemspec +47 -0
  173. data/setup.rb +1585 -0
  174. data/test/helper.rb +13 -0
  175. data/test/support.rb +95 -0
  176. data/test/test_dot_script.rb +47 -0
  177. data/test/test_examples.rb +151 -0
  178. data/test/test_graph.rb +115 -0
  179. data/test/test_search.rb +29 -0
  180. data/test/test_subgraph.rb +27 -0
  181. data/test/test_theory.rb +98 -0
  182. data/test/test_types.rb +65 -0
  183. data/test/test_utils_colors.rb +52 -0
  184. metadata +301 -0
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in ruby-graphviz.gemspec
4
+ gemspec
data/README.rdoc ADDED
@@ -0,0 +1,206 @@
1
+ This is just a fork to get a fixed version of this gem. I would prefer the original author to do this, but he seems to have abandoned this gem and I need this fix.
2
+
3
+ This is the original README with original author etc. All respect is to him.
4
+
5
+ = Ruby/GraphViz
6
+
7
+ {<img src="https://secure.travis-ci.org/glejeune/Ruby-Graphviz.png" />}[http://travis-ci.org/glejeune/Ruby-Graphviz]
8
+ {<img src="https://badge.fury.io/rb/ruby-graphviz.png" alt="Gem Version" />}[http://badge.fury.io/rb/ruby-graphviz]
9
+
10
+ Copyright (C) 2004-2013 Gregoire Lejeune
11
+
12
+ * Doc : http://rdoc.info/projects/glejeune/Ruby-Graphviz
13
+ * Sources : http://github.com/glejeune/Ruby-Graphviz
14
+ * <b>NEW</b> - Mailing List : http://groups.google.com/group/ruby-graphviz
15
+
16
+ == DESCRIPTION
17
+
18
+ Interface to the GraphViz graphing tool
19
+
20
+ == TODO
21
+
22
+ * New FamilyTree
23
+
24
+ == SYNOPSIS
25
+
26
+ A basic example
27
+
28
+ require 'graphviz'
29
+
30
+ # Create a new graph
31
+ g = GraphViz.new( :G, :type => :digraph )
32
+
33
+ # Create two nodes
34
+ hello = g.add_nodes( "Hello" )
35
+ world = g.add_nodes( "World" )
36
+
37
+ # Create an edge between the two nodes
38
+ g.add_edges( hello, world )
39
+
40
+ # Generate output image
41
+ g.output( :png => "hello_world.png" )
42
+
43
+ The same but with a block
44
+
45
+ require 'graphviz'
46
+
47
+ GraphViz::new( :G, :type => :digraph ) { |g|
48
+ g.world( :label => "World" ) << g.hello( :label => "Hello" )
49
+ }.output( :png => "hello_world.png" )
50
+
51
+ Or with the DSL
52
+
53
+ require 'graphviz/dsl'
54
+ digraph :G do
55
+ world[:label => "World"] << hello[:label => "Hello"]
56
+
57
+ output :png => "hello_world.png"
58
+ end
59
+
60
+ Create a graph from a file
61
+
62
+ require 'graphviz'
63
+
64
+ # In this example, hello.dot is :
65
+ # digraph G {Hello->World;}
66
+
67
+ GraphViz.parse( "hello.dot", :path => "/usr/local/bin" ) { |g|
68
+ g.get_node("Hello") { |n|
69
+ n[:label] = "Bonjour"
70
+ }
71
+ g.get_node("World") { |n|
72
+ n[:label] = "Le Monde"
73
+ }
74
+ }.output(:png => "sample.png")
75
+
76
+ GraphML[http://graphml.graphdrawing.org/] support
77
+
78
+ require 'graphviz/graphml'
79
+
80
+ g = GraphViz::GraphML.new( "graphml/cluster.graphml" )
81
+ g.graph.output( :path => "/usr/local/bin", :png => "#{$0}.png" )
82
+
83
+
84
+ == TOOLS
85
+
86
+ Ruby/GraphViz also includes :
87
+
88
+ * <tt>ruby2gv</tt>, a simple tool that allows you to create a dependency graph from a ruby script. Example : http://drp.ly/dShaZ
89
+
90
+ ruby2gv -Tpng -oruby2gv.png ruby2gv
91
+
92
+ * <tt>gem2gv</tt>, a tool that allows you to create a dependency graph between gems. Example : http://drp.ly/dSj9Y
93
+
94
+ gem2gv -Tpng -oruby-graphviz.png ruby-graphviz
95
+
96
+ * <tt>dot2ruby</tt>, a tool that allows you to create a ruby script from a graphviz script
97
+
98
+ $ cat hello.dot
99
+ digraph G {Hello->World;}
100
+
101
+ $ dot2ruby hello.dot
102
+ # This code was generated by dot2ruby.g
103
+
104
+ require 'rubygems'
105
+ require 'graphviz'
106
+ graph_g = GraphViz.digraph( "G" ) { |graph_g|
107
+ graph_g[:bb] = '0,0,70,108'
108
+ node_hello = graph_g.add_nodes( "Hello", :height => '0.5', :label => '\N', :pos => '35,90', :width => '0.88889' )
109
+ graph_g.add_edges( "Hello", "World", :pos => 'e,35,36.413 35,71.831 35,64.131 35,54.974 35,46.417' )
110
+ node_world = graph_g.add_nodes( "World", :height => '0.5', :label => '\N', :pos => '35,18', :width => '0.97222' )
111
+ }
112
+ puts graph_g.output( :canon => String )
113
+
114
+ * <tt>git2gv</tt>, a tool that allows you to show your git commits : http://dl.dropbox.com/u/72629/ruby-graphviz-git.svg
115
+
116
+ * <tt>xml2gv</tt>, a tool that allows you to show a xml file as graph.
117
+
118
+ == GRAPH THEORY
119
+
120
+ require 'graphviz'
121
+ require 'graphviz/theory'
122
+
123
+ g = GraphViz.new( :G ) { ... }
124
+
125
+ t = GraphViz::Theory.new( g )
126
+
127
+ puts "Adjancy matrix : "
128
+ puts t.adjancy_matrix
129
+
130
+ puts "Symmetric ? #{t.symmetric?}"
131
+
132
+ puts "Incidence matrix :"
133
+ puts t.incidence_matrix
134
+
135
+ g.each_node do |name, node|
136
+ puts "Degree of node `#{name}' = #{t.degree(node)}"
137
+ end
138
+
139
+ puts "Laplacian matrix :"
140
+ puts t.laplacian_matrix
141
+
142
+ puts "Dijkstra between a and f"
143
+ r = t.moore_dijkstra(g.a, g.f)
144
+ if r.nil?
145
+ puts "No way !"
146
+ else
147
+ print "\tPath : "; p r[:path]
148
+ puts "\tDistance : #{r[:distance]}"
149
+ end
150
+
151
+ print "Ranges : "
152
+ rr = t.range
153
+ p rr
154
+ puts "Your graph contains circuits" if rr.include?(nil)
155
+
156
+ puts "Critical path : "
157
+ rrr = t.critical_path
158
+ print "\tPath "; p rrr[:path]
159
+ puts "\tDistance : #{rrr[:distance]}"
160
+
161
+ == INSTALLATION
162
+
163
+ sudo gem install ruby-graphviz
164
+
165
+ You also need to install GraphViz[http://www.graphviz.org]
166
+
167
+ On *Windows* you also need to install win32-open3. This is not an absolute requirement.
168
+
169
+ == LICENCES
170
+
171
+ === Ruby/GraphViz
172
+
173
+ Ruby/GraphViz is freely distributable according to the terms of the
174
+ GNU General Public License (see the file 'COPYING').
175
+
176
+ This program is distributed without any warranty. See the file
177
+ 'COPYING' for details.
178
+
179
+ GNU General Public Licence: http://en.wikipedia.org/wiki/Gpl
180
+
181
+ === nothugly.xsl
182
+
183
+ By Vidar Hokstad and Ryan Shea; Contributions by Jonas Tingborn,
184
+ Earl Cummings, Michael Kennedy (Graphviz 2.20.2 compatibility, bug fixes, testing, lots of gradients)
185
+
186
+ Copyright (c) 2009 Vidar Hokstad
187
+
188
+ Permission is hereby granted, free of charge, to any person obtaining a copy
189
+ of this software and associated documentation files (the "Software"), to deal
190
+ in the Software without restriction, including without limitation the rights
191
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
192
+ copies of the Software, and to permit persons to whom the Software is
193
+ furnished to do so, subject to the following conditions:
194
+
195
+ The above copyright notice and this permission notice shall be included in
196
+ all copies or substantial portions of the Software.
197
+
198
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
199
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
200
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
201
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
202
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
203
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
204
+ THE SOFTWARE.
205
+
206
+ MIT license: http://en.wikipedia.org/wiki/MIT_License
data/Rakefile ADDED
@@ -0,0 +1,71 @@
1
+ $:.unshift( "lib" )
2
+ require "graphviz/constants"
3
+
4
+ require 'rubygems'
5
+ require 'rake/clean'
6
+ require 'bundler'
7
+ require 'rubygems/package_task'
8
+ require 'rdoc/task'
9
+ require 'rake/testtask'
10
+ require 'fileutils'
11
+ require 'open-uri'
12
+ include FileUtils
13
+
14
+ CLEAN.include ['**/.*.sw?', '*.gem', '.config', 'test/test.log']
15
+ RDOC_OPTS = ['--quiet', '--title', "Ruby/GraphViz, the Documentation",
16
+ "--opname", "index.html",
17
+ "--line-numbers",
18
+ "--main", "README.rdoc"]
19
+
20
+ desc "Packages up Ruby/GraphViz."
21
+ task :default => [:test, :package]
22
+ task :package => [:clean]
23
+
24
+ task :doc => :rdoc
25
+
26
+ RDoc::Task.new do |rdoc|
27
+ rdoc.rdoc_dir = 'doc/rdoc'
28
+ rdoc.options += RDOC_OPTS
29
+ rdoc.main = "README.rdoc"
30
+ rdoc.title = "Ruby/GraphViz, the Documentation"
31
+ rdoc.rdoc_files.add ['README.rdoc', 'CHANGELOG.rdoc', 'AUTHORS.rdoc', 'COPYING.rdoc',
32
+ 'lib/graphviz.rb',
33
+ 'lib/graphviz/node.rb',
34
+ 'lib/graphviz/edge.rb',
35
+ 'lib/graphviz/constants.rb',
36
+ 'lib/graphviz/xml.rb',
37
+ 'lib/graphviz/graphml.rb',
38
+ 'lib/graphviz/family_tree.rb',
39
+ 'lib/graphviz/family_tree/couple.rb',
40
+ 'lib/graphviz/family_tree/generation.rb',
41
+ 'lib/graphviz/family_tree/person.rb',
42
+ 'lib/graphviz/family_tree/sibling.rb']
43
+ end
44
+
45
+ Rake::TestTask.new(:test) do |t|
46
+ t.libs << 'lib' << 'test'
47
+ t.verbose = true
48
+
49
+ require 'graphviz/utils'
50
+ include GraphViz::Utils
51
+ test_files = FileList['test/test_*.rb']
52
+ test_files.exclude("test/test_examples.rb") unless find_executable("dot", nil)
53
+
54
+ p test_files
55
+ t.test_files = test_files
56
+ end
57
+
58
+ desc "Generate man pages"
59
+ task :man do
60
+ unless RUBY_PLATFORM == 'java'
61
+ require 'ronn'
62
+ chdir 'man' do
63
+ sh "ronn -r *.ronn"
64
+ end
65
+ else
66
+ puts "Can't generate man pages with JRuby"
67
+ end
68
+ end
69
+
70
+ Bundler::GemHelper.install_tasks
71
+
data/bin/dot2ruby ADDED
@@ -0,0 +1,91 @@
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 'graphviz/constants'
20
+ require 'graphviz/dot2ruby'
21
+ require 'getoptlong'
22
+
23
+ def usage
24
+ puts "usage: dot2ruby [-ofile] [-Tformat] [-h] [-V] script"
25
+ puts "-o, --output-file file Output file"
26
+ puts "-T, --output-format format Output format (default: nil)"
27
+ puts "-p, --path Graphviz path"
28
+ puts "-V, --version Show version"
29
+ puts "-h, --help Show this usage message"
30
+ end
31
+
32
+ def version
33
+ puts "Dot2Ruby 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
+ xOutFile = nil
51
+ xGVPath = nil
52
+ xOutFormat = nil
53
+
54
+ oOpt = GetoptLong.new(
55
+ ['--output-file', '-o', GetoptLong::REQUIRED_ARGUMENT],
56
+ ['--output-format', '-T', GetoptLong::REQUIRED_ARGUMENT],
57
+ ['--path', '-p', GetoptLong::REQUIRED_ARGUMENT],
58
+ ['--help', '-h', GetoptLong::NO_ARGUMENT],
59
+ ['--version', '-V', GetoptLong::NO_ARGUMENT]
60
+ )
61
+
62
+ begin
63
+ oOpt.each_option do |xOpt, xValue|
64
+ case xOpt
65
+ when '--output-file'
66
+ xOutFile = xValue
67
+ when '--output-format'
68
+ xOutFormat = xValue
69
+ when '--path'
70
+ xGVPath = xValue
71
+ when '--help'
72
+ usage( )
73
+ exit
74
+ when '--version'
75
+ version( )
76
+ exit
77
+ end
78
+ end
79
+ rescue GetoptLong::InvalidOption
80
+ usage( )
81
+ exit
82
+ end
83
+
84
+ xFile = ARGV[0]
85
+
86
+ if xFile.nil?
87
+ usage( )
88
+ exit
89
+ end
90
+
91
+ Dot2Ruby::new( xGVPath, xOutFile, xOutFormat ).run( xFile )
data/bin/gem2gv ADDED
@@ -0,0 +1,165 @@
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 'graphviz'
20
+ require 'getoptlong'
21
+
22
+ class Gem2Gv
23
+ def initialize( xGVPath, xUse )
24
+ @oGraph = GraphViz::new( :G, :path => xGVPath, :use => xUse )
25
+
26
+ @nodes = []
27
+ @name = 'gem2gv'
28
+ end
29
+
30
+ def out( xFormat = "dot", xFile = nil )
31
+ if xFile.nil?
32
+ @oGraph.output( xFormat => String )
33
+ else
34
+ @oGraph.output( xFormat => xFile )
35
+ end
36
+ end
37
+
38
+ def go( gemName, version = ">0" )
39
+ nodes = getDependency(gemName, version)
40
+
41
+ createEdges( gemName, version, nodes )
42
+
43
+ nodes.each do |node|
44
+ unless @nodes.include?(node)
45
+ @nodes << node
46
+ go( node[:name], node[:version] )
47
+ end
48
+ end
49
+ end
50
+
51
+ def getDependency( gemName, version = ">0" )
52
+ nodes = []
53
+
54
+ dependency = Gem::Dependency.new( gemName, version )
55
+ fetcher = Gem::SpecFetcher.fetcher
56
+
57
+ fetcher.find_matching(dependency).each do |spec_tuple, source_uri|
58
+ spec = fetcher.fetch_spec spec_tuple, URI.parse(source_uri)
59
+
60
+ spec.dependencies.each do |dep|
61
+ #nodes << { :name => dep.name, :version => dep.version_requirements.to_s} unless nodes.include?({ :name => dep.name, :version => dep.version_requirements.to_s})
62
+ nodes << { :name => dep.name, :version => ">0" } unless nodes.include?({ :name => dep.name, :version => ">0" })
63
+ end
64
+ end
65
+
66
+ return nodes
67
+ end
68
+
69
+ def getNode( name, version )
70
+ #nodeName = "#{name}#{version}"
71
+ #nodeLabel = "#{name}\n#{version}"
72
+ nodeName = "#{name}"
73
+ nodeLabel = "#{name}"
74
+ return @oGraph.get_node(nodeName) || @oGraph.add_nodes( nodeName, "label" => nodeLabel )
75
+ end
76
+
77
+ def createEdges( gemName, version, nodes )
78
+ nodeA = getNode( gemName, version )
79
+
80
+ nodes.each do |node|
81
+ nodeB = getNode( node[:name], node[:version] )
82
+ @oGraph.add_edges( nodeA, nodeB )
83
+ end
84
+ end
85
+ end
86
+
87
+ def usage
88
+ puts "usage: gem2gv [-Tformat] [-ofile] [-h] [-V] gemname"
89
+ puts "-T, --output-format format Output format (default: PNG)"
90
+ puts "-o, --output-file file Output file (default: STDOUT)"
91
+ puts "-p, --path Graphviz path"
92
+ puts "-u, --use PROGRAM Program to use (default: dot)"
93
+ puts "-s, --stop LIB[,LIB, ...] Stop on libs"
94
+ puts "-V, --version Show version"
95
+ puts "-h, --help Show this usage message"
96
+ end
97
+
98
+ def version
99
+ puts "Gem2GraphViz v#{GraphViz::Constants::RGV_VERSION}, (c)2010 Gregoire Lejeune <gregoire.lejeune@free.fr>"
100
+ puts ""
101
+ puts "This program is free software; you can redistribute it and/or modify"
102
+ puts "it under the terms of the GNU General Public License as published by"
103
+ puts "the Free Software Foundation; either version 2 of the License, or"
104
+ puts "(at your option) any later version."
105
+ puts ""
106
+ puts "This program is distributed in the hope that it will be useful,"
107
+ puts "but WITHOUT ANY WARRANTY; without even the implied warranty of"
108
+ puts "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the"
109
+ puts "GNU General Public License for more details."
110
+ puts ""
111
+ puts "You should have received a copy of the GNU General Public License"
112
+ puts "along with this program; if not, write to the Free Software"
113
+ puts "Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA"
114
+ end
115
+
116
+ xOutFormat = "png"
117
+ xOutFile = nil
118
+ xGVPath = ""
119
+ xUse = "dot"
120
+
121
+ oOpt = GetoptLong.new(
122
+ ['--output-format', '-T', GetoptLong::REQUIRED_ARGUMENT],
123
+ ['--output-file', '-o', GetoptLong::REQUIRED_ARGUMENT],
124
+ ['--path', '-p', GetoptLong::REQUIRED_ARGUMENT],
125
+ ['--use', '-u', GetoptLong::REQUIRED_ARGUMENT],
126
+ ['--help', '-h', GetoptLong::NO_ARGUMENT],
127
+ ['--version', '-V', GetoptLong::NO_ARGUMENT]
128
+ )
129
+
130
+ begin
131
+ oOpt.each_option do |xOpt, xValue|
132
+ case xOpt
133
+ when '--output-format'
134
+ xOutFormat = xValue
135
+ when '--output-file'
136
+ xOutFile = xValue
137
+ when '--path'
138
+ xGVPath = xValue
139
+ when '--use'
140
+ xUse = xValue
141
+ when '--help'
142
+ usage( )
143
+ exit
144
+ when '--version'
145
+ version( )
146
+ exit
147
+ end
148
+ end
149
+ rescue GetoptLong::InvalidOption
150
+ usage( )
151
+ exit
152
+ end
153
+
154
+ xGem = ARGV[0]
155
+
156
+ if xGem.nil?
157
+ usage( )
158
+ exit
159
+ end
160
+
161
+
162
+ g = Gem2Gv.new( xGVPath, xUse )
163
+ g.go( xGem )
164
+ result = g.out( xOutFormat, xOutFile )
165
+ puts result unless result.nil?