summaryrefslogtreecommitdiffstats
path: root/lib/puppet/util/settings.rb
diff options
context:
space:
mode:
authorMarkus Roberts <Markus@reality.com>2010-07-09 18:05:55 -0700
committerMarkus Roberts <Markus@reality.com>2010-07-09 18:05:55 -0700
commite8cf06336b64491a2dd7538a06651e0caaf6a48d (patch)
tree9f5d4c83d03fefa54c385462f60875056a58a82c /lib/puppet/util/settings.rb
parenteefccf252527dc5b69af5959b0b0e2ddb5c91b74 (diff)
downloadpuppet-e8cf06336b64491a2dd7538a06651e0caaf6a48d.tar.gz
puppet-e8cf06336b64491a2dd7538a06651e0caaf6a48d.tar.xz
puppet-e8cf06336b64491a2dd7538a06651e0caaf6a48d.zip
Code smell: Use string interpolation
* Replaced 83 occurances of (.*)" *[+] *([$@]?[\w_0-9.:]+?)(.to_s\b)?(?! *[*(%\w_0-9.:{\[]) with \1#{\2}" 3 Examples: The code: puts "PUPPET " + status + ": " + process + ", " + state becomes: puts "PUPPET " + status + ": " + process + ", #{state}" The code: puts "PUPPET " + status + ": #{process}" + ", #{state}" becomes: puts "PUPPET #{status}" + ": #{process}" + ", #{state}" The code: }.compact.join( "\n" ) + "\n" + t + "]\n" becomes: }.compact.join( "\n" ) + "\n#{t}" + "]\n" * Replaced 21 occurances of (.*)" *[+] *" with \1 3 Examples: The code: puts "PUPPET #{status}" + ": #{process}" + ", #{state}" becomes: puts "PUPPET #{status}" + ": #{process}, #{state}" The code: puts "PUPPET #{status}" + ": #{process}, #{state}" becomes: puts "PUPPET #{status}: #{process}, #{state}" The code: res = self.class.name + ": #{@name}" + "\n" becomes: res = self.class.name + ": #{@name}\n" * Don't use string concatenation to split lines unless they would be very long. Replaced 11 occurances of (.*)(['"]) *[+] *(['"])(.*) with 3 Examples: The code: o.define_head "The check_puppet Nagios plug-in checks that specified " + "Puppet process is running and the state file is no " + becomes: o.define_head "The check_puppet Nagios plug-in checks that specified Puppet process is running and the state file is no " + The code: o.separator "Mandatory arguments to long options are mandatory for " + "short options too." becomes: o.separator "Mandatory arguments to long options are mandatory for short options too." The code: o.define_head "The check_puppet Nagios plug-in checks that specified Puppet process is running and the state file is no " + "older than specified interval." becomes: o.define_head "The check_puppet Nagios plug-in checks that specified Puppet process is running and the state file is no older than specified interval." * Replaced no occurances of do (.*?) end with {\1} * Replaced 1488 occurances of "([^"\n]*%s[^"\n]*)" *% *(.+?)(?=$| *\b(do|if|while|until|unless|#)\b) with 20 Examples: The code: args[0].split(/\./).map do |s| "dc=%s"%[s] end.join(",") becomes: args[0].split(/\./).map do |s| "dc=#{s}" end.join(",") The code: puts "%s" % Puppet.version becomes: puts "#{Puppet.version}" The code: raise "Could not find information for %s" % node becomes: raise "Could not find information for #{node}" The code: raise Puppet::Error, "Cannot create %s: basedir %s is a file" % [dir, File.join(path)] becomes: raise Puppet::Error, "Cannot create #{dir}: basedir #{File.join(path)} is a file" The code: Puppet.err "Could not run %s: %s" % [client_class, detail] becomes: Puppet.err "Could not run #{client_class}: #{detail}" The code: raise "Could not find handler for %s" % arg becomes: raise "Could not find handler for #{arg}" The code: Puppet.err "Will not start without authorization file %s" % Puppet[:authconfig] becomes: Puppet.err "Will not start without authorization file #{Puppet[:authconfig]}" The code: raise Puppet::Error, "Could not deserialize catalog from pson: %s" % detail becomes: raise Puppet::Error, "Could not deserialize catalog from pson: #{detail}" The code: raise "Could not find facts for %s" % Puppet[:certname] becomes: raise "Could not find facts for #{Puppet[:certname]}" The code: raise ArgumentError, "%s is not readable" % path becomes: raise ArgumentError, "#{path} is not readable" The code: raise ArgumentError, "Invalid handler %s" % name becomes: raise ArgumentError, "Invalid handler #{name}" The code: debug "Executing '%s' in zone %s with '%s'" % [command, @resource[:name], str] becomes: debug "Executing '#{command}' in zone #{@resource[:name]} with '#{str}'" The code: raise Puppet::Error, "unknown cert type '%s'" % hash[:type] becomes: raise Puppet::Error, "unknown cert type '#{hash[:type]}'" The code: Puppet.info "Creating a new certificate request for %s" % Puppet[:certname] becomes: Puppet.info "Creating a new certificate request for #{Puppet[:certname]}" The code: "Cannot create alias %s: object already exists" % [name] becomes: "Cannot create alias #{name}: object already exists" The code: return "replacing from source %s with contents %s" % [metadata.source, metadata.checksum] becomes: return "replacing from source #{metadata.source} with contents #{metadata.checksum}" The code: it "should have a %s parameter" % param do becomes: it "should have a #{param} parameter" do The code: describe "when registring '%s' messages" % log do becomes: describe "when registring '#{log}' messages" do The code: paths = %w{a b c d e f g h}.collect { |l| "/tmp/iteration%stest" % l } becomes: paths = %w{a b c d e f g h}.collect { |l| "/tmp/iteration#{l}test" } The code: assert_raise(Puppet::Error, "Check '%s' did not fail on false" % check) do becomes: assert_raise(Puppet::Error, "Check '#{check}' did not fail on false") do
Diffstat (limited to 'lib/puppet/util/settings.rb')
-rw-r--r--lib/puppet/util/settings.rb46
1 files changed, 23 insertions, 23 deletions
diff --git a/lib/puppet/util/settings.rb b/lib/puppet/util/settings.rb
index 3a823d30b..afec53a8a 100644
--- a/lib/puppet/util/settings.rb
+++ b/lib/puppet/util/settings.rb
@@ -100,7 +100,7 @@ class Puppet::Util::Settings
elsif pval = self.value(varname)
pval
else
- raise Puppet::DevError, "Could not find value for %s" % value
+ raise Puppet::DevError, "Could not find value for #{value}"
end
end
@@ -220,7 +220,7 @@ class Puppet::Util::Settings
hash[name] = val
end
hash.sort { |a,b| a[0].to_s <=> b[0].to_s }.each do |name, val|
- puts "%s = %s" % [name, val]
+ puts "#{name} = #{val}"
end
else
val.split(/\s*,\s*/).sort.each do |v|
@@ -230,9 +230,9 @@ class Puppet::Util::Settings
puts value(val,env)
break
end
- puts "%s = %s" % [v, value(v,env)]
+ puts "#{v} = #{value(v,env)}"
else
- puts "invalid parameter: %s" % v
+ puts "invalid parameter: #{v}"
return false
end
end
@@ -382,7 +382,7 @@ class Puppet::Util::Settings
end
if type = hash[:type]
unless klass = {:setting => Setting, :file => FileSetting, :boolean => BooleanSetting}[type]
- raise ArgumentError, "Invalid setting type '%s'" % type
+ raise ArgumentError, "Invalid setting type '#{type}'"
end
hash.delete(:type)
else
@@ -394,7 +394,7 @@ class Puppet::Util::Settings
when String, Integer, Float # nothing
klass = Setting
else
- raise ArgumentError, "Invalid value '%s' for %s" % [hash[:default].inspect, hash[:name]]
+ raise ArgumentError, "Invalid value '#{hash[:default].inspect}' for #{hash[:name]}"
end
end
hash[:settings] = self
@@ -427,7 +427,7 @@ class Puppet::Util::Settings
# Reparse our config file, if necessary.
def reparse
if file and file.changed?
- Puppet.notice "Reparsing %s" % file.file
+ Puppet.notice "Reparsing #{file.file}"
parse
reuse()
end
@@ -501,7 +501,7 @@ class Puppet::Util::Settings
return
else
raise ArgumentError,
- "Attempt to assign a value to unknown configuration parameter %s" % param.inspect
+ "Attempt to assign a value to unknown configuration parameter #{param.inspect}"
end
end
if setting.respond_to?(:munge)
@@ -550,12 +550,12 @@ class Puppet::Util::Settings
hash[:name] = name
hash[:section] = section
if @config.include?(name)
- raise ArgumentError, "Parameter %s is already defined" % name
+ raise ArgumentError, "Parameter #{name} is already defined"
end
tryconfig = newsetting(hash)
if short = tryconfig.short
if other = @shortnames[short]
- raise ArgumentError, "Parameter %s is already using short name '%s'" % [other.name, short]
+ raise ArgumentError, "Parameter #{other.name} is already using short name '#{short}'"
end
@shortnames[short] = tryconfig
end
@@ -612,7 +612,7 @@ Generated on #{Time.now}.
# Add a section heading that matches our name.
if @config.include?(:run_mode)
- str += "[%s]\n" % self[:run_mode]
+ str += "[#{self[:run_mode]}]\n"
end
eachsection do |section|
persection(section) do |obj|
@@ -644,7 +644,7 @@ if @config.include?(:run_mode)
catalog = to_catalog(*sections).to_ral
rescue => detail
puts detail.backtrace if Puppet[:trace]
- Puppet.err "Could not create resources for managing Puppet's files and directories in sections %s: %s" % [sections.inspect, detail]
+ Puppet.err "Could not create resources for managing Puppet's files and directories in sections #{sections.inspect}: #{detail}"
# We need some way to get rid of any resources created during the catalog creation
# but not cleaned up.
@@ -657,7 +657,7 @@ if @config.include?(:run_mode)
if transaction.any_failed?
report = transaction.report
failures = report.logs.find_all { |log| log.level == :err }
- raise "Got %s failure(s) while initializing: %s" % [failures.length, failures.collect { |l| l.to_s }.join("; ")]
+ raise "Got #{failures.length} failure(s) while initializing: #{failures.collect { |l| l.to_s }.join("; ")}"
end
end
end
@@ -769,14 +769,14 @@ if @config.include?(:run_mode)
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 #{file}; directory #{File.dirname(file)} does not exist"
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 #{file}; Aborting locked write. Check the .tmp file and delete if appropriate"
end
# If there's a failure, remove our tmpfile
@@ -790,7 +790,7 @@ if @config.include?(:run_mode)
begin
File.rename(tmpfile, file)
rescue => detail
- Puppet.err "Could not rename %s to %s: %s" % [file, tmpfile, detail]
+ Puppet.err "Could not rename #{file} to #{tmpfile}: #{detail}"
File.unlink(tmpfile) if FileTest.exist?(tmpfile)
end
end
@@ -803,11 +803,11 @@ if @config.include?(:run_mode)
def get_config_file_default(default)
obj = nil
unless obj = @config[default]
- raise ArgumentError, "Unknown default %s" % default
+ raise ArgumentError, "Unknown default #{default}"
end
unless obj.is_a? FileSetting
- raise ArgumentError, "Default %s is not a file" % default
+ raise ArgumentError, "Default #{default} is not a file"
end
return obj
@@ -860,14 +860,14 @@ if @config.include?(:run_mode)
param, value = $1.intern, $2
result[param] = value
unless [:owner, :mode, :group].include?(param)
- raise ArgumentError, "Invalid file option '%s'" % param
+ raise ArgumentError, "Invalid file option '#{param}'"
end
if param == :mode and value !~ /^\d+$/
raise ArgumentError, "File modes must be numbers"
end
else
- raise ArgumentError, "Could not parse '%s'" % string
+ raise ArgumentError, "Could not parse '#{string}'"
end
end
''
@@ -937,7 +937,7 @@ if @config.include?(:run_mode)
raise
end
else
- error = Puppet::Error.new("Could not match line %s" % line)
+ error = Puppet::Error.new("Could not match line #{line}")
error.file = file
error.line = line
raise error
@@ -952,9 +952,9 @@ if @config.include?(:run_mode)
begin
return File.read(file)
rescue Errno::ENOENT
- raise ArgumentError, "No such file %s" % file
+ raise ArgumentError, "No such file #{file}"
rescue Errno::EACCES
- raise ArgumentError, "Permission denied to file %s" % file
+ raise ArgumentError, "Permission denied to file #{file}"
end
end