diff options
| author | luke <luke@980ebf18-57e1-0310-9a29-db15c13687c0> | 2007-03-06 19:03:05 +0000 |
|---|---|---|
| committer | luke <luke@980ebf18-57e1-0310-9a29-db15c13687c0> | 2007-03-06 19:03:05 +0000 |
| commit | 46d344b9daa24047b60183cc94509d306b6b562a (patch) | |
| tree | 3c11eaad696ba3d6e6dd40bd7b9e7d1a4a71af85 /lib/puppet/util | |
| parent | 68233706a9ff05be8fa8ab3ab7198cd0918517d6 (diff) | |
| download | puppet-46d344b9daa24047b60183cc94509d306b6b562a.tar.gz puppet-46d344b9daa24047b60183cc94509d306b6b562a.tar.xz puppet-46d344b9daa24047b60183cc94509d306b6b562a.zip | |
Merging the webserver_portability branch from version 2182 to version 2258.
git-svn-id: https://reductivelabs.com/svn/puppet/trunk@2259 980ebf18-57e1-0310-9a29-db15c13687c0
Diffstat (limited to 'lib/puppet/util')
| -rw-r--r-- | lib/puppet/util/config.rb | 18 | ||||
| -rw-r--r-- | lib/puppet/util/log.rb | 2 | ||||
| -rw-r--r-- | lib/puppet/util/subclass_loader.rb | 83 |
3 files changed, 92 insertions, 11 deletions
diff --git a/lib/puppet/util/config.rb b/lib/puppet/util/config.rb index 117f87f92..e139d2217 100644 --- a/lib/puppet/util/config.rb +++ b/lib/puppet/util/config.rb @@ -301,7 +301,7 @@ class Puppet::Util::Config # the group can be set in the config file. The problem # is that we're using the word 'group' twice, which is # confusing. - if var == :group and section == Puppet.execname and @config.include?(:group) + if var == :group and section == Puppet[:name] and @config.include?(:group) @config[:group].value = value end next @@ -519,7 +519,7 @@ class Puppet::Util::Config # Convert our list of objects into a configuration file. def to_config - str = %{The configuration file for #{Puppet.execname}. Note that this file + str = %{The configuration file for #{Puppet[:name]}. Note that this file is likely to have unused configuration parameters in it; any parameter that's valid anywhere in Puppet can be in any config file, even if it's not used. @@ -719,18 +719,16 @@ Generated on #{Time.now}. def convert(value) return value unless value return value unless value.is_a? String - if value =~ /\$(\w+)/ - parent = $1 - if pval = @parent[parent] - newval = value.to_s.sub(/\$#{parent.to_s}/, pval.to_s) - #return File.join(newval.split("/")) - return newval + newval = value.gsub(/\$(\w+)|\$\{(\w+)\}/) do |value| + varname = $2 || $1 + if pval = @parent[varname] + pval else raise Puppet::DevError, "Could not find value for %s" % parent end - else - return value end + + return newval end def desc=(value) diff --git a/lib/puppet/util/log.rb b/lib/puppet/util/log.rb index 38f9d8de1..b427f7b61 100644 --- a/lib/puppet/util/log.rb +++ b/lib/puppet/util/log.rb @@ -167,7 +167,7 @@ class Puppet::Util::Log if Syslog.opened? Syslog.close end - name = Puppet.execname + name = Puppet[:name] name = "puppet-#{name}" unless name =~ /puppet/ options = Syslog::LOG_PID | Syslog::LOG_NDELAY diff --git a/lib/puppet/util/subclass_loader.rb b/lib/puppet/util/subclass_loader.rb new file mode 100644 index 000000000..4f24d5544 --- /dev/null +++ b/lib/puppet/util/subclass_loader.rb @@ -0,0 +1,83 @@ +# A module for loading subclasses into an array and retrieving +# them by name. Also sets up a method for each class so +# that you can just do Klass.subclass, rather than Klass.subclass(:subclass). +module Puppet::Util::SubclassLoader + attr_accessor :loader, :classloader + + # Iterate over each of the subclasses. + def each + @subclasses ||= [] + @subclasses.each { |c| yield c } + end + + # The hook method that sets up subclass loading. We need the name + # of the method to create and the path in which to look for them. + def handle_subclasses(name, path) + unless self.is_a?(Class) + raise ArgumentError, "Must be a class to use SubclassLoader" + end + @subclasses = [] + @loader = Puppet::Util::Autoload.new(self, + path, :wrap => false + ) + + @subclassname = name + + @classloader = self + + # Now create a method for retrieving these subclasses by name. Note + # that we're defining a class method here, not an instance. + meta_def(name) do |subname| + subname = subname.to_s.downcase + + unless c = @subclasses.find { |c| c.name.to_s.downcase == subname } + loader.load(subname) + c = @subclasses.find { |c| c.name.to_s.downcase == subname } + + # Now make the method that returns this subclass. This way we + # normally avoid the method_missing method. + if c and ! respond_to?(subname) + define_method(subname) { c } + end + end + return c + end + end + + # Add a new class to our list. Note that this has to handle subclasses of + # subclasses, thus the reason we're keeping track of the @@classloader. + def inherited(sub) + @subclasses ||= [] + @subclasses << sub + sub.classloader = self.classloader + if self.classloader == self + @subclasses << sub + else + @classloader.inherited(sub) + end + end + + # See if we can load a class. + def method_missing(method, *args) + unless self == self.classloader + super + end + return nil unless defined? @subclassname + if c = self.send(@subclassname, method) + return c + else + return nil + end + end + + # Retrieve or calculate a name. + def name + unless defined? @name + @name = self.to_s.sub(/.+::/, '').intern + end + + return @name + end +end + +# $Id$ |
