diff options
author | luke <luke@980ebf18-57e1-0310-9a29-db15c13687c0> | 2006-09-05 01:51:23 +0000 |
---|---|---|
committer | luke <luke@980ebf18-57e1-0310-9a29-db15c13687c0> | 2006-09-05 01:51:23 +0000 |
commit | 617fe58626aa8a13af10071ca87f66d6363cf058 (patch) | |
tree | db9974c675c3b73cae56a253386f716e83bc8b6f /lib/puppet/provider/parsedfile.rb | |
parent | 8f39318ce46148c3bd483d790c965f277a4eb1c9 (diff) | |
download | puppet-617fe58626aa8a13af10071ca87f66d6363cf058.tar.gz puppet-617fe58626aa8a13af10071ca87f66d6363cf058.tar.xz puppet-617fe58626aa8a13af10071ca87f66d6363cf058.zip |
Removing all of the changes I made towards refactoring in the last couple of days. They have all been moved into the sync-retrieve-refactor branch. This branch will soon become 0.19.0, and will not include that refactoring.
git-svn-id: https://reductivelabs.com/svn/puppet/trunk@1555 980ebf18-57e1-0310-9a29-db15c13687c0
Diffstat (limited to 'lib/puppet/provider/parsedfile.rb')
-rwxr-xr-x | lib/puppet/provider/parsedfile.rb | 174 |
1 files changed, 0 insertions, 174 deletions
diff --git a/lib/puppet/provider/parsedfile.rb b/lib/puppet/provider/parsedfile.rb deleted file mode 100755 index f690c03a4..000000000 --- a/lib/puppet/provider/parsedfile.rb +++ /dev/null @@ -1,174 +0,0 @@ -require 'puppet' - -class Puppet::Provider::ParsedFile < Puppet::Provider - class << self - attr_accessor :filetype, :fields - attr_reader :path - attr_writer :fileobj - end - - # Override 'newstate' so that all states default to having the - # correct parent type - def self.newstate(name, options = {}, &block) - options[:parent] ||= Puppet::State::ParsedParam - super(name, options, &block) - end - - # Add another type var. - def self.initvars - @instances = [] - super - end - - # Add a non-object comment or whatever to our list of instances - def self.comment(line) - @instances << line - end - - # Override the default Puppet::Type method, because instances - # also need to be deleted from the @instances hash - def self.delete(child) - if @instances.include?(child) - @instances.delete(child) - end - super - end - - # Initialize the object if necessary. - def self.fileobj - @fileobj ||= @filetype.new(@path) - - @fileobj - end - - # Return the header placed at the top of each generated file, warning - # users that modifying this file manually is probably a bad idea. - def self.header -%{# HEADER: This file was autogenerated at #{Time.now} -# HEADER: by puppet. While it can still be managed manually, it -# HEADER: is definitely not recommended.\n} - end - - # Parse a file - # - # Subclasses must override this method. - def self.parse(text) - raise Puppet::DevError, "Parse was not overridden in %s" % - self.name - end - - # If they change the path, we need to get rid of our cache object - def self.path=(path) - @fileobj = nil - @path = path - end - - # Retrieve the text for the file. Returns nil in the unlikely - # event that it doesn't exist. - def self.retrieve - text = fileobj.read - if text.nil? or text == "" - # there is no file - return [] - else - self.parse(text) - end - end - - # Write out the file. - def self.store(instances) - if instances.empty? - Puppet.notice "No %s instances for %s" % [self.name, @path] - else - fileobj.write(self.to_file(instances)) - end - end - - # Collect all Host instances convert them into literal text. - def self.to_file(instances) - str = self.header() - unless instances.empty? - # Reject empty hashes and those with :ensure == :absent - str += instances.reject { |obj| - obj.is_a? Hash and (obj.empty? or obj[:ensure] == :absent) - }.collect { |obj| - # If it's a hash, convert it, otherwise just write it out - if obj.is_a?(Hash) - to_record(obj) - else - obj.to_s - end - }.join("\n") + "\n" - - return str - else - Puppet.notice "No %s instances" % self.name - return "" - end - end - - # A Simple wrapper method that subclasses can override, so there's more control - # over how instances are retrieved. - def allinstances - self.class.retrieve - end - - def clear - super - @instances = nil - end - - # Return a hash that maps to our info, if possible. - def hash - @instances = allinstances() - - if @instances and h = @instances.find do |o| - o.is_a? Hash and o[:name] == @model[:name] - end - @me = h - else - @me = {} - if @instances.empty? - @instances = [@me] - else - @instances << @me - end - end - - return @me - end - - def initialize(model) - super - - @instances = nil - end - - def store(hash = nil) - hash ||= self.model.to_hash - - unless @instances - self.hash - end - - if hash.empty? - @me.clear - else - hash.each do |name, value| - if @me[name] != hash[name] - @me[name] = hash[name] - end - end - - @me.each do |name, value| - unless hash.has_key? name - @me.delete(name) - end - end - end - - self.class.store(@instances) - end -end - -# $Id$ |