diff options
Diffstat (limited to 'lib/puppet/util')
31 files changed, 165 insertions, 154 deletions
diff --git a/lib/puppet/util/autoload.rb b/lib/puppet/util/autoload.rb index a1c44cdd6..27a361396 100644 --- a/lib/puppet/util/autoload.rb +++ b/lib/puppet/util/autoload.rb @@ -66,7 +66,7 @@ class Puppet::Util::Autoload end end - unless defined? @wrap + unless defined?(@wrap) @wrap = true end end diff --git a/lib/puppet/util/backups.rb b/lib/puppet/util/backups.rb index 6cabd248e..4270f528c 100644 --- a/lib/puppet/util/backups.rb +++ b/lib/puppet/util/backups.rb @@ -10,10 +10,10 @@ module Puppet::Util::Backups # let the path be specified file ||= self[:path] - return true unless FileTest.exists?(file) + return true unless FileTest.exists?(file) return perform_backup_with_bucket(file) if self.bucket - return perform_backup_with_backuplocal(file, self[:backup]) + return perform_backup_with_backuplocal(file, self[:backup]) end private @@ -84,5 +84,5 @@ module Puppet::Util::Backups sum = self.bucket.backup(f) self.info "Filebucketed %s to %s with sum %s" % [f, self.bucket.name, sum] return sum - end + end end diff --git a/lib/puppet/util/classgen.rb b/lib/puppet/util/classgen.rb index 1aa961399..83c302c01 100644 --- a/lib/puppet/util/classgen.rb +++ b/lib/puppet/util/classgen.rb @@ -52,7 +52,7 @@ module Puppet::Util::ClassGen options = symbolize_options(options) const = genconst_string(name, options) retval = false - if const_defined? const + if const_defined?(const) remove_const(const) retval = true end @@ -132,7 +132,7 @@ module Puppet::Util::ClassGen def handleclassconst(klass, name, options) const = genconst_string(name, options) - if const_defined? const + if const_defined?(const) if options[:overwrite] Puppet.info "Redefining %s in %s" % [name, self] remove_const(const) diff --git a/lib/puppet/util/command_line.rb b/lib/puppet/util/command_line.rb index 8c8eb91d5..9ccc94a23 100644 --- a/lib/puppet/util/command_line.rb +++ b/lib/puppet/util/command_line.rb @@ -1,7 +1,9 @@ module Puppet module Util class CommandLine - LegacyName = Hash.new{|h,k| k}.update({ + + LegacyName = Hash.new{|h,k| k}.update( + { 'agent' => 'puppetd', 'cert' => 'puppetca', 'doc' => 'puppetdoc', @@ -12,6 +14,7 @@ module Puppet 'resource' => 'ralsh', 'kick' => 'puppetrun', 'master' => 'puppetmasterd', + }) def initialize( zero = $0, argv = ARGV, stdin = STDIN ) diff --git a/lib/puppet/util/diff.rb b/lib/puppet/util/diff.rb index ac3a1c3c9..0e5deab82 100644 --- a/lib/puppet/util/diff.rb +++ b/lib/puppet/util/diff.rb @@ -35,9 +35,12 @@ module Puppet::Util::Diff diffs.each do |piece| begin - hunk = ::Diff::LCS::Hunk.new(data_old, data_new, piece, - context_lines, - file_length_difference) + + hunk = ::Diff::LCS::Hunk.new( + data_old, data_new, piece, + context_lines, + + file_length_difference) file_length_difference = hunk.file_length_difference next unless oldhunk # Hunks may overlap, which is why we need to be careful when our diff --git a/lib/puppet/util/docs.rb b/lib/puppet/util/docs.rb index 860a5453c..02374d8b7 100644 --- a/lib/puppet/util/docs.rb +++ b/lib/puppet/util/docs.rb @@ -22,7 +22,7 @@ module Puppet::Util::Docs self.send(m) }.join(" ") - if defined? @doc and @doc + if defined?(@doc) and @doc @doc + extra else extra diff --git a/lib/puppet/util/errors.rb b/lib/puppet/util/errors.rb index 0d2f2da9f..a44c1ca18 100644 --- a/lib/puppet/util/errors.rb +++ b/lib/puppet/util/errors.rb @@ -38,8 +38,7 @@ module Puppet::Util::Errors rescue Puppet::Error => detail raise adderrorcontext(detail) rescue => detail - message = options[:message] || "%s failed with error %s: %s" % - [self.class, detail.class, detail.to_s] + message = options[:message] || "%s failed with error %s: %s" % [self.class, detail.class, detail.to_s] error = options[:type].new(message) # We can't use self.fail here because it always expects strings, diff --git a/lib/puppet/util/fileparsing.rb b/lib/puppet/util/fileparsing.rb index 06f8a2e7d..7965532fd 100644 --- a/lib/puppet/util/fileparsing.rb +++ b/lib/puppet/util/fileparsing.rb @@ -64,7 +64,7 @@ module Puppet::Util::FileParsing self.separator ||= /\s+/ self.joiner ||= " " self.optional ||= [] - unless defined? @rollup + unless defined?(@rollup) @rollup = true end end @@ -354,7 +354,7 @@ module Puppet::Util::FileParsing # Whether to add a trailing separator to the file. Defaults to true def trailing_separator - if defined? @trailing_separator + if defined?(@trailing_separator) return @trailing_separator else return true diff --git a/lib/puppet/util/filetype.rb b/lib/puppet/util/filetype.rb index 898753226..c2291a3ab 100755 --- a/lib/puppet/util/filetype.rb +++ b/lib/puppet/util/filetype.rb @@ -18,9 +18,12 @@ class Puppet::Util::FileType def self.newfiletype(name, &block) @filetypes ||= {} - klass = genclass(name, + + klass = genclass( + name, :block => block, :prefix => "FileType", + :hash => @filetypes ) @@ -44,8 +47,7 @@ class Puppet::Util::FileType if Puppet[:trace] puts detail.backtrace end - raise Puppet::Error, "%s could not read %s: %s" % - [self.class, @path, detail] + raise Puppet::Error, "%s could not read %s: %s" % [self.class, @path, detail] end end @@ -62,8 +64,7 @@ class Puppet::Util::FileType if Puppet[:debug] puts detail.backtrace end - raise Puppet::Error, "%s could not write %s: %s" % - [self.class, @path, detail] + raise Puppet::Error, "%s could not write %s: %s" % [self.class, @path, detail] end end end @@ -260,7 +261,7 @@ class Puppet::Util::FileType begin output = Puppet::Util.execute(%w{crontab -l}, :uid => @path) if output.include?("You are not authorized to use the cron command") - raise Puppet::Error, "User %s not authorized to use cron" % @path + raise Puppet::Error, "User %s not authorized to use cron" % @path end return output rescue => detail diff --git a/lib/puppet/util/inifile.rb b/lib/puppet/util/inifile.rb index eb943fe13..0a957d447 100644 --- a/lib/puppet/util/inifile.rb +++ b/lib/puppet/util/inifile.rb @@ -113,8 +113,7 @@ module Puppet::Util::IniConfig text.each_line do |l| line += 1 if l.strip.empty? || "#;".include?(l[0,1]) || - (l.split(nil, 2)[0].downcase == "rem" && - l[0,1].downcase == "r") + (l.split(nil, 2)[0].downcase == "rem" && l[0,1].downcase == "r") # Whitespace or comment if section.nil? @files[file] << l diff --git a/lib/puppet/util/ldap/connection.rb b/lib/puppet/util/ldap/connection.rb index 19c53a2e6..18d9bf5ab 100644 --- a/lib/puppet/util/ldap/connection.rb +++ b/lib/puppet/util/ldap/connection.rb @@ -11,12 +11,12 @@ class Puppet::Util::Ldap::Connection # Return a default connection, using our default settings. def self.instance ssl = if Puppet[:ldaptls] - :tls - elsif Puppet[:ldapssl] - true - else - false - end + :tls + elsif Puppet[:ldapssl] + true + else + false + end options = {} options[:ssl] = ssl diff --git a/lib/puppet/util/log.rb b/lib/puppet/util/log.rb index 237887eb5..57be5f5ba 100644 --- a/lib/puppet/util/log.rb +++ b/lib/puppet/util/log.rb @@ -16,9 +16,12 @@ class Puppet::Util::Log # Create a new destination type. def self.newdesttype(name, options = {}, &block) - dest = genclass(name, :parent => Puppet::Util::Log::Destination, :prefix => "Dest", + + dest = genclass( + name, :parent => Puppet::Util::Log::Destination, :prefix => "Dest", :block => block, :hash => @desttypes, + :attributes => options ) dest.match(dest.name) @@ -234,7 +237,7 @@ class Puppet::Util::Log Log.newmessage(self) end - + def message=(msg) raise ArgumentError, "Puppet::Util::Log requires a message" unless msg @message = msg.to_s diff --git a/lib/puppet/util/log/destination.rb b/lib/puppet/util/log/destination.rb index 85959072e..81baa9301 100644 --- a/lib/puppet/util/log/destination.rb +++ b/lib/puppet/util/log/destination.rb @@ -29,7 +29,7 @@ class Puppet::Util::Log::Destination end def name - if defined? @name + if defined?(@name) return @name else return self.class.name diff --git a/lib/puppet/util/log/destinations.rb b/lib/puppet/util/log/destinations.rb index e748e5108..9fe61d484 100644 --- a/lib/puppet/util/log/destinations.rb +++ b/lib/puppet/util/log/destinations.rb @@ -30,8 +30,7 @@ Puppet::Util::Log.newdesttype :syslog do if msg.source == "Puppet" @syslog.send(msg.level, msg.to_s.gsub("%", '%%')) else - @syslog.send(msg.level, "(%s) %s" % - [msg.source.to_s.gsub("%", ""), + @syslog.send(msg.level, "(%s) %s" % [msg.source.to_s.gsub("%", ""), msg.to_s.gsub("%", '%%') ] ) @@ -43,14 +42,14 @@ Puppet::Util::Log.newdesttype :file do match(/^\//) def close - if defined? @file + if defined?(@file) @file.close @file = nil end end def flush - if defined? @file + if defined?(@file) @file.flush end end @@ -74,8 +73,7 @@ Puppet::Util::Log.newdesttype :file do end def handle(msg) - @file.puts("%s %s (%s): %s" % - [msg.time, msg.source, msg.level, msg.to_s]) + @file.puts("%s %s (%s): %s" % [msg.time, msg.source, msg.level, msg.to_s]) @file.flush if @autoflush end @@ -160,10 +158,10 @@ Puppet::Util::Log.newdesttype :host do def handle(msg) unless msg.is_a?(String) or msg.remote - unless defined? @hostname + unless defined?(@hostname) @hostname = Facter["hostname"].value end - unless defined? @domain + unless defined?(@domain) @domain = Facter["domain"].value if @domain @hostname += "." + @domain diff --git a/lib/puppet/util/log_paths.rb b/lib/puppet/util/log_paths.rb index 46f6c481d..b5bdc50de 100644 --- a/lib/puppet/util/log_paths.rb +++ b/lib/puppet/util/log_paths.rb @@ -5,7 +5,7 @@ module Puppet::Util::LogPaths # return the full path to us, for logging and rollback # some classes (e.g., FileTypeRecords) will have to override this def path - unless defined? @path + unless defined?(@path) @path = pathbuilder end diff --git a/lib/puppet/util/metric.rb b/lib/puppet/util/metric.rb index 8717fe0b9..cf8ed9ee1 100644 --- a/lib/puppet/util/metric.rb +++ b/lib/puppet/util/metric.rb @@ -19,7 +19,7 @@ class Puppet::Util::Metric end def basedir - if defined? @basedir + if defined?(@basedir) @basedir else Puppet[:rrddir] diff --git a/lib/puppet/util/monkey_patches.rb b/lib/puppet/util/monkey_patches.rb index a25be7d52..e5e835ef0 100644 --- a/lib/puppet/util/monkey_patches.rb +++ b/lib/puppet/util/monkey_patches.rb @@ -1,6 +1,6 @@ Process.maxgroups = 1024 -module RDoc +module RDoc def self.caller(skip=nil) in_gem_wrapper = false Kernel.caller.reject { |call| diff --git a/lib/puppet/util/provider_features.rb b/lib/puppet/util/provider_features.rb index 7986f6eae..86f30cc8b 100644 --- a/lib/puppet/util/provider_features.rb +++ b/lib/puppet/util/provider_features.rb @@ -107,7 +107,7 @@ module Puppet::Util::ProviderFeatures # Generate a module that sets up the boolean methods to test for given # features. def feature_module - unless defined? @feature_module + unless defined?(@feature_module) @features ||= {} @feature_module = ::Module.new const_set("FeatureModule", @feature_module) diff --git a/lib/puppet/util/pson.rb b/lib/puppet/util/pson.rb index 3356437b3..87afbe0c5 100644 --- a/lib/puppet/util/pson.rb +++ b/lib/puppet/util/pson.rb @@ -1,4 +1,4 @@ -# A simple module to provide consistency between how we use PSON and how +# A simple module to provide consistency between how we use PSON and how # ruby expects it to be used. Basically, we don't want to require # that the sender specify a class. # Ruby wants everyone to provide a 'type' field, and the PSON support diff --git a/lib/puppet/util/rdoc.rb b/lib/puppet/util/rdoc.rb index cb9610c0a..1bc48abd0 100644 --- a/lib/puppet/util/rdoc.rb +++ b/lib/puppet/util/rdoc.rb @@ -16,15 +16,18 @@ module Puppet::Util::RDoc require 'puppet/util/rdoc/parser' r = RDoc::RDoc.new - RDoc::RDoc::GENERATORS["puppet"] = RDoc::RDoc::Generator.new("puppet/util/rdoc/generators/puppet_generator.rb", - "PuppetGenerator".intern, - "puppet") + + RDoc::RDoc::GENERATORS["puppet"] = RDoc::RDoc::Generator.new( + "puppet/util/rdoc/generators/puppet_generator.rb", + "PuppetGenerator".intern, + + "puppet") # specify our own format & where to output options = [ "--fmt", "puppet", - "--quiet", - "--force-update", - "--exclude", "/modules/[^/]*/files/.*\.pp$", - "--op", outputdir ] + "--quiet", + "--force-update", + "--exclude", "/modules/[^/]*/files/.*\.pp$", + "--op", outputdir ] options += [ "--charset", charset] if charset options += files diff --git a/lib/puppet/util/rdoc/generators/puppet_generator.rb b/lib/puppet/util/rdoc/generators/puppet_generator.rb index 31181f05a..c2c27c8eb 100644 --- a/lib/puppet/util/rdoc/generators/puppet_generator.rb +++ b/lib/puppet/util/rdoc/generators/puppet_generator.rb @@ -215,9 +215,12 @@ module Generators gen_an_index(@classes, 'All Classes', RDoc::Page::CLASS_INDEX, "fr_class_index.html") @allfiles.each do |file| unless file['file'].context.file_relative_name =~ /\.rb$/ - gen_composite_index(file, - RDoc::Page::COMBO_INDEX, - "#{MODULE_DIR}/fr_#{file["file"].context.module_name}.html") + + gen_composite_index( + file, + RDoc::Page::COMBO_INDEX, + + "#{MODULE_DIR}/fr_#{file["file"].context.module_name}.html") end end end @@ -365,8 +368,8 @@ module Generators res = [] resources.each do |r| res << { - "name" => CGI.escapeHTML(r.name), - "aref" => CGI.escape(path_prefix)+"\#"+CGI.escape(r.aref) + "name" => CGI.escapeHTML(r.name), + "aref" => CGI.escape(path_prefix)+"\#"+CGI.escape(r.aref) } end res @@ -480,9 +483,12 @@ module Generators def write_on(f) value_hash - template = TemplatePage.new(RDoc::Page::BODYINC, - RDoc::Page::NODE_PAGE, - RDoc::Page::METHOD_LIST) + + template = TemplatePage.new( + RDoc::Page::BODYINC, + RDoc::Page::NODE_PAGE, + + RDoc::Page::METHOD_LIST) template.write_html_on(f, @values) end @@ -733,9 +739,12 @@ module Generators def write_on(f) value_hash - template = TemplatePage.new(RDoc::Page::BODYINC, - RDoc::Page::PLUGIN_PAGE, - RDoc::Page::PLUGIN_LIST) + + template = TemplatePage.new( + RDoc::Page::BODYINC, + RDoc::Page::PLUGIN_PAGE, + + RDoc::Page::PLUGIN_LIST) template.write_html_on(f, @values) end diff --git a/lib/puppet/util/reference.rb b/lib/puppet/util/reference.rb index a1679bcb6..f34e54b8c 100644 --- a/lib/puppet/util/reference.rb +++ b/lib/puppet/util/reference.rb @@ -70,7 +70,7 @@ class Puppet::Util::Reference def self.markdown(name, text) puts "Creating markdown for #{name} reference." dir = "/tmp/" + Puppet::PUPPETVERSION - FileUtils.mkdir(dir) unless File.directory?(dir) + FileUtils.mkdir(dir) unless File.directory?(dir) Puppet::Util.secure_open(dir + "/" + "#{name}.rst", "w") do |f| f.puts text end @@ -89,7 +89,7 @@ class Puppet::Util::Reference $stderr.puts output exit(1) end - + File.unlink(dir + "/" + "#{name}.rst") end diff --git a/lib/puppet/util/selinux.rb b/lib/puppet/util/selinux.rb index 3801ecdb0..28752cfac 100644 --- a/lib/puppet/util/selinux.rb +++ b/lib/puppet/util/selinux.rb @@ -14,7 +14,7 @@ require 'pathname' module Puppet::Util::SELinux def selinux_support? - unless defined? Selinux + unless defined?(Selinux) return false end if Selinux.is_selinux_enabled == 1 @@ -89,7 +89,7 @@ module Puppet::Util::SELinux # I believe that the OS should always provide at least a fall-through context # though on any well-running system. def set_selinux_context(file, value, component = false) - unless selinux_support? && selinux_label_support?(file) + unless selinux_support? && selinux_label_support?(file) return nil end diff --git a/lib/puppet/util/settings.rb b/lib/puppet/util/settings.rb index 56a13f847..3a823d30b 100644 --- a/lib/puppet/util/settings.rb +++ b/lib/puppet/util/settings.rb @@ -67,7 +67,7 @@ class Puppet::Util::Settings unsafe_clear(exceptcli) end end - + # Remove all set values, potentially skipping cli values. def unsafe_clear(exceptcli = false) @values.each do |name, values| @@ -227,8 +227,8 @@ class Puppet::Util::Settings if include?(v) #if there is only one value, just print it for back compatibility if v == val - puts value(val,env) - break + puts value(val,env) + break end puts "%s = %s" % [v, value(v,env)] else @@ -434,7 +434,7 @@ class Puppet::Util::Settings end def reuse - return unless defined? @used + return unless defined?(@used) @sync.synchronize do # yay, thread-safe new = @used @used = [] @@ -477,7 +477,7 @@ class Puppet::Util::Settings end def legacy_to_mode(type, param) - if not defined? @app_names then + if not defined?(@app_names) then require 'puppet/util/command_line' command_line = Puppet::Util::CommandLine.new @app_names = Puppet::Util::CommandLine::LegacyName.inject({}) do |hash, pair| @@ -524,7 +524,7 @@ class Puppet::Util::Settings # Clear the list of environments, because they cache, at least, the module path. # We *could* preferentially just clear them if the modulepath is changed, # but we don't really know if, say, the vardir is changed and the modulepath - # is defined relative to it. We need the defined? stuff because of loading + # is defined relative to it. We need the defined?(stuff) because of loading # order issues. Puppet::Node::Environment.clear if defined?(Puppet::Node) and defined?(Puppet::Node::Environment) end @@ -610,9 +610,9 @@ Generated on #{Time.now}. }.gsub(/^/, "# ") - # Add a section heading that matches our name. - if @config.include?(:run_mode) - str += "[%s]\n" % self[:run_mode] +# Add a section heading that matches our name. +if @config.include?(:run_mode) + str += "[%s]\n" % self[:run_mode] end eachsection do |section| persection(section) do |obj| @@ -689,7 +689,7 @@ Generated on #{Time.now}. end throw :foundval, nil end - + # If we didn't get a value, use the default val = @config[param].default if val.nil? @@ -769,16 +769,14 @@ Generated on #{Time.now}. tmpfile = file + ".tmp" sync = Sync.new unless FileTest.directory?(File.dirname(tmpfile)) - raise Puppet::DevError, "Cannot create %s; directory %s does not exist" % - [file, File.dirname(file)] + raise Puppet::DevError, "Cannot create %s; directory %s does not exist" % [file, File.dirname(file)] end sync.synchronize(Sync::EX) do File.open(file, ::File::CREAT|::File::RDWR, 0600) do |rf| rf.lock_exclusive do if File.exist?(tmpfile) - raise Puppet::Error, ".tmp file already exists for %s; Aborting locked write. Check the .tmp file and delete if appropriate" % - [file] + raise Puppet::Error, ".tmp file already exists for %s; Aborting locked write. Check the .tmp file and delete if appropriate" % [file] end # If there's a failure, remove our tmpfile diff --git a/lib/puppet/util/settings/boolean_setting.rb b/lib/puppet/util/settings/boolean_setting.rb index cc2704c4e..aa365fd8e 100644 --- a/lib/puppet/util/settings/boolean_setting.rb +++ b/lib/puppet/util/settings/boolean_setting.rb @@ -5,11 +5,9 @@ class Puppet::Util::Settings::BooleanSetting < Puppet::Util::Settings::Setting # get the arguments in getopt format def getopt_args if short - [["--#{name}", "-#{short}", GetoptLong::NO_ARGUMENT], - ["--no-#{name}", GetoptLong::NO_ARGUMENT]] + [["--#{name}", "-#{short}", GetoptLong::NO_ARGUMENT], ["--no-#{name}", GetoptLong::NO_ARGUMENT]] else - [["--#{name}", GetoptLong::NO_ARGUMENT], - ["--no-#{name}", GetoptLong::NO_ARGUMENT]] + [["--#{name}", GetoptLong::NO_ARGUMENT], ["--no-#{name}", GetoptLong::NO_ARGUMENT]] end end @@ -26,8 +24,7 @@ class Puppet::Util::Settings::BooleanSetting < Puppet::Util::Settings::Setting when true, "true"; return true when false, "false"; return false else - raise ArgumentError, "Invalid value '%s' for %s" % - [value.inspect, @name] + raise ArgumentError, "Invalid value '%s' for %s" % [value.inspect, @name] end end end diff --git a/lib/puppet/util/settings/file_setting.rb b/lib/puppet/util/settings/file_setting.rb index 6f0f315eb..815bdcf52 100644 --- a/lib/puppet/util/settings/file_setting.rb +++ b/lib/puppet/util/settings/file_setting.rb @@ -16,7 +16,7 @@ class Puppet::Util::Settings::FileSetting < Puppet::Util::Settings::Setting def group=(value) unless AllowedGroups.include?(value) - identifying_fields = [desc,name,default].compact.join(': ') + identifying_fields = [desc,name,default].compact.join(': ') raise SettingError, "Internal error: The :group setting for %s must be 'service', not '%s'" % [identifying_fields,value] end @group = value @@ -29,7 +29,7 @@ class Puppet::Util::Settings::FileSetting < Puppet::Util::Settings::Setting def owner=(value) unless AllowedOwners.include?(value) - identifying_fields = [desc,name,default].compact.join(': ') + identifying_fields = [desc,name,default].compact.join(': ') raise SettingError, "Internal error: The :owner setting for %s must be either 'root' or 'service', not '%s'" % [identifying_fields,value] end @owner = value @@ -115,8 +115,7 @@ class Puppet::Util::Settings::FileSetting < Puppet::Util::Settings::Setting name = $1 unless @settings.include?(name) raise ArgumentError, - "Settings parameter '%s' is undefined" % - name + "Settings parameter '%s' is undefined" % name end } end diff --git a/lib/puppet/util/settings/setting.rb b/lib/puppet/util/settings/setting.rb index e64cfd6c6..489dfd01d 100644 --- a/lib/puppet/util/settings/setting.rb +++ b/lib/puppet/util/settings/setting.rb @@ -54,7 +54,7 @@ class Puppet::Util::Settings::Setting end def iscreated? - if defined? @iscreated + if defined?(@iscreated) return @iscreated else return false @@ -62,7 +62,7 @@ class Puppet::Util::Settings::Setting end def set? - if defined? @value and ! @value.nil? + if defined?(@value) and ! @value.nil? return true else return false @@ -82,7 +82,7 @@ class Puppet::Util::Settings::Setting str = @desc.gsub(/^/, "# ") + "\n" # Add in a statement about the default. - if defined? @default and @default + if defined?(@default) and @default str += "# The default value is '%s'.\n" % @default end diff --git a/lib/puppet/util/storage.rb b/lib/puppet/util/storage.rb index de2f3825e..076952c1d 100644 --- a/lib/puppet/util/storage.rb +++ b/lib/puppet/util/storage.rb @@ -47,7 +47,7 @@ class Puppet::Util::Storage Puppet.settings.use(:main) unless FileTest.directory?(Puppet[:statedir]) unless File.exists?(Puppet[:statefile]) - unless defined? @@state and ! @@state.nil? + unless defined?(@@state) and ! @@state.nil? self.init end return @@ -61,15 +61,12 @@ class Puppet::Util::Storage begin @@state = YAML.load(file) rescue => detail - Puppet.err "Checksumfile %s is corrupt (%s); replacing" % - [Puppet[:statefile], detail] + Puppet.err "Checksumfile %s is corrupt (%s); replacing" % [Puppet[:statefile], detail] begin - File.rename(Puppet[:statefile], - Puppet[:statefile] + ".bad") + File.rename(Puppet[:statefile], Puppet[:statefile] + ".bad") rescue raise Puppet::Error, - "Could not rename corrupt %s; remove manually" % - Puppet[:statefile] + "Could not rename corrupt %s; remove manually" % Puppet[:statefile] end end end diff --git a/lib/puppet/util/subclass_loader.rb b/lib/puppet/util/subclass_loader.rb index b71ec7293..80a3672c9 100644 --- a/lib/puppet/util/subclass_loader.rb +++ b/lib/puppet/util/subclass_loader.rb @@ -19,7 +19,10 @@ module Puppet::Util::SubclassLoader raise ArgumentError, "Must be a class to use SubclassLoader" end @subclasses = [] - @loader = Puppet::Util::Autoload.new(self, + + @loader = Puppet::Util::Autoload.new( + self, + path, :wrap => false ) @@ -63,7 +66,7 @@ module Puppet::Util::SubclassLoader unless self == self.classloader super end - return nil unless defined? @subclassname + return nil unless defined?(@subclassname) if c = self.send(@subclassname, method) return c else @@ -73,7 +76,7 @@ module Puppet::Util::SubclassLoader # Retrieve or calculate a name. def name(dummy_argument=:work_arround_for_ruby_GC_bug) - unless defined? @name + unless defined?(@name) @name = self.to_s.sub(/.+::/, '').intern end diff --git a/lib/puppet/util/suidmanager.rb b/lib/puppet/util/suidmanager.rb index 777c36411..b8e7d534c 100644 --- a/lib/puppet/util/suidmanager.rb +++ b/lib/puppet/util/suidmanager.rb @@ -6,8 +6,7 @@ module Puppet::Util::SUIDManager extend Forwardable # Note groups= is handled specially due to a bug in OS X 10.6 - to_delegate_to_process = [ :euid=, :euid, :egid=, :egid, - :uid=, :uid, :gid=, :gid, :groups ] + to_delegate_to_process = [ :euid=, :euid, :egid=, :egid, :uid=, :uid, :gid=, :gid, :groups ] to_delegate_to_process.each do |method| def_delegator Process, method @@ -19,8 +18,8 @@ module Puppet::Util::SUIDManager require 'facter' # 'kernel' is available without explicitly loading all facts if Facter.value('kernel') != 'Darwin' - @osx_maj_ver = false - return @osx_maj_ver + @osx_maj_ver = false + return @osx_maj_ver end # But 'macosx_productversion_major' requires it. Facter.loadfacts @@ -28,7 +27,7 @@ module Puppet::Util::SUIDManager return @osx_maj_ver end module_function :osx_maj_ver - + def groups=(grouplist) if osx_maj_ver == '10.6' return true @@ -75,7 +74,7 @@ module Puppet::Util::SUIDManager raise ArgumentError, "Invalid id type %s" % type unless map.include?(type) ret = Puppet::Util.send(type, id) if ret == nil - raise Puppet::Error, "Invalid %s: %s" % [map[type], id] + raise Puppet::Error, "Invalid %s: %s" % [map[type], id] end return ret end diff --git a/lib/puppet/util/zaml.rb b/lib/puppet/util/zaml.rb index b0e22a3ff..88c660cac 100644 --- a/lib/puppet/util/zaml.rb +++ b/lib/puppet/util/zaml.rb @@ -1,14 +1,14 @@ # # ZAML -- A partial replacement for YAML, writen with speed and code clarity -# in mind. ZAML fixes one YAML bug (loading Exceptions) and provides +# in mind. ZAML fixes one YAML bug (loading Exceptions) and provides # a replacement for YAML.dump() unimaginatively called ZAML.dump(), -# which is faster on all known cases and an order of magnitude faster +# which is faster on all known cases and an order of magnitude faster # with complex structures. # # http://github.com/hallettj/zaml # # Authors: Markus Roberts, Jesse Hallett, Ian McIntosh, Igal Koshevoy, Simon Chiang -# +# require 'yaml' @@ -40,19 +40,19 @@ class ZAML end class Label # - # YAML only wants objects in the datastream once; if the same object - # occurs more than once, we need to emit a label ("&idxxx") on the + # YAML only wants objects in the datastream once; if the same object + # occurs more than once, we need to emit a label ("&idxxx") on the # first occurrence and then emit a back reference (*idxxx") on any - # subsequent occurrence(s). + # subsequent occurrence(s). # # To accomplish this we keeps a hash (by object id) of the labels of # the things we serialize as we begin to serialize them. The labels # initially serialize as an empty string (since most objects are only - # going to be be encountered once), but can be changed to a valid - # (by assigning it a number) the first time it is subsequently used, - # if it ever is. Note that we need to do the label setup BEFORE we - # start to serialize the object so that circular structures (in - # which we will encounter a reference to the object as we serialize + # going to be be encountered once), but can be changed to a valid + # (by assigning it a number) the first time it is subsequently used, + # if it ever is. Note that we need to do the label setup BEFORE we + # start to serialize the object so that circular structures (in + # which we will encounter a reference to the object as we serialize # it can be handled). # def self.counter_reset @@ -81,9 +81,9 @@ class ZAML def first_time_only(obj) if label = Label.for(obj) emit(label.reference) - else + else if @structured_key_prefix and not obj.is_a? String - emit(@structured_key_prefix) + emit(@structured_key_prefix) @structured_key_prefix = nil end emit(new_label_for(obj)) @@ -95,7 +95,7 @@ class ZAML @recent_nl = false unless s.kind_of?(Label) end def nl(s='') - emit(@indent || "\n") unless @recent_nl + emit(@indent || "\n") unless @recent_nl emit(s) @recent_nl = true end @@ -126,19 +126,19 @@ class Object end def to_zaml(z) z.first_time_only(self) { - z.emit(zamlized_class_name(Object)) + z.emit(zamlized_class_name(Object)) z.nested { instance_variables = to_yaml_properties if instance_variables.empty? z.emit(" {}") - else + else instance_variables.each { |v| z.nl v[1..-1].to_zaml(z) # Remove leading '@' z.emit(': ') instance_variable_get(v).to_zaml(z) } - end + end } } end @@ -221,50 +221,50 @@ class String gsub( /([\x80-\xFF])/ ) { |x| "\\x#{x.unpack("C")[0].to_s(16)}" } end def to_zaml(z) - z.first_time_only(self) { + z.first_time_only(self) { num = '[-+]?(0x)?\d+\.?\d*' case - when self == '' - z.emit('""') - # when self =~ /[\x00-\x08\x0B\x0C\x0E-\x1F\x80-\xFF]/ - # z.emit("!binary |\n") - # z.emit([self].pack("m*")) - when ( - (self =~ /\A(true|false|yes|no|on|null|off|#{num}(:#{num})*|!|=|~)$/i) or + when self == '' + z.emit('""') + # when self =~ /[\x00-\x08\x0B\x0C\x0E-\x1F\x80-\xFF]/ + # z.emit("!binary |\n") + # z.emit([self].pack("m*")) + when ( + (self =~ /\A(true|false|yes|no|on|null|off|#{num}(:#{num})*|!|=|~)$/i) or (self =~ /\A\n* /) or (self =~ /[\s:]$/) or (self =~ /^[>|][-+\d]*\s/i) or - (self[-1..-1] =~ /\s/) or + (self[-1..-1] =~ /\s/) or (self =~ /[\x00-\x08\x0B\x0C\x0E-\x1F\x80-\xFF]/) or - (self =~ /[,\[\]\{\}\r\t]|:\s|\s#/) or - (self =~ /\A([-:?!#&*'"]|<<|%.+:.)/) + (self =~ /[,\[\]\{\}\r\t]|:\s|\s#/) or + (self =~ /\A([-:?!#&*'"]|<<|%.+:.)/) ) - z.emit("\"#{escaped_for_zaml}\"") - when self =~ /\n/ - if self[-1..-1] == "\n" then z.emit('|+') else z.emit('|-') end - z.nested { split("\n",-1).each { |line| z.nl; z.emit(line.chomp("\n")) } } - z.nl - else - z.emit(self) - end + z.emit("\"#{escaped_for_zaml}\"") + when self =~ /\n/ + if self[-1..-1] == "\n" then z.emit('|+') else z.emit('|-') end + z.nested { split("\n",-1).each { |line| z.nl; z.emit(line.chomp("\n")) } } + z.nl + else + z.emit(self) + end } end end class Hash def to_zaml(z) - z.first_time_only(self) { + z.first_time_only(self) { z.nested { if empty? z.emit('{}') - else + else each_pair { |k, v| z.nl z.prefix_structured_keys('? ') { k.to_zaml(z) } z.emit(': ') v.to_zaml(z) } - end + end } } end @@ -273,13 +273,13 @@ end class Array def to_zaml(z) z.first_time_only(self) { - z.nested { + z.nested { if empty? z.emit('[]') - else + else each { |v| z.nl('- '); v.to_zaml(z) } - end - } + end + } } end end @@ -302,7 +302,7 @@ end class Range def to_zaml(z) z.first_time_only(self) { - z.emit(zamlized_class_name(Range)) + z.emit(zamlized_class_name(Range)) z.nested { z.nl z.emit('begin: ') |