From f98be4a7198326b26f1072c401b3e337f340db40 Mon Sep 17 00:00:00 2001 From: Luke Kanies Date: Sat, 19 Jan 2008 13:40:40 -0800 Subject: Fixing #976 -- both the full name of qualified classes and the class parts are now added as tags. I've also created a Tagging module that we should push throughout the rest of the system that uses tags. --- lib/puppet/util/tagging.rb | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 lib/puppet/util/tagging.rb (limited to 'lib/puppet/util') diff --git a/lib/puppet/util/tagging.rb b/lib/puppet/util/tagging.rb new file mode 100644 index 000000000..25d74c420 --- /dev/null +++ b/lib/puppet/util/tagging.rb @@ -0,0 +1,34 @@ +# Created on 2008-01-19 +# Copyright Luke Kanies + +# A common module to handle tagging. +module Puppet::Util::Tagging + # Add a tag to our current list. These tags will be added to all + # of the objects contained in this scope. + def tag(*ary) + @tags ||= [] + + qualified = [] + + ary.collect { |tag| tag.to_s.downcase }.each do |tag| + fail(Puppet::ParseError, "Invalid tag %s" % tag.inspect) unless valid_tag?(tag) + qualified << tag if tag.include?("::") + @tags << tag unless @tags.include?(tag) + end + + qualified.collect { |name| name.split("::") }.flatten.each { |tag| @tags << tag unless @tags.include?(tag) } + end + + # Return a copy of the tag list, so someone can't ask for our tags + # and then modify them. + def tags + @tags ||= [] + @tags.dup + end + + private + + def valid_tag?(tag) + tag =~ /^\w[-\w:]*$/ + end +end -- cgit From 8a649ff28a46afe6b1e4dd002ac90c93651edfa3 Mon Sep 17 00:00:00 2001 From: Luke Kanies Date: Sun, 20 Jan 2008 21:21:37 -0800 Subject: I think I've finally fixed #959, by having the Settings class skip any resources that are already in memory. --- lib/puppet/util/settings.rb | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) (limited to 'lib/puppet/util') diff --git a/lib/puppet/util/settings.rb b/lib/puppet/util/settings.rb index b672d9564..ff019edb8 100644 --- a/lib/puppet/util/settings.rb +++ b/lib/puppet/util/settings.rb @@ -510,18 +510,19 @@ class Puppet::Util::Settings end # Only files are convertable to transportable resources. - if obj.respond_to? :to_transportable - next if value(obj.name) =~ /^\/dev/ - transobjects = obj.to_transportable - transobjects = [transobjects] unless transobjects.is_a? Array - transobjects.each do |trans| - # transportable could return nil - next unless trans - unless done[:file].include? trans.name - @created << trans.name - objects << trans - done[:file][trans.name] = trans - end + next unless obj.respond_to? :to_transportable + next if value(obj.name) =~ /^\/dev/ + next if Puppet::Type::File[obj.value] # skip files that are in our global resource list. + + transobjects = obj.to_transportable + transobjects = [transobjects] unless transobjects.is_a? Array + transobjects.each do |trans| + # transportable could return nil + next unless trans + unless done[:file].include? trans.name + @created << trans.name + objects << trans + done[:file][trans.name] = trans end end end -- cgit From 2931723bae9e4226ab8eb7f6f806bf9a2ea5cbb8 Mon Sep 17 00:00:00 2001 From: Luke Kanies Date: Thu, 7 Feb 2008 15:31:43 -0600 Subject: Fixing the Settings class so that it correctly handles file values that are false. --- lib/puppet/util/settings.rb | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) (limited to 'lib/puppet/util') diff --git a/lib/puppet/util/settings.rb b/lib/puppet/util/settings.rb index ff019edb8..c84a5bfb1 100644 --- a/lib/puppet/util/settings.rb +++ b/lib/puppet/util/settings.rb @@ -509,12 +509,11 @@ class Puppet::Util::Settings objects += add_user_resources(section, obj, done) end + value = obj.value + # Only files are convertable to transportable resources. - next unless obj.respond_to? :to_transportable - next if value(obj.name) =~ /^\/dev/ - next if Puppet::Type::File[obj.value] # skip files that are in our global resource list. + next unless obj.respond_to? :to_transportable and transobjects = obj.to_transportable - transobjects = obj.to_transportable transobjects = [transobjects] unless transobjects.is_a? Array transobjects.each do |trans| # transportable could return nil @@ -1154,12 +1153,15 @@ Generated on #{Time.now}. def to_transportable type = self.type return nil unless type - path = @parent.value(self.name).split(File::SEPARATOR) - path.shift # remove the leading nil - objects = [] path = self.value + return nil unless path.is_a?(String) + return nil if path =~ /^\/dev/ + return nil if Puppet::Type::File[path] # skip files that are in our global resource list. + + objects = [] + # Skip plain files that don't exist, since we won't be managing them anyway. return nil unless self.name.to_s =~ /dir$/ or File.exist?(path) or self.create obj = Puppet::TransObject.new(path, "file") -- cgit From b293763f9ef2e134f18bb2c3fdaaaa502aa2c201 Mon Sep 17 00:00:00 2001 From: Luke Kanies Date: Thu, 7 Feb 2008 15:34:30 -0600 Subject: Applying patch by Jay to fix #989 -- missing crl files are correctly ignored, and you now use 'false' instead of 'none' to explicitly ignore them. --- lib/puppet/util/settings.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib/puppet/util') diff --git a/lib/puppet/util/settings.rb b/lib/puppet/util/settings.rb index c84a5bfb1..cf15d3194 100644 --- a/lib/puppet/util/settings.rb +++ b/lib/puppet/util/settings.rb @@ -1124,7 +1124,7 @@ Generated on #{Time.now}. # the variable 'dir', or adding a slash at the end. def munge(value) # If it's not a fully qualified path... - if value.is_a?(String) and value !~ /^\$/ and value !~ /^\// + if value.is_a?(String) and value !~ /^\$/ and value !~ /^\// and value != 'false' # Make it one value = File.join(Dir.getwd, value) end -- cgit From 744cd45378384d33b3118351536e70cd6ea8370d Mon Sep 17 00:00:00 2001 From: Luke Kanies Date: Mon, 11 Feb 2008 18:13:51 -0600 Subject: Added a 'tagged?' method to the Tagging module. --- lib/puppet/util/tagging.rb | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'lib/puppet/util') diff --git a/lib/puppet/util/tagging.rb b/lib/puppet/util/tagging.rb index 25d74c420..9abb3fb2b 100644 --- a/lib/puppet/util/tagging.rb +++ b/lib/puppet/util/tagging.rb @@ -19,6 +19,11 @@ module Puppet::Util::Tagging qualified.collect { |name| name.split("::") }.flatten.each { |tag| @tags << tag unless @tags.include?(tag) } end + # Are we tagged with the provided tag? + def tagged?(tag) + defined?(@tags) and @tags.include?(tag.to_s) + end + # Return a copy of the tag list, so someone can't ask for our tags # and then modify them. def tags -- cgit From 8b2fae019b31513becd002eb474e1b4803abde24 Mon Sep 17 00:00:00 2001 From: Luke Kanies Date: Mon, 11 Feb 2008 18:27:49 -0600 Subject: Removing the last remaining vestiges of GRATR -- removing the bangs from 'add_vertex!' and 'add_edge!'. --- lib/puppet/util/graph.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib/puppet/util') diff --git a/lib/puppet/util/graph.rb b/lib/puppet/util/graph.rb index a9744578b..d1ef36f8e 100644 --- a/lib/puppet/util/graph.rb +++ b/lib/puppet/util/graph.rb @@ -16,7 +16,7 @@ module Puppet::Util::Graph self.each do |child| unless block_given? and ! yield(child) - graph.add_edge!(self, child) + graph.add_edge(self, child) if child.respond_to?(:to_graph) child.to_graph(graph, &block) -- cgit From 3af6827875f4e02b47fe2293280ff9afe811485f Mon Sep 17 00:00:00 2001 From: Luke Kanies Date: Tue, 12 Feb 2008 16:35:31 -0600 Subject: Adding an inflection util class. --- lib/puppet/util/constant_inflector.rb | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 lib/puppet/util/constant_inflector.rb (limited to 'lib/puppet/util') diff --git a/lib/puppet/util/constant_inflector.rb b/lib/puppet/util/constant_inflector.rb new file mode 100644 index 000000000..8b083951f --- /dev/null +++ b/lib/puppet/util/constant_inflector.rb @@ -0,0 +1,14 @@ +# Created on 2008-02-12 +# Copyright Luke Kanies + +# A common module for converting between constants and +# file names. +module Puppet::Util::ConstantInflector + def file2constant(file) + file.split("/").collect { |name| name.capitalize }.join("::").gsub(/_+(.)/) { |term| $1.capitalize } + end + + def constant2file(constant) + constant.to_s.gsub(/([a-z])([A-Z])/) { |term| $1 + "_" + $2 }.gsub("::", "/").downcase + end +end -- cgit