Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(PUP-7042) Mark strings in type #5566

Merged
merged 2 commits into from Apr 12, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions lib/puppet/type/augeas.rb
Expand Up @@ -164,7 +164,7 @@
validate do
has_lens = !self[:lens].nil?
has_incl = !self[:incl].nil?
self.fail "You must specify both the lens and incl parameters, or neither." if has_lens != has_incl
self.fail _("You must specify both the lens and incl parameters, or neither.") if has_lens != has_incl
end

newparam(:show_diff, :boolean => true, :parent => Puppet::Parameter::Boolean) do
Expand All @@ -188,7 +188,7 @@

# Make output a bit prettier
def change_to_s(currentvalue, newvalue)
"executed successfully"
_("executed successfully")
end

# if the onlyif resource is provided, then the value is parsed.
Expand Down
8 changes: 4 additions & 4 deletions lib/puppet/type/cron.rb
Expand Up @@ -195,7 +195,7 @@ def should=(ary)
if retval
return retval.to_s
else
self.fail "#{value} is not a valid #{self.class.name}"
self.fail _("%{value} is not a valid %{name}") % { value: value, name: self.class.name }
end
end
end
Expand Down Expand Up @@ -253,7 +253,7 @@ def specials
end

validate do |value|
raise ArgumentError, "Invalid special schedule #{value.inspect}" unless specials.include?(value)
raise ArgumentError, _("Invalid special schedule %{value}") % { value: value.inspect } unless specials.include?(value)
end

def munge(value)
Expand Down Expand Up @@ -326,7 +326,7 @@ def alpha

validate do |value|
unless value =~ /^\s*(\w+)\s*=\s*(.*)\s*$/ or value == :absent or value == "absent"
raise ArgumentError, "Invalid environment setting #{value.inspect}"
raise ArgumentError, _("Invalid environment setting %{value}") % { value: value.inspect }
end
end

Expand Down Expand Up @@ -433,7 +433,7 @@ def should_to_s(newvalue = @should)
[ :minute, :hour, :weekday, :monthday, :month ].each do |field|
next unless self[field]
next if self[field] == :absent
raise ArgumentError, "#{self.ref} cannot specify both a special schedule and a value for #{field}"
raise ArgumentError, _("%{cron} cannot specify both a special schedule and a value for %{field}") % { cron: self.ref, field: field }
end
end

Expand Down
32 changes: 16 additions & 16 deletions lib/puppet/type/exec.rb
Expand Up @@ -101,7 +101,7 @@ def event_name

# Make output a bit prettier
def change_to_s(currentvalue, newvalue)
"executed successfully"
_("executed successfully")
end

# First verify that all of our checks pass.
Expand Down Expand Up @@ -135,7 +135,7 @@ def sync
end
end
rescue Timeout::Error
self.fail Puppet::Error, "Command exceeded timeout", $!
self.fail Puppet::Error, _("Command exceeded timeout"), $!
end

if log = @resource[:logoutput]
Expand All @@ -159,9 +159,9 @@ def sync
unless self.should.include?(@status.exitstatus.to_s)
if @resource.parameter(:command).sensitive
# Don't print sensitive commands in the clear
self.fail("[command redacted] returned #{@status.exitstatus} instead of one of [#{self.should.join(",")}]")
self.fail(_("[command redacted] returned %{status} instead of one of [%{expected}]") % { status: @status.exitstatus, expected: self.should.join(",") })
else
self.fail("'#{self.resource[:command]}' returned #{@status.exitstatus} instead of one of [#{self.should.join(",")}]")
self.fail(_("'%{cmd}' returned %{status} instead of one of [%{expected}]") % { cmd: self.resource[:command], status: @status.exitstatus, expected: self.should.join(",") })
end
end

Expand All @@ -179,7 +179,7 @@ def sync
any output is logged at the `err` log level."

validate do |command|
raise ArgumentError, "Command must be a String, got value of class #{command.class}" unless command.is_a? String
raise ArgumentError, _("Command must be a String, got value of class %{klass}") % { klass: command.class } unless command.is_a? String
end
end

Expand Down Expand Up @@ -208,9 +208,9 @@ def value=(*values)

validate do |user|
if Puppet.features.microsoft_windows?
self.fail "Unable to execute commands as other users on Windows"
self.fail _("Unable to execute commands as other users on Windows")
elsif !Puppet.features.root? && resource.current_username() != user
self.fail "Only root can execute commands as other users"
self.fail _("Only root can execute commands as other users")
end
end
end
Expand Down Expand Up @@ -261,7 +261,7 @@ def value=(*values)
values = [values] unless values.is_a? Array
values.each do |value|
unless value =~ /\w+=/
raise ArgumentError, "Invalid environment setting '#{value}'"
raise ArgumentError, _("Invalid environment setting '%{value}'") % { value: value }
end
end
end
Expand All @@ -274,7 +274,7 @@ def value=(*values)
if value =~ /^0?[0-7]{1,4}$/
return value.to_i(8)
else
raise Puppet::Error, "The umask specification is invalid: #{value.inspect}"
raise Puppet::Error, _("The umask specification is invalid: %{value}") % { value: value.inspect }
end
end
end
Expand All @@ -290,7 +290,7 @@ def value=(*values)
begin
value = Float(value)
rescue ArgumentError
raise ArgumentError, "The timeout must be a number.", $!.backtrace
raise ArgumentError, _("The timeout must be a number."), $!.backtrace
end
[value, 0.0].max
end
Expand All @@ -308,11 +308,11 @@ def value=(*values)
munge do |value|
if value.is_a?(String)
unless value =~ /^[\d]+$/
raise ArgumentError, "Tries must be an integer"
raise ArgumentError, _("Tries must be an integer")
end
value = Integer(value)
end
raise ArgumentError, "Tries must be an integer >= 1" if value < 1
raise ArgumentError, _("Tries must be an integer >= 1") if value < 1
value
end

Expand All @@ -325,11 +325,11 @@ def value=(*values)
munge do |value|
if value.is_a?(String)
unless value =~ /^[-\d.]+$/
raise ArgumentError, "try_sleep must be a number"
raise ArgumentError, _("try_sleep must be a number")
end
value = Float(value)
end
raise ArgumentError, "try_sleep cannot be a negative number" if value < 0
raise ArgumentError, _("try_sleep cannot be a negative number") if value < 0
value
end

Expand Down Expand Up @@ -443,7 +443,7 @@ def check(value)
begin
output, status = provider.run(value, true)
rescue Timeout::Error
err "Check #{value.inspect} exceeded timeout"
err _("Check %{value} exceeded timeout") % { value: value.inspect }
return false
end

Expand Down Expand Up @@ -494,7 +494,7 @@ def check(value)
begin
output, status = provider.run(value, true)
rescue Timeout::Error
err "Check #{value.inspect} exceeded timeout"
err _("Check %{value} exceeded timeout") % { value: value.inspect }
return false
end

Expand Down
41 changes: 20 additions & 21 deletions lib/puppet/type/file.rb
Expand Up @@ -53,7 +53,7 @@ def self.title_patterns

validate do |value|
unless Puppet::Util.absolute_path?(value)
fail Puppet::Error, "File paths must be fully qualified, not '#{value}'"
fail Puppet::Error, _("File paths must be fully qualified, not '%{path}'") % { path: value }
end
end

Expand Down Expand Up @@ -121,7 +121,7 @@ def self.title_patterns
when String
value
else
self.fail "Invalid backup type #{value.inspect}"
self.fail _("Invalid backup type %{value}") % { value: value.inspect }
end
end
end
Expand Down Expand Up @@ -165,7 +165,7 @@ def self.title_patterns
when :false; false
when :remote; :remote
else
self.fail "Invalid recurse value #{value.inspect}"
self.fail _("Invalid recurse value %{value}") % { value: value.inspect }
end
end
end
Expand Down Expand Up @@ -198,7 +198,7 @@ def self.title_patterns
when Integer; value
when /^\d+$/; Integer(value)
else
self.fail "Invalid recurselimit value #{value.inspect}"
self.fail _("Invalid recurselimit value %{value}") % { value: value.inspect }
end
end
end
Expand Down Expand Up @@ -368,28 +368,28 @@ def self.title_patterns
end
creator_count += 1 if @parameters.include?(:source)

self.fail "You cannot specify more than one of #{CREATORS.collect { |p| p.to_s}.join(", ")}" if creator_count > 1
self.fail _("You cannot specify more than one of %{creators}") % { creators: CREATORS.collect { |p| p.to_s}.join(", ") } if creator_count > 1

self.fail "You cannot specify a remote recursion without a source" if !self[:source] && self[:recurse] == :remote
self.fail _("You cannot specify a remote recursion without a source") if !self[:source] && self[:recurse] == :remote

self.fail "You cannot specify source when using checksum 'none'" if self[:checksum] == :none && !self[:source].nil?
self.fail _("You cannot specify source when using checksum 'none'") if self[:checksum] == :none && !self[:source].nil?

SOURCE_ONLY_CHECKSUMS.each do |checksum_type|
self.fail "You cannot specify content when using checksum '#{checksum_type}'" if self[:checksum] == checksum_type && !self[:content].nil?
self.fail _("You cannot specify content when using checksum '%{checksum_type}'") % { checksum_type: checksum_type } if self[:checksum] == checksum_type && !self[:content].nil?
end

self.warning "Possible error: recurselimit is set but not recurse, no recursion will happen" if !self[:recurse] && self[:recurselimit]
self.warning _("Possible error: recurselimit is set but not recurse, no recursion will happen") if !self[:recurse] && self[:recurselimit]

if @parameters[:content] && @parameters[:content].actual_content
# Now that we know the checksum, update content (in case it was created before checksum was known).
@parameters[:content].value = @parameters[:checksum].sum(@parameters[:content].actual_content)
end

if self[:checksum] && self[:checksum_value] && !send("#{self[:checksum]}?", self[:checksum_value])
self.fail "Checksum value '#{self[:checksum_value]}' is not a valid checksum type #{self[:checksum]}"
self.fail _("Checksum value '%{value}' is not a valid checksum type %{checksum}") % { value: self[:checksum_value], checksum: self[:checksum] }
end

self.warning "Checksum value is ignored unless content or source are specified" if self[:checksum_value] && !self[:content] && !self[:source]
self.warning _("Checksum value is ignored unless content or source are specified") if self[:checksum_value] && !self[:content] && !self[:source]

provider.validate if provider.respond_to?(:validate)
end
Expand Down Expand Up @@ -427,11 +427,11 @@ def bucket
return nil if backup =~ /^\./

unless catalog or backup == "puppet"
fail "Can not find filebucket for backups without a catalog"
fail _("Can not find filebucket for backups without a catalog")
end

unless catalog and filebucket = catalog.resource(:filebucket, backup) or backup == "puppet"
fail "Could not find filebucket #{backup} specified in backup"
fail _("Could not find filebucket %{backup} specified in backup") % { backup: backup }
end

return default_bucket unless filebucket
Expand Down Expand Up @@ -737,7 +737,7 @@ def remove_existing(should)
when "link", "file"
return remove_file(current_type, wanted_type)
else
self.fail "Could not back up files of type #{current_type}"
self.fail _("Could not back up files of type %{current_type}") % { current_type: current_type }
end
end

Expand All @@ -747,9 +747,7 @@ def retrieve
# catalog validation (because that would be a breaking change from Puppet 4).
if Puppet.features.microsoft_windows? && parameter(:source) &&
[:use, :use_when_creating].include?(self[:source_permissions])
err_msg = "Copying owner/mode/group from the source file on Windows" <<
" is not supported; use source_permissions => ignore."

err_msg = _("Copying owner/mode/group from the source file on Windows is not supported; use source_permissions => ignore.")
if self[:owner] == nil || self[:group] == nil || self[:mode] == nil
# Fail on Windows if source permissions are being used and the file resource
# does not have mode owner, group, and mode all set (which would take precedence).
Expand Down Expand Up @@ -830,7 +828,7 @@ def stat
rescue Errno::ENOTDIR => error
nil
rescue Errno::EACCES => error
warning "Could not stat; permission denied"
warning _("Could not stat; permission denied")
nil
end
end
Expand Down Expand Up @@ -952,7 +950,7 @@ def remove_directory(wanted_type)
stat_needed
true
else
notice "Not removing directory; use 'force' to override"
notice _("Not removing directory; use 'force' to override")
false
end
end
Expand All @@ -976,7 +974,8 @@ def stat_needed
# @return [void]
def backup_existing
unless perform_backup
raise Puppet::Error, "Could not back up; will not replace"
#TRANSLATORS refers to a file which could not be backed up
raise Puppet::Error, _("Could not back up; will not replace")
end
end

Expand All @@ -990,7 +989,7 @@ def fail_if_checksum_is_wrong(path, content_checksum)
newsum = parameter(:checksum).sum_file(path)
return if [:absent, nil, content_checksum].include?(newsum)

self.fail "File written to disk did not match checksum; discarding changes (#{content_checksum} vs #{newsum})"
self.fail _("File written to disk did not match checksum; discarding changes (%{content_checksum} vs %{newsum})") % { content_checksum: content_checksum, newsum: newsum }
end

def write_temporary_file?
Expand Down
6 changes: 3 additions & 3 deletions lib/puppet/type/filebucket.rb
Expand Up @@ -71,11 +71,11 @@ module Puppet

validate do |value|
if value.is_a? Array
raise ArgumentError, "You can only have one filebucket path"
raise ArgumentError, _("You can only have one filebucket path")
end

if value.is_a? String and not Puppet::Util.absolute_path?(value)
raise ArgumentError, "Filebucket paths must be absolute"
raise ArgumentError, _("Filebucket paths must be absolute")
end

true
Expand Down Expand Up @@ -111,7 +111,7 @@ def mkbucket
begin
@bucket = Puppet::FileBucket::Dipper.new(args)
rescue => detail
message = "Could not create #{type} filebucket: #{detail}"
message = _("Could not create %{type} filebucket: %{detail}") % { type: type, detail: detail }
self.log_exception(detail, message)
self.fail(message)
end
Expand Down
4 changes: 2 additions & 2 deletions lib/puppet/type/group.rb
Expand Up @@ -66,7 +66,7 @@ def sync
if gid =~ /^[-0-9]+$/
gid = Integer(gid)
else
self.fail "Invalid GID #{gid}"
self.fail _("Invalid GID %{gid}") % { gid: gid }
end
when Symbol
unless gid == :absent
Expand Down Expand Up @@ -157,7 +157,7 @@ def delimiter
end

validate do |value|
raise ArgumentError, "Attributes value pairs must be separated by an =" unless value.include?("=")
raise ArgumentError, _("Attributes value pairs must be separated by an =") unless value.include?("=")
end
end

Expand Down