puppet 5.3.1 → 5.3.2

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of puppet might be problematic. Click here for more details.

@@ -126,6 +126,19 @@ module Puppet
126
126
  munge(value)
127
127
  value.to_sym
128
128
  end
129
+ },
130
+ :disable_i18n => {
131
+ :default => false,
132
+ :type => :boolean,
133
+ :desc => "If true, turns off all translations of Puppet and module
134
+ log messages, which affects error, warning, and info log messages,
135
+ as well as any translations in the report and CLI.",
136
+ :hook => proc do |value|
137
+ if value
138
+ require 'puppet/gettext/stubs'
139
+ Puppet::GettextConfig.disable_gettext
140
+ end
141
+ end
129
142
  }
130
143
  )
131
144
 
@@ -1,18 +1,36 @@
1
1
  require 'puppet/util/platform'
2
+ require 'puppet/file_system'
2
3
 
3
4
  module Puppet::GettextConfig
4
5
  LOCAL_PATH = File.absolute_path('../../../locales', File.dirname(__FILE__))
5
6
  POSIX_PATH = File.absolute_path('../../../../../share/locale', File.dirname(__FILE__))
6
7
  WINDOWS_PATH = File.absolute_path('../../../../../../../puppet/share/locale', File.dirname(__FILE__))
7
8
 
9
+ # Load gettext helpers and track whether they're available.
10
+ # Used instead of features because we initialize gettext before features is available.
11
+ # Stubbing gettext if unavailable is handled in puppet.rb.
12
+ begin
13
+ require 'gettext-setup'
14
+ require 'locale'
15
+ @gettext_loaded = true
16
+ rescue LoadError
17
+ @gettext_loaded = false
18
+ end
19
+
20
+ # Whether we were able to require gettext-setup and locale
21
+ # @return [Boolean] true if gettext-setup was successfully loaded
22
+ def self.gettext_loaded?
23
+ @gettext_loaded
24
+ end
25
+
8
26
  # Search for puppet gettext config files
9
27
  # @return [String] path to the config, or nil if not found
10
28
  def self.puppet_locale_path
11
- if File.exist?(LOCAL_PATH)
29
+ if Puppet::FileSystem.exist?(LOCAL_PATH)
12
30
  return LOCAL_PATH
13
- elsif Puppet::Util::Platform.windows? && File.exist?(WINDOWS_PATH)
31
+ elsif Puppet::Util::Platform.windows? && Puppet::FileSystem.exist?(WINDOWS_PATH)
14
32
  return WINDOWS_PATH
15
- elsif !Puppet::Util::Platform.windows? && File.exist?(POSIX_PATH)
33
+ elsif !Puppet::Util::Platform.windows? && Puppet::FileSystem.exist?(POSIX_PATH)
16
34
  return POSIX_PATH
17
35
  else
18
36
  nil
@@ -30,40 +48,43 @@ module Puppet::GettextConfig
30
48
  end
31
49
  end
32
50
 
51
+ # Prevent future gettext initializations
52
+ def self.disable_gettext
53
+ @gettext_disabled = true
54
+ end
55
+
33
56
  # Attempt to initialize the gettext-setup gem
34
57
  # @param path [String] to gettext config file
35
58
  # @param file_format [Symbol] translation file format to use, either :po or :mo
36
59
  # @return true if initialization succeeded, false otherwise
37
- def self.initialize(conf_file_location, file_format)
60
+ def self.initialize(conf_file_dir, file_format)
61
+ return false if @gettext_disabled || !@gettext_loaded
62
+
38
63
  unless file_format == :po || file_format == :mo
39
64
  raise Puppet::Error, "Unsupported translation file format #{file_format}; please use :po or :mo"
40
65
  end
41
66
 
42
- begin
43
- require 'gettext-setup'
44
- require 'locale'
67
+ return false if conf_file_dir.nil?
45
68
 
46
- if conf_file_location && File.exists?(conf_file_location)
47
- if GettextSetup.method(:initialize).parameters.count == 1
48
- # For use with old gettext-setup gem versions, will load PO files only
49
- GettextSetup.initialize(conf_file_location)
50
- else
51
- GettextSetup.initialize(conf_file_location, :file_format => file_format)
52
- end
53
- # Only change this once.
54
- # Because negotiate_locales will only return a non-default locale if
55
- # the system locale matches a translation set actually available for the
56
- # given gettext project, we don't want this to get set back to default if
57
- # we load a module that doesn't have translations, but Puppet does have
58
- # translations for the user's locale.
59
- if FastGettext.locale == GettextSetup.default_locale
60
- FastGettext.locale = GettextSetup.negotiate_locale(Locale.current.language)
61
- end
62
- true
69
+ conf_file = File.join(conf_file_dir, "config.yaml")
70
+ if Puppet::FileSystem.exist?(conf_file)
71
+ if GettextSetup.method(:initialize).parameters.count == 1
72
+ # For use with old gettext-setup gem versions, will load PO files only
73
+ GettextSetup.initialize(conf_file_dir)
63
74
  else
64
- false
75
+ GettextSetup.initialize(conf_file_dir, :file_format => file_format)
65
76
  end
66
- rescue LoadError
77
+ # Only change this once.
78
+ # Because negotiate_locales will only return a non-default locale if
79
+ # the system locale matches a translation set actually available for the
80
+ # given gettext project, we don't want this to get set back to default if
81
+ # we load a module that doesn't have translations, but Puppet does have
82
+ # translations for the user's locale.
83
+ if FastGettext.locale == GettextSetup.default_locale
84
+ FastGettext.locale = GettextSetup.negotiate_locale(Locale.current.language)
85
+ end
86
+ true
87
+ else
67
88
  false
68
89
  end
69
90
  end
@@ -98,7 +98,7 @@ class Puppet::Module
98
98
  @absolute_path_to_manifests = Puppet::FileSystem::PathPattern.absolute(manifests)
99
99
 
100
100
  # i18n initialization for modules
101
- initialize_i18n
101
+ initialize_i18n unless Puppet[:disable_i18n]
102
102
  end
103
103
 
104
104
  # @deprecated The puppetversion module metadata field is no longer used.
@@ -428,22 +428,24 @@ class Puppet::Module
428
428
 
429
429
  locales_path = File.absolute_path('locales', path)
430
430
 
431
- begin
432
- Puppet::GettextConfig.initialize(locales_path, :po)
431
+ if Puppet::GettextConfig.initialize(locales_path, :po)
433
432
  Puppet.debug "#{module_name} initialized for i18n: #{GettextSetup.translation_repositories[module_name]}"
434
- rescue
435
- config_path = File.absolute_path('config.yaml', locales_path)
436
- Puppet.debug "Could not find locales configuration file for #{module_name} at #{config_path}. Skipping i18n initialization."
433
+ else if Puppet::GettextConfig.gettext_loaded?
434
+ config_path = File.absolute_path('config.yaml', locales_path)
435
+ Puppet.debug "Could not find locales configuration file for #{module_name} at #{config_path}. Skipping i18n initialization."
436
+ else
437
+ Puppet.debug "No gettext library found, skipping i18n initialization."
438
+ end
437
439
  end
438
440
  end
439
441
 
440
442
  private
441
443
 
442
444
  def i18n_initialized?(module_name)
443
- begin
445
+ if Puppet::GettextConfig.gettext_loaded?
444
446
  GettextSetup.translation_repositories.has_key? module_name
445
- rescue NameError
446
- # GettextSetup not yet initialized
447
+ else
448
+ # GettextSetup not yet initialized or not found
447
449
  false
448
450
  end
449
451
  end
@@ -6,7 +6,7 @@
6
6
  # Raketasks and such to set the version based on the output of `git describe`
7
7
 
8
8
  module Puppet
9
- PUPPETVERSION = '5.3.1'
9
+ PUPPETVERSION = '5.3.2'
10
10
 
11
11
  ##
12
12
  # version is a public API method intended to always provide a fast and
@@ -225,7 +225,10 @@ describe Puppet::Module do
225
225
  mod_dir = "#{@modpath}/#{mod_name}"
226
226
  metadata_file = "#{mod_dir}/metadata.json"
227
227
  tasks_dir = "#{mod_dir}/tasks"
228
+ locale_config = "#{mod_dir}/locales/config.yaml"
228
229
  Puppet::FileSystem.stubs(:exist?).with(metadata_file).returns true
230
+ # Skip checking for translation config file
231
+ Puppet::FileSystem.stubs(:exist?).with(locale_config).returns false
229
232
  end
230
233
  mod = PuppetSpec::Modules.create(
231
234
  'test_gte_req',
@@ -448,19 +451,21 @@ describe Puppet::Module do
448
451
  let(:modpath) { tmpdir('modpath') }
449
452
  let(:modname) { 'puppetlabs-i18n'}
450
453
  let(:modroot) { "#{modpath}/#{modname}/" }
451
- let(:config_path) { "#{modroot}/locales/config.yaml" }
454
+ let(:locale_dir) { "#{modroot}locales" }
455
+ let(:config_path) { "#{locale_dir}/config.yaml" }
452
456
  let(:mod_obj) { PuppetSpec::Modules.create( modname, modpath, :metadata => { :dependencies => [] }, :env => env ) }
453
457
 
454
458
  it "is expected to initialize an un-initialized module" do
455
459
  expect(GettextSetup.translation_repositories.has_key? modname).to be false
456
460
 
457
- FileUtils.mkdir_p("#{mod_obj.path}/locales")
461
+ FileUtils.mkdir_p(locale_dir)
458
462
  config = {
459
463
  "gettext" => {
460
464
  "project_name" => modname
461
465
  }
462
466
  }
463
467
  File.open(config_path, 'w') { |file| file.write(config.to_yaml) }
468
+ Puppet::FileSystem.stubs(:exist?).with(config_path).returns(true)
464
469
 
465
470
  mod_obj.initialize_i18n
466
471
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: puppet
3
3
  version: !ruby/object:Gem::Version
4
- version: 5.3.1
4
+ version: 5.3.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2017-09-30 00:00:00.000000000 Z
12
+ date: 2017-10-04 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: facter