puppet 0.24.1 → 0.24.2

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of puppet might be problematic. Click here for more details.

Files changed (266) hide show
  1. data/CHANGELOG +94 -0
  2. data/Rakefile +0 -4
  3. data/bin/puppet +18 -10
  4. data/bin/puppetd +1 -1
  5. data/bin/puppetdoc +14 -4
  6. data/bin/puppetmasterd +1 -1
  7. data/bin/puppetrun +3 -8
  8. data/bin/ralsh +12 -11
  9. data/conf/freebsd/puppetd +1 -1
  10. data/conf/freebsd/puppetmasterd +1 -1
  11. data/conf/gentoo/puppet/puppet.conf +29 -0
  12. data/conf/namespaceauth.conf +20 -0
  13. data/conf/redhat/puppet.spec +4 -1
  14. data/conf/solaris/smf/puppetd.xml +1 -1
  15. data/conf/solaris/smf/puppetmasterd.xml +1 -1
  16. data/conf/suse/puppet.spec +10 -8
  17. data/examples/root/etc/puppet/{puppetmasterd.conf → puppet.conf} +6 -3
  18. data/ext/logcheck/puppet +7 -0
  19. data/ext/puppet-test +28 -5
  20. data/lib/puppet.rb +2 -1
  21. data/lib/puppet/defaults.rb +12 -5
  22. data/lib/puppet/dsl.rb +43 -45
  23. data/lib/puppet/external/{gratr/rdot.rb → dot.rb} +0 -0
  24. data/lib/puppet/external/nagios.rb +50 -0
  25. data/lib/puppet/external/nagios/base.rb +421 -0
  26. data/lib/puppet/external/nagios/parser.rb +816 -0
  27. data/lib/puppet/file_serving/file_base.rb +16 -3
  28. data/lib/puppet/file_serving/metadata.rb +29 -11
  29. data/lib/puppet/indirector/terminus.rb +1 -0
  30. data/lib/puppet/metatype/closure.rb +4 -0
  31. data/lib/puppet/metatype/evaluation.rb +2 -17
  32. data/lib/puppet/metatype/metaparams.rb +1 -1
  33. data/lib/puppet/network.rb +3 -0
  34. data/lib/puppet/network/client.rb +4 -5
  35. data/lib/puppet/network/client/master.rb +10 -7
  36. data/lib/puppet/network/handler/fileserver.rb +22 -45
  37. data/lib/puppet/network/http_pool.rb +3 -0
  38. data/lib/puppet/network/http_server/mongrel.rb +7 -1
  39. data/lib/puppet/network/http_server/webrick.rb +4 -3
  40. data/lib/puppet/network/xmlrpc/client.rb +12 -1
  41. data/lib/puppet/node/catalog.rb +51 -40
  42. data/lib/puppet/parser/ast.rb +27 -49
  43. data/lib/puppet/parser/ast/astarray.rb +5 -24
  44. data/lib/puppet/parser/ast/caseopt.rb +4 -4
  45. data/lib/puppet/parser/ast/casestatement.rb +4 -5
  46. data/lib/puppet/parser/ast/collection.rb +3 -5
  47. data/lib/puppet/parser/ast/collexpr.rb +3 -5
  48. data/lib/puppet/parser/ast/definition.rb +148 -159
  49. data/lib/puppet/parser/ast/else.rb +2 -3
  50. data/lib/puppet/parser/ast/function.rb +3 -10
  51. data/lib/puppet/parser/ast/hostclass.rb +66 -59
  52. data/lib/puppet/parser/ast/ifstatement.rb +4 -5
  53. data/lib/puppet/parser/ast/leaf.rb +6 -6
  54. data/lib/puppet/parser/ast/node.rb +26 -58
  55. data/lib/puppet/parser/ast/resource.rb +5 -7
  56. data/lib/puppet/parser/ast/resource_defaults.rb +2 -4
  57. data/lib/puppet/parser/ast/resource_override.rb +4 -6
  58. data/lib/puppet/parser/ast/resource_reference.rb +2 -4
  59. data/lib/puppet/parser/ast/resourceparam.rb +2 -4
  60. data/lib/puppet/parser/ast/selector.rb +5 -6
  61. data/lib/puppet/parser/ast/tag.rb +2 -4
  62. data/lib/puppet/parser/ast/vardef.rb +3 -4
  63. data/lib/puppet/parser/collector.rb +5 -5
  64. data/lib/puppet/parser/{compile.rb → compiler.rb} +69 -107
  65. data/lib/puppet/parser/functions.rb +3 -3
  66. data/lib/puppet/parser/interpreter.rb +32 -23
  67. data/lib/puppet/parser/lexer.rb +391 -282
  68. data/lib/puppet/parser/parser.rb +5 -4
  69. data/lib/puppet/parser/parser_support.rb +3 -6
  70. data/lib/puppet/parser/resource.rb +24 -36
  71. data/lib/puppet/parser/resource/param.rb +1 -1
  72. data/lib/puppet/parser/resource/reference.rb +7 -3
  73. data/lib/puppet/parser/scope.rb +12 -7
  74. data/lib/puppet/parser/templatewrapper.rb +1 -1
  75. data/lib/puppet/pgraph.rb +9 -98
  76. data/lib/puppet/provider/interface/redhat.rb +65 -65
  77. data/lib/puppet/provider/mount/parsed.rb +1 -1
  78. data/lib/puppet/provider/naginator.rb +55 -0
  79. data/lib/puppet/provider/nameservice/directoryservice.rb +6 -7
  80. data/lib/puppet/provider/package/fink.rb +0 -2
  81. data/lib/puppet/provider/package/gem.rb +9 -5
  82. data/lib/puppet/provider/package/openbsd.rb +1 -1
  83. data/lib/puppet/provider/package/pkgdmg.rb +3 -8
  84. data/lib/puppet/provider/package/portage.rb +4 -4
  85. data/lib/puppet/provider/package/yumhelper.py +8 -6
  86. data/lib/puppet/provider/parsedfile.rb +7 -1
  87. data/lib/puppet/provider/service/debian.rb +2 -0
  88. data/lib/puppet/provider/service/gentoo.rb +4 -0
  89. data/lib/puppet/provider/service/init.rb +1 -1
  90. data/lib/puppet/provider/sshkey/parsed.rb +2 -0
  91. data/lib/puppet/provider/user/useradd.rb +1 -1
  92. data/lib/puppet/rails.rb +4 -0
  93. data/lib/puppet/rails/database/001_add_created_at_to_all_tables.rb +17 -0
  94. data/lib/puppet/rails/fact_value.rb +4 -0
  95. data/lib/puppet/rails/host.rb +1 -2
  96. data/lib/puppet/rails/param_value.rb +4 -0
  97. data/lib/puppet/rails/resource_tag.rb +4 -0
  98. data/lib/puppet/rails/source_file.rb +4 -1
  99. data/lib/puppet/relationship.rb +5 -1
  100. data/lib/puppet/reports/tagmail.rb +12 -1
  101. data/lib/puppet/resource_reference.rb +1 -1
  102. data/lib/puppet/simple_graph.rb +78 -11
  103. data/lib/puppet/sslcertificates.rb +1 -1
  104. data/lib/puppet/sslcertificates/ca.rb +3 -3
  105. data/lib/puppet/transaction.rb +7 -4
  106. data/lib/puppet/transportable.rb +1 -1
  107. data/lib/puppet/type.rb +3 -10
  108. data/lib/puppet/type/cron.rb +18 -0
  109. data/lib/puppet/type/exec.rb +18 -12
  110. data/lib/puppet/type/{pfile.rb → file.rb} +66 -84
  111. data/lib/puppet/type/file/checksum.rb +271 -0
  112. data/lib/puppet/type/{pfile → file}/content.rb +10 -15
  113. data/lib/puppet/type/{pfile → file}/ensure.rb +15 -8
  114. data/lib/puppet/type/{pfile → file}/group.rb +0 -0
  115. data/lib/puppet/type/{pfile → file}/mode.rb +0 -0
  116. data/lib/puppet/type/{pfile → file}/owner.rb +0 -0
  117. data/lib/puppet/type/{pfile → file}/source.rb +34 -48
  118. data/lib/puppet/type/{pfile → file}/target.rb +0 -0
  119. data/lib/puppet/type/{pfile → file}/type.rb +0 -0
  120. data/lib/puppet/type/{pfilebucket.rb → filebucket.rb} +0 -0
  121. data/lib/puppet/type/host.rb +13 -0
  122. data/lib/puppet/type/mailalias.rb +1 -1
  123. data/lib/puppet/type/nagios_command.rb +3 -0
  124. data/lib/puppet/type/nagios_contact.rb +3 -0
  125. data/lib/puppet/type/nagios_contactgroup.rb +3 -0
  126. data/lib/puppet/type/nagios_host.rb +3 -0
  127. data/lib/puppet/type/nagios_hostextinfo.rb +3 -0
  128. data/lib/puppet/type/nagios_hostgroup.rb +3 -0
  129. data/lib/puppet/type/nagios_hostgroupescalation.rb +3 -0
  130. data/lib/puppet/type/nagios_service.rb +3 -0
  131. data/lib/puppet/type/nagios_servicedependency.rb +3 -0
  132. data/lib/puppet/type/nagios_serviceescalation.rb +3 -0
  133. data/lib/puppet/type/nagios_serviceextinfo.rb +3 -0
  134. data/lib/puppet/type/nagios_timeperiod.rb +3 -0
  135. data/lib/puppet/type/package.rb +4 -12
  136. data/lib/puppet/type/service.rb +9 -0
  137. data/lib/puppet/type/sshkey.rb +3 -3
  138. data/lib/puppet/util/autoload.rb +5 -5
  139. data/lib/puppet/util/checksums.rb +51 -13
  140. data/lib/puppet/util/constant_inflector.rb +14 -0
  141. data/lib/puppet/util/filetype.rb +1 -1
  142. data/lib/puppet/util/graph.rb +3 -9
  143. data/lib/puppet/util/nagios_maker.rb +57 -0
  144. data/lib/puppet/util/settings.rb +19 -16
  145. data/lib/puppet/util/tagging.rb +39 -0
  146. data/test/executables/puppetbin.rb +17 -0
  147. data/test/language/ast.rb +8 -58
  148. data/test/language/ast/casestatement.rb +3 -3
  149. data/test/language/ast/resource.rb +6 -7
  150. data/test/language/ast/resource_reference.rb +12 -12
  151. data/test/language/ast/selector.rb +2 -2
  152. data/test/language/ast/variable.rb +2 -2
  153. data/test/language/functions.rb +24 -24
  154. data/test/language/parser.rb +20 -8
  155. data/test/language/resource.rb +5 -42
  156. data/test/language/scope.rb +21 -37
  157. data/test/language/snippets.rb +7 -0
  158. data/test/lib/puppettest.rb +28 -14
  159. data/test/lib/puppettest/parsertesting.rb +10 -10
  160. data/test/lib/puppettest/support/resources.rb +1 -1
  161. data/test/network/client/master.rb +10 -0
  162. data/test/network/handler/fileserver.rb +51 -49
  163. data/test/network/server/webrick.rb +1 -1
  164. data/test/other/dsl.rb +3 -4
  165. data/test/other/transactions.rb +6 -4
  166. data/test/rails/ast.rb +2 -2
  167. data/test/rails/configuration.rb +1 -1
  168. data/test/rails/railsparameter.rb +2 -0
  169. data/test/rails/railsresource.rb +1 -0
  170. data/test/ral/manager/type.rb +4 -4
  171. data/test/ral/providers/cron/crontab.rb +3 -1
  172. data/test/ral/providers/package.rb +1 -1
  173. data/test/ral/{types → type}/basic.rb +2 -2
  174. data/test/ral/{types → type}/cron.rb +0 -0
  175. data/test/ral/{types → type}/exec.rb +42 -2
  176. data/test/ral/{types → type}/file.rb +34 -79
  177. data/test/ral/{types → type}/file/target.rb +0 -0
  178. data/test/ral/{types → type}/filebucket.rb +0 -0
  179. data/test/ral/{types → type}/fileignoresource.rb +0 -0
  180. data/test/ral/{types → type}/filesources.rb +8 -27
  181. data/test/ral/{types → type}/group.rb +0 -0
  182. data/test/ral/{types → type}/host.rb +16 -0
  183. data/test/ral/{types → type}/mailalias.rb +0 -0
  184. data/test/ral/{types → type}/parameter.rb +0 -0
  185. data/test/ral/{types → type}/port.rb +0 -0
  186. data/test/ral/{types → type}/property.rb +0 -0
  187. data/test/ral/{types → type}/resources.rb +0 -0
  188. data/test/ral/{types → type}/service.rb +0 -0
  189. data/test/ral/{types → type}/sshkey.rb +0 -0
  190. data/test/ral/{types → type}/tidy.rb +1 -0
  191. data/test/ral/{types → type}/user.rb +0 -0
  192. data/test/ral/{types → type}/yumrepo.rb +0 -0
  193. data/test/ral/{types → type}/zone.rb +0 -0
  194. data/test/util/autoload.rb +24 -5
  195. metadata +60 -107
  196. data/conf/gentoo/puppet/puppetca.conf +0 -29
  197. data/conf/gentoo/puppet/puppetd.conf +0 -29
  198. data/conf/gentoo/puppet/puppetmasterd.conf +0 -29
  199. data/examples/root/etc/puppet/puppetd.conf +0 -4
  200. data/lib/puppet/external/gratr.rb +0 -33
  201. data/lib/puppet/external/gratr/adjacency_graph.rb +0 -257
  202. data/lib/puppet/external/gratr/base.rb +0 -34
  203. data/lib/puppet/external/gratr/biconnected.rb +0 -116
  204. data/lib/puppet/external/gratr/chinese_postman.rb +0 -123
  205. data/lib/puppet/external/gratr/common.rb +0 -73
  206. data/lib/puppet/external/gratr/comparability.rb +0 -92
  207. data/lib/puppet/external/gratr/digraph.rb +0 -116
  208. data/lib/puppet/external/gratr/digraph_distance.rb +0 -185
  209. data/lib/puppet/external/gratr/dot.rb +0 -90
  210. data/lib/puppet/external/gratr/edge.rb +0 -145
  211. data/lib/puppet/external/gratr/graph.rb +0 -303
  212. data/lib/puppet/external/gratr/graph_api.rb +0 -83
  213. data/lib/puppet/external/gratr/import.rb +0 -44
  214. data/lib/puppet/external/gratr/labels.rb +0 -90
  215. data/lib/puppet/external/gratr/maximum_flow.rb +0 -64
  216. data/lib/puppet/external/gratr/search.rb +0 -409
  217. data/lib/puppet/external/gratr/strong_components.rb +0 -127
  218. data/lib/puppet/external/gratr/undirected_graph.rb +0 -153
  219. data/lib/puppet/rails/external/tagging/acts_as_taggable.rb +0 -62
  220. data/lib/puppet/rails/external/tagging/init.rb +0 -5
  221. data/lib/puppet/rails/external/tagging/tag.rb +0 -50
  222. data/lib/puppet/rails/external/tagging/tagging.rb +0 -12
  223. data/lib/puppet/rails/puppet_class.rb +0 -6
  224. data/lib/puppet/reference/node_source.rb +0 -9
  225. data/lib/puppet/reference/report.rb +0 -21
  226. data/lib/puppet/type/pfile/checksum.rb +0 -326
  227. data/test/language/ast/definition.rb +0 -166
  228. data/test/language/ast/hostclass.rb +0 -184
  229. data/test/language/compile.rb +0 -569
  230. data/test/language/lexer.rb +0 -276
  231. data/test/lib/mocha.rb +0 -19
  232. data/test/lib/mocha/any_instance_method.rb +0 -35
  233. data/test/lib/mocha/auto_verify.rb +0 -113
  234. data/test/lib/mocha/central.rb +0 -35
  235. data/test/lib/mocha/class_method.rb +0 -62
  236. data/test/lib/mocha/deprecation.rb +0 -22
  237. data/test/lib/mocha/exception_raiser.rb +0 -17
  238. data/test/lib/mocha/expectation.rb +0 -378
  239. data/test/lib/mocha/expectation_error.rb +0 -6
  240. data/test/lib/mocha/infinite_range.rb +0 -25
  241. data/test/lib/mocha/inspect.rb +0 -39
  242. data/test/lib/mocha/instance_method.rb +0 -8
  243. data/test/lib/mocha/is_a.rb +0 -9
  244. data/test/lib/mocha/metaclass.rb +0 -7
  245. data/test/lib/mocha/missing_expectation.rb +0 -27
  246. data/test/lib/mocha/mock.rb +0 -207
  247. data/test/lib/mocha/multiple_yields.rb +0 -20
  248. data/test/lib/mocha/no_yields.rb +0 -11
  249. data/test/lib/mocha/object.rb +0 -110
  250. data/test/lib/mocha/parameter_matchers.rb +0 -9
  251. data/test/lib/mocha/parameter_matchers/all_of.rb +0 -39
  252. data/test/lib/mocha/parameter_matchers/any_of.rb +0 -44
  253. data/test/lib/mocha/parameter_matchers/anything.rb +0 -30
  254. data/test/lib/mocha/parameter_matchers/has_entry.rb +0 -39
  255. data/test/lib/mocha/parameter_matchers/has_key.rb +0 -39
  256. data/test/lib/mocha/parameter_matchers/has_value.rb +0 -39
  257. data/test/lib/mocha/parameter_matchers/includes.rb +0 -37
  258. data/test/lib/mocha/pretty_parameters.rb +0 -28
  259. data/test/lib/mocha/return_values.rb +0 -31
  260. data/test/lib/mocha/setup_and_teardown.rb +0 -23
  261. data/test/lib/mocha/single_return_value.rb +0 -24
  262. data/test/lib/mocha/single_yield.rb +0 -18
  263. data/test/lib/mocha/standalone.rb +0 -32
  264. data/test/lib/mocha/stub.rb +0 -18
  265. data/test/lib/mocha/test_case_adapter.rb +0 -49
  266. data/test/lib/mocha/yield_parameters.rb +0 -31
@@ -1,90 +0,0 @@
1
- #--
2
- # Copyright (c) 2006 Shawn Patrick Garbett
3
- # Copyright (c) 2002,2004,2005 by Horst Duchene
4
- #
5
- # Redistribution and use in source and binary forms, with or without modification,
6
- # are permitted provided that the following conditions are met:
7
- #
8
- # * Redistributions of source code must retain the above copyright notice(s),
9
- # this list of conditions and the following disclaimer.
10
- # * Redistributions in binary form must reproduce the above copyright notice,
11
- # this list of conditions and the following disclaimer in the documentation
12
- # and/or other materials provided with the distribution.
13
- # * Neither the name of the Shawn Garbett nor the names of its contributors
14
- # may be used to endorse or promote products derived from this software
15
- # without specific prior written permission.
16
- #
17
- # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
18
- # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19
- # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20
- # DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
21
- # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22
- # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
23
- # SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
24
- # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
25
- # OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26
- # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27
- #++
28
- #
29
- # Minimal Dot support, based on Dave Thomas's dot module (included in rdoc).
30
- # rdot.rb is a modified version which also contains support for undirected
31
- # graphs.
32
-
33
- require 'puppet/external/gratr/rdot'
34
-
35
- module GRATR
36
- module Graph
37
-
38
- # Return a DOT::DOTDigraph for directed graphs or a DOT::DOTSubgraph for an
39
- # undirected Graph. _params_ can contain any graph property specified in
40
- # rdot.rb. If an edge or vertex label is a kind of Hash then the keys
41
- # which match +dot+ properties will be used as well.
42
- def to_dot_graph (params = {})
43
- params['name'] ||= self.class.name.gsub(/:/,'_')
44
- fontsize = params['fontsize'] ? params['fontsize'] : '8'
45
- graph = (directed? ? DOT::DOTDigraph : DOT::DOTSubgraph).new(params)
46
- edge_klass = directed? ? DOT::DOTDirectedEdge : DOT::DOTEdge
47
- vertices.each do |v|
48
- name = v.to_s
49
- params = {'name' => '"'+name+'"',
50
- 'fontsize' => fontsize,
51
- 'label' => name}
52
- v_label = vertex_label(v)
53
- params.merge!(v_label) if v_label and v_label.kind_of? Hash
54
- graph << DOT::DOTNode.new(params)
55
- end
56
- edges.each do |e|
57
- params = {'from' => '"'+ e.source.to_s + '"',
58
- 'to' => '"'+ e.target.to_s + '"',
59
- 'fontsize' => fontsize }
60
- e_label = edge_label(e)
61
- params.merge!(e_label) if e_label and e_label.kind_of? Hash
62
- graph << edge_klass.new(params)
63
- end
64
- graph
65
- end
66
-
67
- # Output the dot format as a string
68
- def to_dot (params={}) to_dot_graph(params).to_s; end
69
-
70
- # Call +dotty+ for the graph which is written to the file 'graph.dot'
71
- # in the # current directory.
72
- def dotty (params = {}, dotfile = 'graph.dot')
73
- File.open(dotfile, 'w') {|f| f << to_dot(params) }
74
- system('dotty', dotfile)
75
- end
76
-
77
- # Use +dot+ to create a graphical representation of the graph. Returns the
78
- # filename of the graphics file.
79
- def write_to_graphic_file (fmt='png', dotfile='graph')
80
- src = dotfile + '.dot'
81
- dot = dotfile + '.' + fmt
82
-
83
- File.open(src, 'w') {|f| f << self.to_dot << "\n"}
84
-
85
- system( "dot -T#{fmt} #{src} -o #{dot}" )
86
- dot
87
- end
88
-
89
- end # module Graph
90
- end # module GRATR
@@ -1,145 +0,0 @@
1
- #--
2
- # Copyright (c) 2006 Shawn Patrick Garbett
3
- # Copyright (c) 2002,2004,2005 by Horst Duchene
4
- #
5
- # Redistribution and use in source and binary forms, with or without modification,
6
- # are permitted provided that the following conditions are met:
7
- #
8
- # * Redistributions of source code must retain the above copyright notice(s),
9
- # this list of conditions and the following disclaimer.
10
- # * Redistributions in binary form must reproduce the above copyright notice,
11
- # this list of conditions and the following disclaimer in the documentation
12
- # and/or other materials provided with the distribution.
13
- # * Neither the name of the Shawn Garbett nor the names of its contributors
14
- # may be used to endorse or promote products derived from this software
15
- # without specific prior written permission.
16
- #
17
- # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
18
- # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19
- # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20
- # DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
21
- # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22
- # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
23
- # SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
24
- # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
25
- # OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26
- # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27
- #++
28
-
29
-
30
- module GRATR
31
-
32
- # Edge includes classes for representing egdes of directed and
33
- # undirected graphs. There is no need for a Vertex class, because any ruby
34
- # object can be a vertex of a graph.
35
- #
36
- # Edge's base is a Struct with a :source, a :target and a :label
37
- Struct.new("EdgeBase",:source, :target, :label)
38
-
39
- class Edge < Struct::EdgeBase
40
-
41
- def initialize(p_source,p_target,p_label=nil)
42
- super(p_source, p_target, p_label)
43
- end
44
-
45
- # Ignore labels for equality
46
- def eql?(other) self.class == other.class and target==other.target and source==other.source; end
47
-
48
- # Alias for eql?
49
- alias == eql?
50
-
51
- # Returns (v,u) if self == (u,v).
52
- def reverse() self.class.new(target, source, label); end
53
-
54
- # Sort support
55
- def <=>(rhs) [source,target] <=> [rhs.source,rhs.target]; end
56
-
57
- # Edge.new[1,2].to_s => "(1-2 'label')"
58
- def to_s
59
- l = label ? " '#{label.to_s}'" : ''
60
- "(#{source}-#{target}#{l})"
61
- end
62
-
63
- # Hash is defined in such a way that label is not
64
- # part of the hash value
65
- def hash() source.hash ^ (target.hash+1); end
66
-
67
- # Shortcut constructor. Instead of Edge.new(1,2) one can use Edge[1,2]
68
- def self.[](p_source, p_target, p_label=nil)
69
- new(p_source, p_target, p_label)
70
- end
71
-
72
- def inspect() "#{self.class.to_s}[#{source.inspect},#{target.inspect},#{label.inspect}]"; end
73
-
74
- end
75
-
76
- # An undirected edge is simply an undirected pair (source, target) used in
77
- # undirected graphs. UndirectedEdge[u,v] == UndirectedEdge[v,u]
78
- class UndirectedEdge < Edge
79
-
80
- # Equality allows for the swapping of source and target
81
- def eql?(other) super or (self.class == other.class and target==other.source and source==other.target); end
82
-
83
- # Alias for eql?
84
- alias == eql?
85
-
86
- # Hash is defined such that source and target can be reversed and the
87
- # hash value will be the same
88
- #
89
- # This will cause problems with self loops
90
- def hash() source.hash ^ target.hash; end
91
-
92
- # Sort support
93
- def <=>(rhs)
94
- [[source,target].max,[source,target].min] <=>
95
- [[rhs.source,rhs.target].max,[rhs.source,rhs.target].min]
96
- end
97
-
98
- # UndirectedEdge[1,2].to_s == "(1=2 'label)"
99
- def to_s
100
- l = label ? " '#{label.to_s}'" : ''
101
- s = source.to_s
102
- t = target.to_s
103
- "(#{[s,t].min}=#{[s,t].max}#{l})"
104
- end
105
-
106
- end
107
-
108
- # This module provides for internal numbering of edges for differentiating between mutliple edges
109
- module EdgeNumber
110
-
111
- attr_accessor :number # Used to differentiate between mutli-edges
112
-
113
- def initialize(p_source,p_target,p_number,p_label=nil)
114
- self.number = p_number
115
- super(p_source, p_target, p_label)
116
- end
117
-
118
- # Returns (v,u) if self == (u,v).
119
- def reverse() self.class.new(target, source, number, label); end
120
- def hash() super ^ number.hash; end
121
- def to_s() super + "[#{number}]"; end
122
- def <=>(rhs) (result = super(rhs)) == 0 ? number <=> rhs.number : result; end
123
- def inspect() "#{self.class.to_s}[#{source.inspect},#{target.inspect},#{number.inspect},#{label.inspect}]"; end
124
- def eql?(rhs) super(rhs) and (rhs.number.nil? or number.nil? or number == rhs.number); end
125
- def ==(rhs) eql?(rhs); end
126
-
127
- # Shortcut constructor. Instead of Edge.new(1,2) one can use Edge[1,2]
128
- def self.included(cl)
129
-
130
- def cl.[](p_source, p_target, p_number=nil, p_label=nil)
131
- new(p_source, p_target, p_number, p_label)
132
- end
133
- end
134
-
135
- end
136
-
137
- class MultiEdge < Edge
138
- include EdgeNumber
139
- end
140
-
141
- class MultiUndirectedEdge < UndirectedEdge
142
- include EdgeNumber
143
- end
144
-
145
- end
@@ -1,303 +0,0 @@
1
- #--
2
- # Copyright (c) 2006 Shawn Patrick Garbett
3
- # Copyright (c) 2002,2004,2005 by Horst Duchene
4
- #
5
- # Redistribution and use in source and binary forms, with or without modification,
6
- # are permitted provided that the following conditions are met:
7
- #
8
- # * Redistributions of source code must retain the above copyright notice(s),
9
- # this list of conditions and the following disclaimer.
10
- # * Redistributions in binary form must reproduce the above copyright notice,
11
- # this list of conditions and the following disclaimer in the documentation
12
- # and/or other materials provided with the distribution.
13
- # * Neither the name of the Shawn Garbett nor the names of its contributors
14
- # may be used to endorse or promote products derived from this software
15
- # without specific prior written permission.
16
- #
17
- # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
18
- # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19
- # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20
- # DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
21
- # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22
- # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
23
- # SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
24
- # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
25
- # OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26
- # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27
- #++
28
-
29
-
30
- require 'puppet/external/gratr/edge'
31
- require 'puppet/external/gratr/labels'
32
- require 'puppet/external/gratr/graph_api'
33
-
34
- module GRATR
35
-
36
- # Using the functions required by the GraphAPI, it implements all the
37
- # basic functions of a Graph class by using only functions in GraphAPI.
38
- # An actual implementation still needs to be done, as in Digraph or
39
- # UndirectedGraph.
40
- module Graph
41
- include Enumerable
42
- include Labels
43
- include GraphAPI
44
-
45
- # Non destructive version of add_vertex!, returns modified copy of Graph
46
- def add_vertex(v, l=nil) x=self.class.new(self); x.add_vertex!(v,l); end
47
-
48
- # Non destructive version add_edge!, returns modified copy of Graph
49
- def add_edge(u, v=nil, l=nil) x=self.class.new(self); x.add_edge!(u,v,l); end
50
-
51
- # Non destructive version of remove_vertex!, returns modified copy of Graph
52
- def remove_vertex(v) x=self.class.new(self); x.remove_vertex!(v); end
53
-
54
- # Non destructive version of remove_edge!, returns modified copy of Graph
55
- def remove_edge(u,v=nil) x=self.class.new(self); x.remove_edge!(u,v); end
56
-
57
- # Return Array of adjacent portions of the Graph
58
- # x can either be a vertex an edge.
59
- # options specifies parameters about the adjacency search
60
- # :type can be either :edges or :vertices (default).
61
- # :direction can be :in, :out(default) or :all.
62
- #
63
- # Note: It is probably more efficently done in implementation.
64
- def adjacent(x, options={})
65
- d = directed? ? (options[:direction] || :out) : :all
66
-
67
- # Discharge the easy ones first
68
- return [x.source] if x.kind_of? Edge and options[:type] == :vertices and d == :in
69
- return [x.target] if x.kind_of? Edge and options[:type] == :vertices and d == :out
70
- return [x.source, x.target] if x.kind_of? Edge and options[:type] != :edges and d == :all
71
-
72
- (options[:type] == :edges ? edges : to_a).select {|u| adjacent?(x,u,d)}
73
- end
74
-
75
- # Add all objects in _a_ to the vertex set.
76
- def add_vertices!(*a) a.each {|v| add_vertex! v}; self; end
77
-
78
- # See add_vertices!
79
-
80
- def add_vertices(*a) x=self.class.new(self); x.add_vertices(*a); self; end
81
-
82
- # Add all edges in the _edges_ Enumerable to the edge set. Elements of the
83
- # Enumerable can be both two-element arrays or instances of DirectedEdge or
84
- # UnDirectedEdge.
85
- def add_edges!(*args) args.each { |edge| add_edge!(edge) }; self; end
86
-
87
- # See add_edge!
88
- def add_edges(*a) x=self.class.new(self); x.add_edges!(*a); self; end
89
-
90
- # Remove all vertices specified by the Enumerable a from the graph by
91
- # calling remove_vertex!.
92
- def remove_vertices!(*a) a.each { |v| remove_vertex! v }; end
93
-
94
- # See remove_vertices!
95
- def remove_vertices(*a) x=self.class.new(self); x.remove_vertices(*a); end
96
-
97
- # Remove all vertices edges by the Enumerable a from the graph by
98
- # calling remove_edge!
99
- def remove_edges!(*a) a.each { |e| remove_edges! e }; end
100
-
101
- # See remove_edges
102
- def remove_edges(*a) x=self.class.new(self); x.remove_edges(*a); end
103
-
104
- # Execute given block for each vertex, provides for methods in Enumerable
105
- def each(&block) vertices.each(&block); end
106
-
107
- # Returns true if _v_ is a vertex of the graph.
108
- # This is a default implementation that is of O(n) average complexity.
109
- # If a subclass uses a hash to store vertices, then this can be
110
- # made into an O(1) average complexity operation.
111
- def vertex?(v) vertices.include?(v); end
112
-
113
- # Returns true if u or (u,v) is an Edge of the graph.
114
- def edge?(*arg) edges.include?(edge_convert(*args)); end
115
-
116
- # Tests two objects to see if they are adjacent.
117
- # direction parameter specifies direction of adjacency, :in, :out, or :all(default)
118
- # All denotes that if there is any adjacency, then it will return true.
119
- # Note that the default is different than adjacent where one is primarily concerned with finding
120
- # all adjacent objects in a graph to a given object. Here the concern is primarily on seeing
121
- # if two objects touch. For vertexes, any edge between the two will usually do, but the direction
122
- # can be specified if need be.
123
- def adjacent?(source, target, direction=:all)
124
- if source.kind_of? GRATR::Edge
125
- raise NoEdgeError unless edge? source
126
- if target.kind_of? GRATR::Edge
127
- raise NoEdgeError unless edge? target
128
- (direction != :out and source.source == target.target) or (direction != :in and source.target == target.source)
129
- else
130
- raise NoVertexError unless vertex? target
131
- (direction != :out and source.source == target) or (direction != :in and source.target == target)
132
- end
133
- else
134
- raise NoVertexError unless vertex? source
135
- if target.kind_of? GRATR::Edge
136
- raise NoEdgeError unless edge? target
137
- (direction != :out and source == target.target) or (direction != :in and source == target.source)
138
- else
139
- raise NoVertexError unless vertex? target
140
- (direction != :out and edge?(target,source)) or (direction != :in and edge?(source,target))
141
- end
142
- end
143
- end
144
-
145
- # Returns true if the graph has no vertex, i.e. num_vertices == 0.
146
- def empty?() vertices.size.zero?; end
147
-
148
- # Returns true if the given object is a vertex or Edge in the Graph.
149
- #
150
- def include?(x) x.kind_of?(GRATR::Edge) ? edge?(x) : vertex?(x); end
151
-
152
- # Returns the neighboorhood of the given vertex (or Edge)
153
- # This is equivalent to adjacent, but bases type on the type of object.
154
- # direction can be :all, :in, or :out
155
- def neighborhood(x, direction = :all)
156
- adjacent(x, :direction => direction, :type => ((x.kind_of? GRATR::Edge) ? :edges : :vertices ))
157
- end
158
-
159
- # Union of all neighborhoods of vertices (or edges) in the Enumerable x minus the contents of x
160
- # Definition taken from Jorgen Bang-Jensen, Gregory Gutin, _Digraphs: Theory, Algorithms and Applications_, pg 4
161
- def set_neighborhood(x, direction = :all)
162
- x.inject(Set.new) {|a,v| a.merge(neighborhood(v,direction))}.reject {|v2| x.include?(v2)}
163
- end
164
-
165
- # Union of all set_neighborhoods reachable in p edges
166
- # Definition taken from Jorgen Bang-Jensen, Gregory Gutin, _Digraphs: Theory, Algorithms and Applications_, pg 46
167
- def closed_pth_neighborhood(w,p,direction=:all)
168
- if p <= 0
169
- w
170
- elsif p == 1
171
- (w + set_neighborhood(w,direction)).uniq
172
- else
173
- n = set_neighborhood(w, direction)
174
- (w + n + closed_pth_neighborhood(n,p-1,direction)).uniq
175
- end
176
- end
177
-
178
- # Returns the neighboorhoods reachable in p steps from every vertex (or edge)
179
- # in the Enumerable x
180
- # Definition taken from Jorgen Bang-Jensen, Gregory Gutin, _Digraphs: Theory, Algorithms and Applications_, pg 46
181
- def open_pth_neighborhood(x, p, direction=:all)
182
- if p <= 0
183
- x
184
- elsif p == 1
185
- set_neighborhood(x,direction)
186
- else
187
- set_neighborhood(open_pth_neighborhood(x, p-1, direction),direction) - closed_pth_neighborhood(x,p-1,direction)
188
- end
189
- end
190
-
191
- # Returns the number of out-edges (for directed graphs) or the number of
192
- # incident edges (for undirected graphs) of vertex _v_.
193
- def out_degree(v) adjacent(v, :direction => :out).size; end
194
-
195
- # Returns the number of in-edges (for directed graphs) or the number of
196
- # incident edges (for undirected graphs) of vertex _v_.
197
- def in_degree(v) adjacent(v, :direction => :in ).size; end
198
-
199
- # Returns the sum of the number in and out edges for a vertex
200
- def degree(v) in_degree(v) + out_degree(v); end
201
-
202
- # Minimum in-degree
203
- def min_in_degree() to_a.map {|v| in_degree(v)}.min; end
204
-
205
- # Minimum out-degree
206
- def min_out_degree() to_a.map {|v| out_degree(v)}.min; end
207
-
208
- # Minimum degree of all vertexes
209
- def min_degree() [min_in_degree, min_out_degree].min; end
210
-
211
- # Maximum in-degree
212
- def max_in_degree() vertices.map {|v| in_degree(v)}.max; end
213
-
214
- # Maximum out-degree
215
- def max_out_degree() vertices.map {|v| out_degree(v)}.max; end
216
-
217
- # Minimum degree of all vertexes
218
- def max_degree() [max_in_degree, max_out_degree].max; end
219
-
220
- # Regular
221
- def regular?() min_degree == max_degree; end
222
-
223
- # Returns the number of vertices.
224
- def size() vertices.size; end
225
-
226
- # Synonym for size.
227
- def num_vertices() vertices.size; end
228
-
229
- # Returns the number of edges.
230
- def num_edges() edges.size; end
231
-
232
- # Utility method to show a string representation of the edges of the graph.
233
- def to_s() edges.to_s; end
234
-
235
- # Equality is defined to be same set of edges and directed?
236
- def eql?(g)
237
- return false unless g.kind_of? GRATR::Graph
238
-
239
- (g.directed? == self.directed?) and
240
- (vertices.sort == g.vertices.sort) and
241
- (g.edges.sort == edges.sort)
242
- end
243
-
244
- # Synonym for eql?
245
- def ==(rhs) eql?(rhs); end
246
-
247
- # Merge another graph into this one
248
- def merge(other)
249
- other.vertices.each {|v| add_vertex!(v) }
250
- other.edges.each {|e| add_edge!(e) }
251
- other.edges.each {|e| add_edge!(e.reverse) } if directed? and !other.directed?
252
- self
253
- end
254
-
255
- # A synonym for merge, that doesn't modify the current graph
256
- def +(other)
257
- result = self.class.new(self)
258
- case other
259
- when GRATR::Graph : result.merge(other)
260
- when GRATR::Edge : result.add_edge!(other)
261
- else result.add_vertex!(other)
262
- end
263
- end
264
-
265
- # Remove all vertices in the specified right hand side graph
266
- def -(other)
267
- case other
268
- when GRATR::Graph : induced_subgraph(vertices - other.vertices)
269
- when GRATR::Edge : self.class.new(self).remove_edge!(other)
270
- else self.class.new(self).remove_vertex!(other)
271
- end
272
- end
273
-
274
- # A synonym for add_edge!
275
- def <<(edge) add_edge!(edge); end
276
-
277
- # Return the complement of the current graph
278
- def complement
279
- vertices.inject(self.class.new) do |a,v|
280
- a.add_vertex!(v)
281
- vertices.each {|v2| a.add_edge!(v,v2) unless edge?(v,v2) }; a
282
- end
283
- end
284
-
285
- # Given an array of vertices return the induced subgraph
286
- def induced_subgraph(v)
287
- edges.inject(self.class.new) do |a,e|
288
- ( v.include?(e.source) and v.include?(e.target) ) ? (a << e) : a
289
- end;
290
- end
291
-
292
- def inspect
293
- l = vertices.select {|v| self[v]}.map {|u| "vertex_label_set(#{u.inspect},#{self[u].inspect})"}.join('.')
294
- self.class.to_s + '[' + edges.map {|e| e.inspect}.join(', ') + ']' + (l ? '.'+l : '')
295
- end
296
-
297
- private
298
- def edge_convert(*args) args[0].kind_of?(GRATR::Edge) ? args[0] : edge_class[*args]; end
299
-
300
-
301
- end # Graph
302
-
303
- end # GRATR