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,29 +0,0 @@
1
- [puppet]
2
- # Where Puppet stores dynamic and growing data.
3
- # The default value is '/var/puppet'.
4
- vardir = /var/lib/puppet
5
-
6
- # The Puppet log directory.
7
- # The default value is '$vardir/log'.
8
- logdir = /var/log/puppet
9
-
10
- # Where Puppet PID files are kept.
11
- # The default value is '$vardir/run'.
12
- rundir = /var/run/puppet
13
-
14
- # Where SSL certificates are kept.
15
- # The default value is '$confdir/ssl'.
16
- ssldir = $vardir/ssl
17
-
18
- [puppetd]
19
- # The file in which puppetd stores a list of the classes
20
- # associated with the retrieved configuratiion. Can be loaded in
21
- # the separate ``puppet`` executable using the ``--loadclasses``
22
- # option.
23
- # The default value is '$confdir/classes.txt'.
24
- classfile = $vardir/classes.txt
25
-
26
- # Where puppetd caches the local configuration. An
27
- # extension indicating the cache format is added automatically.
28
- # The default value is '$confdir/localconfig'.
29
- localconfig = $vardir/localconfig
@@ -1,4 +0,0 @@
1
- [puppet]
2
- report = true
3
- factsync = true
4
- pluginsync = true
@@ -1,33 +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/base'
31
- require 'puppet/external/gratr/digraph'
32
- require 'puppet/external/gratr/undirected_graph'
33
- require 'puppet/external/gratr/common'
@@ -1,257 +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/graph'
32
- require 'set'
33
-
34
- module GRATR
35
-
36
- # This provides the basic routines needed to implement the Digraph, UndirectedGraph,
37
- # PseudoGraph, DirectedPseudoGraph, MultiGraph and DirectedPseudoGraph class.
38
- module AdjacencyGraph
39
-
40
- include Graph
41
-
42
- class ArrayWithAdd < Array # :nodoc:
43
- alias add push
44
- end
45
-
46
- # Initialization parameters can include an Array of edges to add, Graphs to
47
- # copy (will merge if multiple)
48
- # :parallel_edges denotes that duplicate edges are allowed
49
- # :loops denotes that loops are allowed
50
- def initialize(*params)
51
- @vertex_dict = Hash.new
52
- raise ArgumentError if params.any? do |p|
53
- !(p.kind_of? GRATR::Graph or
54
- p.kind_of? Array or
55
- p == :parallel_edges or
56
- p == :loops)
57
- end
58
- clear_all_labels
59
-
60
- # Basic configuration of adjacency
61
- @allow_loops = params.any? {|p| p == :loops}
62
- @parallel_edges = params.any? {|p| p == :parallel_edges}
63
- @edgelist_class = @parallel_edges ? ArrayWithAdd : Set
64
- if @parallel_edges
65
- @edge_number = Hash.new
66
- @next_edge_number = 0
67
- end
68
-
69
- # Copy any given graph into this graph
70
- params.select {|p| p.kind_of? GRATR::Graph}.each do |g|
71
- g.edges.each do |e|
72
- add_edge!(e)
73
- edge_label_set(e, edge_label(e)) if edge_label(e)
74
- end
75
- g.vertices.each do |v|
76
- vertex_label_set(v, vertex_label(v)) if vertex_label(v)
77
- end
78
- end
79
-
80
- # Add all array edges specified
81
- params.select {|p| p.kind_of? Array}.each do |a|
82
- 0.step(a.size-1, 2) {|i| add_edge!(a[i], a[i+1])}
83
- end
84
-
85
- end
86
-
87
- # Returns true if v is a vertex of this Graph
88
- # An O(1) implementation of vertex?
89
- def vertex?(v) @vertex_dict.has_key?(v); end
90
-
91
- # Returns true if [u,v] or u is an Edge
92
- # An O(1) implementation
93
- def edge?(u, v=nil)
94
- u, v = u.source, u.target if u.kind_of? GRATR::Edge
95
- vertex?(u) and @vertex_dict[u].include?(v)
96
- end
97
-
98
- # Adds a vertex to the graph with an optional label
99
- def add_vertex!(vertex, label=nil)
100
- @vertex_dict[vertex] ||= @edgelist_class.new
101
- self[vertex] = label if label
102
- self
103
- end
104
-
105
- # Adds an edge to the graph
106
- # Can be called in two basic ways, label is optional
107
- # * add_edge!(Edge[source,target], "Label")
108
- # * add_edge!(source,target, "Label")
109
- def add_edge!(u, v=nil, l=nil, n=nil)
110
- if u.class.include? EdgeNumber and n.nil?
111
- n = u.number
112
- end
113
- if u.kind_of? GRATR::Edge
114
- edge = u
115
- u, v, l = u.source, u.target, u.label
116
- end
117
- if not @allow_loops and u == v
118
- return self
119
- end
120
- if @parallel_edges and ! n
121
- n = (@next_edge_number+=1)
122
- end
123
- add_vertex!(u);
124
- add_vertex!(v)
125
- @vertex_dict[u].add(v)
126
-
127
- if @parallel_edges
128
- (@edge_number[u] ||= @edgelist_class.new).add(n)
129
- end
130
- unless directed?
131
- @vertex_dict[v].add(u)
132
- if @parallel_edges
133
- (@edge_number[v] ||= @edgelist_class.new).add(n)
134
- end
135
- end
136
-
137
- if l
138
- unless edge
139
- if n
140
- edge = edge_class[u,v,n]
141
- else
142
- edge = edge_class[u,v]
143
- end
144
- end
145
- self[edge] = l
146
- end
147
- self
148
- end
149
-
150
- # Removes a given vertex from the graph
151
- def remove_vertex!(v)
152
- # FIXME This is broken for multi graphs
153
- @vertex_dict.delete(v)
154
- @vertex_dict.each_value { |adjList| adjList.delete(v) }
155
- @vertex_dict.keys.each do |u|
156
- delete_label(edge_class[u,v])
157
- delete_label(edge_class[v,u])
158
- end
159
- delete_label(v)
160
- self
161
- end
162
-
163
- # Removes an edge from the graph, can be called with source and target or with
164
- # and object of GRATR::Edge derivation
165
- def remove_edge!(u, v=nil)
166
- unless u.kind_of? GRATR::Edge
167
- raise ArgumentError if @parallel_edges
168
- u = edge_class[u,v]
169
- end
170
- raise ArgumentError if @parallel_edges and (u.number || 0) == 0
171
- return self unless @vertex_dict[u.source] # It doesn't exist
172
- delete_label(u) # Get rid of label
173
- if @parallel_edges
174
- index = @edge_number[u.source].index(u.number)
175
- raise NoEdgeError unless index
176
- @vertex_dict[u.source].delete_at(index)
177
- @edge_number[u.source].delete_at(index)
178
- else
179
- @vertex_dict[u.source].delete(u.target)
180
- end
181
- self
182
- end
183
-
184
- # Returns an array of vertices that the graph has
185
- def vertices() @vertex_dict.keys; end
186
-
187
- # Returns an array of edges, most likely of class Edge or UndirectedEdge depending
188
- # upon the type of graph
189
- def edges
190
- @vertex_dict.keys.inject(Set.new) do |a,v|
191
- if @parallel_edges and @edge_number[v]
192
- @vertex_dict[v].zip(@edge_number[v]).each do |w|
193
- s,t,n = v,w[0],w[1]
194
- a.add( edge_class[ s,t,n, edge_label(s,t,n) ] )
195
- end
196
- else
197
- @vertex_dict[v].each do |w|
198
- a.add(edge_class[v,w,edge_label(v,w)])
199
- end
200
- end; a
201
- end.to_a
202
- end
203
-
204
- alias graph_adjacent adjacent
205
- def adjacent(x, options={})
206
- unless @vertex_dict.has_key?(x)
207
- raise ArgumentError, "%s is not a vertex" % x
208
- end
209
- options[:direction] ||= :out
210
- if !x.kind_of?(GRATR::Edge) and (options[:direction] == :out || !directed?)
211
- if options[:type] == :edges
212
- @parallel_edges ?
213
- @vertex_dict[x].map {|v| e=edge_class[x,v,@edge_number[x][v]]; e.label = self[e]; e} :
214
- @vertex_dict[x].map {|v| e=edge_class[x,v]; e.label = self[e]; e}
215
- else
216
- @vertex_dict[x].to_a
217
- end
218
- else
219
- graph_adjacent(x,options)
220
- end
221
- end
222
-
223
-
224
- public
225
-
226
- def self.included(cl)
227
- # Shortcut for creating a Graph
228
- #
229
- # Example: GRATR::Digraph[1,2, 2,3, 2,4, 4,5].edges.to_a.to_s =>
230
- # "(1-2)(2-3)(2-4)(4-5)"
231
- #
232
- # Or as a Hash for specifying lables
233
- # GRATR::Digraph[ [:a,:b] => 3, [:b,:c] => 4 ] (Note: Do not use for Multi or Pseudo graphs)
234
- def cl.[] (*a)
235
- result = new
236
- if a.size == 1 and a[0].kind_of? Hash
237
- # Convert to edge class
238
- a[0].each do |k,v|
239
- if result.edge_class.include? GRATR::EdgeNumber
240
- result.add_edge!(result.edge_class[k[0],k[1],nil,v])
241
- else
242
- result.add_edge!(result.edge_class[k[0],k[1],v])
243
- end
244
- end
245
- elsif a[0].kind_of? GRATR::Edge
246
- a.each{|e| result.add_edge!(e); result[e] = e.label}
247
- elsif a.size % 2 == 0
248
- 0.step(a.size-1, 2) {|i| result.add_edge!(a[i], a[i+1])}
249
- else
250
- raise ArgumentError
251
- end
252
- result
253
- end
254
- end
255
-
256
- end # Adjacency Graph
257
- end # GRATR
@@ -1,34 +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
- GRATR_VERSION = "0.4.1"
30
-
31
- module GRATR
32
- class NoVertexError < IndexError; end
33
- class NoEdgeError < IndexError; end
34
- end
@@ -1,116 +0,0 @@
1
- #--
2
- # Copyright (c) 2006 Shawn Patrick Garbett
3
- #
4
- # Redistribution and use in source and binary forms, with or without modification,
5
- # are permitted provided that the following conditions are met:
6
- #
7
- # * Redistributions of source code must retain the above copyright notice(s),
8
- # this list of conditions and the following disclaimer.
9
- # * Redistributions in binary form must reproduce the above copyright notice,
10
- # this list of conditions and the following disclaimer in the documentation
11
- # and/or other materials provided with the distribution.
12
- # * Neither the name of the Shawn Garbett nor the names of its contributors
13
- # may be used to endorse or promote products derived from this software
14
- # without specific prior written permission.
15
- #
16
- # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
17
- # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18
- # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19
- # DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
20
- # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21
- # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
22
- # SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
23
- # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
24
- # OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
25
- # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26
- #++
27
-
28
-
29
- require 'set'
30
-
31
- module GRATR
32
- module Graph
33
- # Biconnected is a module for adding the biconnected algorithm to
34
- # UndirectedGraphs
35
- module Biconnected
36
-
37
- # biconnected computes the biconnected subgraphs
38
- # of a graph using Tarjan's algorithm based on DFS. See: Robert E. Tarjan
39
- # _Depth_First_Search_and_Linear_Graph_Algorithms_. SIAM Journal on
40
- # Computing, 1(2):146-160, 1972
41
- #
42
- # The output of the algorithm is a pair, the first value is an
43
- # array of biconnected subgraphs. The second is the set of
44
- # articulation vertices.
45
- #
46
- # A connected graph is biconnected if the removal of any single vertex
47
- # (and all edges incident on that vertex) cannot disconnect the graph.
48
- # More generally, the biconnected components of a graph are the maximal
49
- # subsets of vertices such that the removal of a vertex from a particular
50
- # component will not disconnect the component. Unlike connected components,
51
- # vertices may belong to multiple biconnected components: those vertices
52
- # that belong to more than one biconnected component are called articulation
53
- # points or, equivalently, cut vertices. Articulation points are vertices
54
- # whose removal would increase the number of connected components in the graph.
55
- # Thus, a graph without articulation points is biconnected.
56
- def biconnected
57
- dfs_num = 0
58
- number = {}; predecessor = {}; low_point = {}
59
- stack = []; result = []; articulation= []
60
-
61
- root_vertex = Proc.new {|v| predecessor[v]=v }
62
- enter_vertex = Proc.new {|u| number[u]=low_point[u]=(dfs_num+=1) }
63
- tree_edge = Proc.new do |e|
64
- stack.push(e)
65
- predecessor[e.target] = e.source
66
- end
67
- back_edge = Proc.new do |e|
68
- if e.target != predecessor[e.source]
69
- stack.push(e)
70
- low_point[e.source] = [low_point[e.source], number[e.target]].min
71
- end
72
- end
73
- exit_vertex = Proc.new do |u|
74
- parent = predecessor[u]
75
- is_articulation_point = false
76
- if number[parent] > number[u]
77
- parent = predecessor[parent]
78
- is_articulation_point = true
79
- end
80
- if parent == u
81
- is_articulation_point = false if (number[u] + 1) == number[predecessor[u]]
82
- else
83
- low_point[parent] = [low_point[parent], low_point[u]].min
84
- if low_point[u] >= number[parent]
85
- if number[parent] > number[predecessor[parent]]
86
- predecessor[u] = predecessor[parent]
87
- predecessor[parent] = u
88
- end
89
- result << (component = self.class.new)
90
- while number[stack[-1].source] >= number[u]
91
- component.add_edge!(stack.pop)
92
- end
93
- component.add_edge!(stack.pop)
94
- if stack.empty?
95
- predecessor[u] = parent
96
- predecessor[parent] = u
97
- end
98
- end
99
- end
100
- articulation << u if is_articulation_point
101
- end
102
-
103
- # Execute depth first search
104
- dfs({:root_vertex => root_vertex,
105
- :enter_vertex => enter_vertex,
106
- :tree_edge => tree_edge,
107
- :back_edge => back_edge,
108
- :exit_vertex => exit_vertex})
109
-
110
- [result, articulation]
111
- end # biconnected
112
-
113
- end # Biconnected
114
-
115
- end # Graph
116
- end # GRATR