class Chef::Resource::Locale

Constants

LC_VARIABLES
LOCALE_CONF
LOCALE_PLATFORM_FAMILIES
LOCALE_REGEX

Public Instance Methods

define_resource_requirements() click to toggle source

Avoid running this resource on platforms that don't use /etc/locale.conf

# File lib/chef/resource/locale.rb, line 82
def define_resource_requirements
  requirements.assert(:all_actions) do |a|
    a.assertion { LOCALE_PLATFORM_FAMILIES.include?(node[:platform_family]) }
    a.failure_message(Chef::Exceptions::ProviderNotFound, "The locale resource is not supported on platform family: #{node[:platform_family]}")
  end

  requirements.assert(:all_actions) do |a|
    # RHEL/CentOS type platforms don't have locale-gen
    a.assertion { shell_out("locale-gen") }
    a.failure_message(Chef::Exceptions::ProviderNotFound, "The locale resource requires the locale-gen tool")
  end
end
generate_locales() click to toggle source

Generates the localisation files from templates using locale-gen. @see manpages.ubuntu.com/manpages/cosmic/man8/locale-gen.8.html @raise [Mixlib::ShellOut::ShellCommandFailed] not a supported language or locale

# File lib/chef/resource/locale.rb, line 99
def generate_locales
  shell_out!("locale-gen #{unavailable_locales.join(' ')}")
end
lc_all(arg = nil) click to toggle source

@deprecated Use {#lc_env} instead of this property.

{#lc_env} uses Hash with specific LC var as key.

@raise [Chef::Deprecated]

# File lib/chef/resource/locale.rb, line 61
def lc_all(arg = nil)
  unless arg.nil?
    Chef.deprecated(:locale_lc_all, "Changing LC_ALL can break #{Chef::Dist::PRODUCT}'s parsing of command output in unexpected ways.\n Use one of the more specific LC_ properties as needed.")
  end
end
new_content() click to toggle source

@return [String] Contents that are required to be

updated in /etc/locale.conf
# File lib/chef/resource/locale.rb, line 130
def new_content
  @new_content ||= begin
    content = {}
    content = new_resource.lc_env.dup if new_resource.lc_env
    content["LANG"] = new_resource.lang if new_resource.lang
    content.sort.map { |t| t.join("=") }.join("\n") + "\n"
  end
end
unavailable_locales() click to toggle source

@return [Array<String>] Locales that user wants to set but are not available on

the system. They are required to be generated.
# File lib/chef/resource/locale.rb, line 119
def unavailable_locales
  @unavailable_locales ||= begin
    available = shell_out!("locale -a").stdout.split("\n")
    required = [new_resource.lang, new_resource.lc_env.values].flatten.compact.uniq
    required - available
  end
end
up_to_date?() click to toggle source

@return [Boolean] Whether any modification is required in /etc/locale.conf

# File lib/chef/resource/locale.rb, line 141
def up_to_date?
  old_content = ::File.read(LOCALE_CONF)
  new_content == old_content
rescue
  false # We need to create the file if it is not present
end
update_locale() click to toggle source

Updates system locale by appropriately writing them in /etc/locale.conf @note This locale change won't affect the current run. At this time it is an exercise left to the user to restart or reboot if the locale change is required at later part of the client run. @see wiki.archlinux.org/index.php/locale#Setting_the_system_locale

# File lib/chef/resource/locale.rb, line 109
def update_locale
  file "Updating system locale" do
    path LOCALE_CONF
    content new_content
  end
end