[Pkg-puppet-devel] [SCM] Puppet packaging for Debian branch, master, updated. debian/0.24.5-2-109-g5a96442

Micah Anderson micah at riseup.net
Sun Nov 30 00:48:21 UTC 2008


The following commit has been merged in the master branch:
commit dcd19d178a95b694063d61c073fd492636820dba
Merge: 852ffd10de34ed82b9b9127512844fe15bd63ff2 96e1d96333fa82362152ef52ea5f6be2b10f1db9 fd83fbd99033889b2e3cf197770a600b51162b19 e39ae97b082d8200d2215efaf4aab77e098a99fd
Author: Micah Anderson <micah at riseup.net>
Date:   Sat Nov 29 19:08:51 2008 -0500

    Merge branches 'debian', '500852' and '500848'
    
    Conflicts:
    	CHANGELOG
    	lib/puppet/type/tidy.rb

diff --combined lib/puppet/type/tidy.rb
index fe8bde9,fe8bde9,f0425d2,8cf705b..e37da5e
--- a/lib/puppet/type/tidy.rb
+++ b/lib/puppet/type/tidy.rb
@@@@@ -1,303 -1,303 -1,315 -1,320 +1,325 @@@@@
  - Puppet::Type.newtype(:tidy) do
  -     require 'puppet/file_serving/fileset'
  + module Puppet
  +     newtype(:tidy, :parent => Puppet.type(:file)) do
  +         @doc = "Remove unwanted files based on specific criteria.  Multiple
  +             criteria are OR'd together, so a file that is too large but is not
-- -            old enough will still get tidied."
++++            old enough will still get tidied.
++++            
++++            You must specify either the size or age of the file (or both) for
++++            files to be tidied."
    
  -     @doc = "Remove unwanted files based on specific criteria.  Multiple
  -         criteria are OR'd together, so a file that is too large but is not
  -         old enough will still get tidied.
  +         newparam(:path) do
  +             desc "The path to the file or directory to manage.  Must be fully
  +                 qualified."
  +             isnamevar
  +         end
    
  -         If you don't specify either 'age' or 'size', then all files will
  -         be removed.
  +         newparam(:matches) do
  +             desc "One or more file glob patterns, which restrict the list of
  +                 files to be tidied to those whose basenames match at least one
  +                 of the patterns specified.  Multiple patterns can be specified
  +                 using an array."
  +         end
    
  -         This resource type works by generating a file resource for every file
  -         that should be deleted and then letting that resource perform the
  -         actual deletion.
  -         "
  +         copyparam(Puppet.type(:file), :backup)
  +         
  +         newproperty(:ensure) do
  +             desc "An internal attribute used to determine which files should be removed."
    
  -     newparam(:path) do
  -         desc "The path to the file or directory to manage.  Must be fully
  -             qualified."
  -         isnamevar
  -     end
  +             @nodoc = true
  +             
  +             TATTRS = [:age, :size]
  +             
  +             defaultto :anything # just so we always get this property
  + 
  +             def change_to_s(currentvalue, newvalue)
  +                 start = "Tidying"
  +                 if @out.include?(:age)
  +                     start += ", older than %s seconds" % @resource.should(:age)
  +                 end
  +                 if @out.include?(:size)
  +                     start += ", larger than %s bytes" % @resource.should(:size)
  +                 end
  + 
  +                 start
  +             end
    
  -     newparam(:matches) do
  -         desc "One or more file glob patterns, which restrict the list of
  -             files to be tidied to those whose basenames match at least one
  -             of the patterns specified.  Multiple patterns can be specified
  -             using an array.
  +             def insync?(is)
++++                if File.lstat(resource[:path]).ftype == "directory" and ! @resource[:rmdirs]
++++                    self.debug "Not tidying directories"
++++                    return true
++++                end
++++
  +                 if is.is_a?(Symbol)
  +                     if [:absent, :notidy].include?(is)
  +                         return true
  +                     else
  +                         return false
  +                     end
  +                 else
  +                     @out = []
  +                     if @resource[:matches]
  +                         basename = File.basename(@resource[:path])
  +                         flags = File::FNM_DOTMATCH | File::FNM_PATHNAME
  +                         unless @resource[:matches].any? {|pattern| File.fnmatch(pattern, basename, flags) }
  +                             self.debug "No patterns specified match basename, skipping"
  +                             return true
  +                         end
  +                     end
  +                     TATTRS.each do |param|
  +                         if property = @resource.property(param)
  +                             self.debug "No is value for %s", [param] if is[property].nil?
  +                             unless property.insync?(is[property])
  +                                 @out << param
  +                             end
  +                         end
  +                     end
  +                     
  +                     if @out.length > 0
  +                         return false
  +                     else
  +                         return true
  +                     end
  +                 end
  +             end
                
  -             Note that the patterns are matched against the
  -             basename of each file -- that is, your glob patterns should not
  -             have any '/' characters in them, since you're only specifying
  -             against the last bit of the file."
  - 
  -         # Make sure we convert to an array.
  -         munge do |value|
  -             value = [value] unless value.is_a?(Array)
  -             value
  -         end
  +             def retrieve
  +                 stat = nil
  +                 unless stat = @resource.stat
  +                     return { self => :absent}
  +                 end
  +                 
  +                 if stat.ftype == "directory" and ! @resource[:rmdirs]
  +                     return {self => :notidy}
  +                 end
  + 
  +                 allprops = TATTRS.inject({}) { |prophash, param|
  +                     if property = @resource.property(param)
  +                         prophash[property] = property.assess(stat)
  +                     end
  +                     prophash
  +                 }
  +                 return { self => allprops } 
  +             end
    
  -         # Does a given path match our glob patterns, if any?  Return true
  -         # if no patterns have been provided.
  -         def tidy?(path, stat)
  -             basename = File.basename(path)
  -             flags = File::FNM_DOTMATCH | File::FNM_PATHNAME
  -             return true if value.find {|pattern| File.fnmatch(pattern, basename, flags) }
  -             return false
  +             def sync
  +                 file = @resource[:path]
  +                 case File.lstat(file).ftype
  +                 when "directory":
-- -                    if @resource[:rmdirs]
-- -                        subs = Dir.entries(@resource[:path]).reject { |d|
-- -                            d == "." or d == ".."
-- -                        }.length
-- -                        if subs > 0
-- -                            self.info "%s has %s children; not tidying" %
-- -                                [@resource[:path], subs]
-- -                            self.info Dir.entries(@resource[:path]).inspect
-- -                        else
-- -                            Dir.rmdir(@resource[:path])
-- -                        end
++++                    # If 'rmdirs' is disabled, then we would have never
++++                    # gotten to this method.
++++                    subs = Dir.entries(@resource[:path]).reject { |d|
++++                        d == "." or d == ".."
++++                    }.length
++++                    if subs > 0
++++                        self.info "%s has %s children; not tidying" %
++++                            [@resource[:path], subs]
++++                        self.info Dir.entries(@resource[:path]).inspect
  +                     else
-- -                        self.debug "Not tidying directories"
-- -                        return nil
++++                        Dir.rmdir(@resource[:path])
  +                     end
  +                 when "file":
  +                     @resource.handlebackup(file)
  +                     File.unlink(file)
  +                 when "link":
  +                     File.unlink(file)
  +                 else
  +                     self.fail "Cannot tidy files of type %s" %
  +                         File.lstat(file).ftype
  +                 end
  + 
  +                 return :file_tidied
  +             end
            end
  -     end
  - 
  -     newparam(:backup) do
  -         desc "Whether tidied files should be backed up.  Any values are passed
  -             directly to the file resources used for actual file deletion, so use
  -             its backup documentation to determine valid values."
  -     end
    
  -     newparam(:age) do
  -         desc "Tidy files whose age is equal to or greater than
  -             the specified time.  You can choose seconds, minutes,
  -             hours, days, or weeks by specifying the first letter of any
  -             of those words (e.g., '1w')."
  +         newproperty(:age) do
  +             desc "Tidy files whose age is equal to or greater than
  +                 the specified time.  You can choose seconds, minutes,
  +                 hours, days, or weeks by specifying the first letter of any
  +                 of those words (e.g., '1w')."
  + 
  +             @@ageconvertors = {
  +                 :s => 1,
  +                 :m => 60
  +             }
  + 
  +             @@ageconvertors[:h] = @@ageconvertors[:m] * 60
  +             @@ageconvertors[:d] = @@ageconvertors[:h] * 24
  +             @@ageconvertors[:w] = @@ageconvertors[:d] * 7
  + 
  +             def assess(stat)
  +                 type = nil
  +                 if stat.ftype == "directory"
  +                     type = :mtime
  +                 else
  +                     type = @resource[:type] || :atime
  +                 end
  +                 
  +                 return stat.send(type).to_i
  +             end
    
  -         @@ageconvertors = {
  -             :s => 1,
  -             :m => 60
  -         }
  +             def convert(unit, multi)
  +                 if num = @@ageconvertors[unit]
  +                     return num * multi
  +                 else
  +                     self.fail "Invalid age unit '%s'" % unit
  +                 end
  +             end
    
  -         @@ageconvertors[:h] = @@ageconvertors[:m] * 60
  -         @@ageconvertors[:d] = @@ageconvertors[:h] * 24
  -         @@ageconvertors[:w] = @@ageconvertors[:d] * 7
  +             def insync?(is)
  +                 if (Time.now.to_i - is) > self.should
  +                     return false
  +                 end
    
  -         def convert(unit, multi)
  -             if num = @@ageconvertors[unit]
  -                 return num * multi
  -             else
  -                 self.fail "Invalid age unit '%s'" % unit
  +                 true
                end
  -         end
    
  -         def tidy?(path, stat)
  -             # If the file's older than we allow, we should get rid of it.
  -             if (Time.now.to_i - stat.send(resource[:type]).to_i) > value
  -                 return true 
  -             else
  -                 return false
  +             munge do |age|
  +                 unit = multi = nil
  +                 case age
  +                 when /^([0-9]+)(\w)\w*$/:
  +                     multi = Integer($1)
  +                     unit = $2.downcase.intern
  +                 when /^([0-9]+)$/:
  +                     multi = Integer($1)
  +                     unit = :d
  +                 else
  +                     self.fail "Invalid tidy age %s" % age
  +                 end
  + 
  +                 convert(unit, multi)
                end
            end
    
  -         munge do |age|
  -             unit = multi = nil
  -             case age
  -             when /^([0-9]+)(\w)\w*$/:
  -                 multi = Integer($1)
  -                 unit = $2.downcase.intern
  -             when /^([0-9]+)$/:
  -                 multi = Integer($1)
  -                 unit = :d
  -             else
  -                 self.fail "Invalid tidy age %s" % age
  +         newproperty(:size) do
  +             desc "Tidy files whose size is equal to or greater than
  +                 the specified size.  Unqualified values are in kilobytes, but
  +                 *b*, *k*, and *m* can be appended to specify *bytes*, *kilobytes*,
  +                 and *megabytes*, respectively.  Only the first character is
  +                 significant, so the full word can also be used."
  + 
  +             @@sizeconvertors = {
  +                 :b => 0,
  +                 :k => 1,
  +                 :m => 2,
  +                 :g => 3
  +             }
  + 
  +             # Retrieve the size from a File::Stat object
  +             def assess(stat)
  +                 return stat.size
                end
    
  -             convert(unit, multi)
  -         end
  -     end
  - 
  -     newparam(:size) do
  -         desc "Tidy files whose size is equal to or greater than
  -             the specified size.  Unqualified values are in kilobytes, but
  -             *b*, *k*, and *m* can be appended to specify *bytes*, *kilobytes*,
  -             and *megabytes*, respectively.  Only the first character is
  -             significant, so the full word can also be used."
  - 
  -         @@sizeconvertors = {
  -             :b => 0,
  -             :k => 1,
  -             :m => 2,
  -             :g => 3
  -         }
  - 
  -         def convert(unit, multi)
  -             if num = @@sizeconvertors[unit]
  -                 result = multi
  -                 num.times do result *= 1024 end
  -                 return result
  -             else
  -                 self.fail "Invalid size unit '%s'" % unit
  +             def convert(unit, multi)
  +                 if num = @@sizeconvertors[unit]
  +                     result = multi
  +                     num.times do result *= 1024 end
  +                     return result
  +                 else
  +                     self.fail "Invalid size unit '%s'" % unit
  +                 end
                end
  -         end
  -         
  -         def tidy?(path, stat)
  -             if stat.size > value
  -                 return true
  -             else
  -                 return false
  +             
  +             def insync?(is)
  +                 if is > self.should
  +                     return false
  +                 end
  + 
  +                 true
                end
  -         end
  -         
  -         munge do |size|
  -             case size
  -             when /^([0-9]+)(\w)\w*$/:
  -                 multi = Integer($1)
  -                 unit = $2.downcase.intern
  -             when /^([0-9]+)$/:
  -                 multi = Integer($1)
  -                 unit = :k
  -             else
  -                 self.fail "Invalid tidy size %s" % age
  +             
  +             munge do |size|
  +                 case size
  +                 when /^([0-9]+)(\w)\w*$/:
  +                     multi = Integer($1)
  +                     unit = $2.downcase.intern
  +                 when /^([0-9]+)$/:
  +                     multi = Integer($1)
  +                     unit = :k
  +                 else
  +                     self.fail "Invalid tidy size %s" % age
  +                 end
  + 
  +                 convert(unit, multi)
                end
  - 
  -             convert(unit, multi)
            end
  -     end
    
  -     newparam(:type) do
  -         desc "Set the mechanism for determining age."
  -         
  -         newvalues(:atime, :mtime, :ctime)
  +         newparam(:type) do
  +             desc "Set the mechanism for determining age."
  +             
  +             newvalues(:atime, :mtime, :ctime)
    
  -         defaultto :atime
  -     end
  +             defaultto :atime
  +         end
    
  -     newparam(:recurse) do
  -         desc "If target is a directory, recursively descend
  -             into the directory looking for files to tidy."
  - 
  -         newvalues(:true, :false, :inf, /^[0-9]+$/)
  - 
  -         # Replace the validation so that we allow numbers in
  -         # addition to string representations of them.
  -         validate { |arg| }
  -         munge do |value|
  -             newval = super(value)
  -             case newval
  -             when :true, :inf: true
  -             when :false: false
  -             when Integer, Fixnum, Bignum: value
  -             when /^\d+$/: Integer(value)
  -             else
  -                 raise ArgumentError, "Invalid recurse value %s" % value.inspect
  +         newparam(:recurse) do
  +             desc "If target is a directory, recursively descend
  +                 into the directory looking for files to tidy."
+++ 
+++             newvalues(:true, :false, :inf, /^[0-9]+$/)
+++ 
+++             # Replace the validation so that we allow numbers in
+++             # addition to string representations of them.
+++             validate { |arg| }
+++             munge do |value|
+++                 newval = super(value)
+++                 case newval
+++                 when :true, :inf: true
+++                 when :false: false
+++                 when Integer, Fixnum, Bignum: value
+++                 when /^\d+$/: Integer(value)
+++                 else
+++                     raise ArgumentError, "Invalid recurse value %s" % value.inspect
+++                 end
++              end
            end
  -     end
  - 
  -     newparam(:rmdirs, :boolean => true) do
  -         desc "Tidy directories in addition to files; that is, remove
  -             directories whose age is older than the specified criteria.
  -             This will only remove empty directories, so all contained
  -             files must also be tidied before a directory gets removed."
  - 
  -         newvalues :true, :false
  -     end
  -     
  -     # Erase PFile's validate method
  -     validate do
  -     end
  - 
  -     def self.instances
  -         []
  -     end
  - 
  -     @depthfirst = true
    
  -     def initialize(hash)
  -         super
  - 
  -         # only allow backing up into filebuckets
  -         unless self[:backup].is_a? Puppet::Network::Client.dipper
  -             self[:backup] = false
  +         newparam(:rmdirs) do
  +             desc "Tidy directories in addition to files; that is, remove
  +                 directories whose age is older than the specified criteria.
  +                 This will only remove empty directories, so all contained
  +                 files must also be tidied before a directory gets removed."
            end
  -     end
  -     
  -     # Make a file resource to remove a given file.
  -     def mkfile(path)
  -         # Force deletion, so directories actually get deleted.
  -         Puppet::Type.type(:file).create :path => path, :backup => self[:backup], :ensure => :absent, :force => true
  -     end
  - 
  -     def retrieve
  -         # Our ensure property knows how to retrieve everything for us.
  -         if obj = @parameters[:ensure] 
  -             return obj.retrieve
  -         else
  -             return {}
  +         
  +         # Erase PFile's validate method
  +         validate do
            end
  -     end
  -     
  -     # Hack things a bit so we only ever check the ensure property.
  -     def properties
  -         []
  -     end
  - 
  -     def eval_generate
  -         []
  -     end
  - 
  -     def generate
  -         return [] unless stat(self[:path])
    
  -         if self[:recurse]
  -             files = Puppet::FileServing::Fileset.new(self[:path], :recurse => self[:recurse]).files.collect do |f|
  -                 f == "." ? self[:path] : File.join(self[:path], f)
  -             end
  -         else
  -             files = [self[:path]]
  +         def self.instances
  +             []
            end
  -         result = files.find_all { |path| tidy?(path) }.collect { |path| mkfile(path) }.each { |file| notice "Tidying %s" % file.ref }.sort { |a,b| b[:path] <=> a[:path] }
    
  -         # No need to worry about relationships if we don't have rmdirs; there won't be
  -         # any directories.
  -         return result unless rmdirs?
  +         @depthfirst = true
    
  -         # Now make sure that all directories require the files they contain, if all are available,
  -         # so that a directory is emptied before we try to remove it.
  -         files_by_name = result.inject({}) { |hash, file| hash[file[:path]] = file; hash }
  +         def initialize(hash)
  +             super
    
  -         files_by_name.keys.sort { |a,b| b <=> b }.each do |path|
  -             dir = File.dirname(path)
  -             next unless resource = files_by_name[dir]
  -             if resource[:require] 
  -                 resource[:require] << [:file, path]
  -             else
  -                 resource[:require] = [[:file, path]]
  +             unless  @parameters.include?(:age) or
  +                     @parameters.include?(:size)
  +                 unless FileTest.directory?(self[:path])
  +                     # don't do size comparisons for directories
  +                     self.fail "Tidy must specify size, age, or both"
  +                 end
                end
  -         end
  - 
  -         return result
  -     end
    
  -     # Does a given path match our glob patterns, if any?  Return true
  -     # if no patterns have been provided.
  -     def matches?(path)
  -         return true unless self[:matches]
  - 
  -         basename = File.basename(path)
  -         flags = File::FNM_DOTMATCH | File::FNM_PATHNAME
  -         if self[:matches].find {|pattern| File.fnmatch(pattern, basename, flags) }
  -             return true
  -         else
  -             debug "No specified patterns match %s, not tidying" % path
  -             return false
  +             # only allow backing up into filebuckets
  +             unless self[:backup].is_a? Puppet::Network::Client.dipper
  +                 self[:backup] = false
  +             end
            end
  -     end
  - 
  -     # Should we remove the specified file?
  -     def tidy?(path)
  -         return false unless stat = self.stat(path)
  - 
  -         return false if stat.ftype == "directory" and ! rmdirs?
  - 
  -         # The 'matches' parameter isn't OR'ed with the other tests --
  -         # it's just used to reduce the list of files we can match.
  -         return false if param = parameter(:matches) and ! param.tidy?(path, stat)
  - 
  -         tested = false
  -         [:age, :size].each do |name|
  -             next unless param = parameter(name)
  -             tested = true
  -             return true if param.tidy?(path, stat)
  +         
  +         def retrieve
  +             # Our ensure property knows how to retrieve everything for us.
  +             if obj = @parameters[:ensure] 
  +                 return obj.retrieve
  +             else
  +                 return {}
  +             end
            end
  - 
  -         # If they don't specify either, then the file should always be removed.
  -         return true unless tested
  -         return false
  -     end
  - 
  -     def stat(path)
  -         begin
  -             File.lstat(path)
  -         rescue Errno::ENOENT => error
  -             info "File does not exist"
  -             return nil
  -         rescue Errno::EACCES => error
  -             warning "Could not stat; permission denied"
  -             return nil
  +         
  +         # Hack things a bit so we only ever check the ensure property.
  +         def properties
  +             []
            end
        end
    end
  + 

-- 
Puppet packaging for Debian



More information about the Pkg-puppet-devel mailing list