beaker-i18n_helper 1.0.1 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 2a92eea0c2995ff9bfc05eb14dbd7a4fe8866cee
4
- data.tar.gz: 05c9e958e3b13ef6c201b8f47ecfe2d82957d7e8
3
+ metadata.gz: 8b6547b333dd953c1304275229cf57bf3c2107d7
4
+ data.tar.gz: 1ea4ff06d011413473f5bd517867238ed46d87a0
5
5
  SHA512:
6
- metadata.gz: 6f33cf0b421c770fe240de47b386ac41e1504f275ebeb29e5918bdcaf513a5419189983df95b46fac2de7eab0cfa7cdbff59ecd82c6001e3a40f699e4bec6f26
7
- data.tar.gz: d84552e8412a7a7982ae46a697ce298bff0f5c429bdff6b1f7d6f7706dae2917e15562a64539d08b4606b8e38d15e4e70cdfcabed0b48473407b270bba425bbf
6
+ metadata.gz: df767bbe65daf3f8132d7ab1c8843f6476bc09a410218df49db34916885cd758c41fae858d1106940e8a0f49cd9af7dac01523168983e259e7357294c0f8a255
7
+ data.tar.gz: a333af940775587c403166fcce537d2710751bcb58e8162174832b5cda384e41f9fc0c671bc94c524733d9023bd568743ca31890366a19679232a01513ecd426
data/.gitignore CHANGED
@@ -7,6 +7,8 @@
7
7
  /pkg/
8
8
  /spec/reports/
9
9
  /tmp/
10
+ /log/
11
+ *.gem
10
12
 
11
13
  # rspec failure tracking
12
14
  .rspec_status
@@ -3,6 +3,16 @@
3
3
  All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
4
4
  and this project adheres to [Semantic Versioning](http://semver.org).
5
5
 
6
+ ## [1.1.0]
7
+ ### Summary
8
+ This release contains a fix and a public API change.
9
+
10
+ #### Changed
11
+ - `install_language_pack_on` method is now called `install_language_on`
12
+
13
+ #### Fixed
14
+ - issue where language packs aren't available on Debian. Installs 'locales-all' instead.
15
+
6
16
  ## [1.0.1]
7
17
  ### Summary
8
18
  This release fixes the `change_locale_on` method and makes some README updates.
@@ -14,5 +24,6 @@ This release fixes the `change_locale_on` method and makes some README updates.
14
24
  ### Summary
15
25
  This is the first release of this gem.
16
26
 
27
+ [1.1.0]:https://github.com/puppetlabs/beaker-i18n_helper/compare/1.0.1...1.1.0
17
28
  [1.0.1]:https://github.com/puppetlabs/beaker-i18n_helper/compare/1.0.0...1.0.1
18
29
  [1.0.0]:https://github.com/puppetlabs/beaker-i18n_helper/tags/1.0.0
data/README.md CHANGED
@@ -25,7 +25,7 @@ c.before :suite do
25
25
  # Required for binding tests.
26
26
  if fact('osfamily') == 'Debian'
27
27
  #install language pack on debian systems
28
- install_language_pack_on(host, "ja_JP.utf-8")
28
+ install_language_on(host, "ja_JP.utf-8")
29
29
  end
30
30
  if fact('osfamily') == 'RedHat'
31
31
  if fact('operatingsystemmajrelease') =~ /7/ || fact('operatingsystem') =~ /Fedora/
@@ -42,21 +42,21 @@ end
42
42
 
43
43
  ## Reference
44
44
 
45
- #### install_language_pack_on(host, lang)
45
+ #### install_language_on(hosts, lang)
46
46
 
47
- Uses Beaker's `install_package` to install a language pack for the desired language. Takes the host and `lang`, a POSIX locale identifier ([lang]_[region].[charset])
47
+ Uses Beaker's `install_package` to install a language pack for the desired language. Takes a hosts array and `lang`, a POSIX locale identifier ([lang]_[region].[charset])
48
48
 
49
49
  ```ruby
50
- install_language_pack_on(host, 'ja_JP.utf-8')
50
+ install_language_on(hosts, 'ja_JP.utf-8')
51
51
  ```
52
52
  Usually only needed for Debian systems, RHEL installs all language packs by default.
53
53
 
54
- #### change_locale_on(host, lang)
54
+ #### change_locale_on(hosts, lang)
55
55
 
56
- Takes in a POSIX locale identifier, `lang`, and sets $LANG, $LANGUAGE, and on the target host to `#{lang}`.
56
+ Takes in a POSIX locale identifier, `lang`, and sets $LANG, $LANGUAGE, and on the target hosts to `#{lang}`.
57
57
 
58
58
  ```ruby
59
- change_locale_on(host, "de_DE.utf-8")
59
+ change_locale_on(hosts, "de_DE.utf-8")
60
60
  ```
61
61
 
62
62
  ## Limitations
@@ -1,16 +1,26 @@
1
1
  require 'beaker'
2
2
 
3
- # Setting up the module
3
+ # Beaker i18n Helper
4
4
  module Beaker::I18nHelper # rubocop:disable Style/ClassAndModuleChildren
5
5
  include Beaker::DSL
6
6
  include Beaker::DSL::Helpers::FacterHelpers
7
7
 
8
+ # Validates POSIX locale identifier format
9
+ #
10
+ # @param lang [String] the identifier as a string, e.g. 'ja_JP.utf8'
11
+ # @return [Boolean] true if it's a valid identifier
12
+ #
8
13
  def valid_lang_string?(lang)
9
14
  lang_regex = %r{^[a-zA-Z][a-zA-Z](\_|\-)[a-zA-Z][a-zA-Z](\..*)?$}
10
15
  raise "Please use correct format for lang: #{lang_regex}" unless lang.match lang_regex
11
16
  true
12
17
  end
13
18
 
19
+ # Parses a given POSIX locale identifier into parts for the other functions to consume
20
+ #
21
+ # @param lang [String] the identifier as a string, e.g. 'ja_JP.utf8'
22
+ # @return [Array] the identifier as an array of [{lang},{region},{charset}]
23
+ #
14
24
  def parse_lang(lang)
15
25
  lang = lang.split('.')[0] if lang =~ %r{\.\S}
16
26
 
@@ -23,20 +33,36 @@ module Beaker::I18nHelper # rubocop:disable Style/ClassAndModuleChildren
23
33
  lang
24
34
  end
25
35
 
26
- def install_language_pack_on(hsts, lang)
36
+ # Installs the language pack on each host for a given language (if necessary)
37
+ #
38
+ # @param hsts [Array] beaker hosts array
39
+ # @param lang [String] the POSIX locale identifier as a string, e.g. 'ja_JP.utf8'
40
+ # @return [nil]
41
+ #
42
+ def install_language_on(hsts, lang)
27
43
  valid_lang_string?(lang)
28
44
  lang = parse_lang(lang)
29
45
 
30
46
  Array(hsts).each do |host|
31
47
  begin
32
- install_package(host, 'systemd-services') unless shell('file /sbin/init').stdout =~ %r{systemd}
33
- install_package(host, "language-pack-#{lang[0]}")
48
+ case fact('operatingsystem')
49
+ when 'Debian'
50
+ install_locales_all_on(host)
51
+ when 'Ubuntu'
52
+ install_language_pack_on(host, lang)
53
+ end
34
54
  rescue RuntimeError
35
55
  raise "Unable to install language pack for #{lang[0]} on #{host}"
36
56
  end
37
57
  end
38
58
  end
39
59
 
60
+ # Changes the locale on each host to the given language
61
+ #
62
+ # @param hsts [Array] beaker hosts array
63
+ # @param lang [String] the POSIX locale identifier as a string, e.g. 'ja_JP.utf8'
64
+ # @return [nil]
65
+ #
40
66
  def change_locale_on(hsts, lang)
41
67
  valid_lang_string?(lang)
42
68
  Array(hsts).each do |host|
@@ -50,6 +76,28 @@ module Beaker::I18nHelper # rubocop:disable Style/ClassAndModuleChildren
50
76
  end
51
77
  end
52
78
  end
79
+
80
+ private
81
+
82
+ # Installs the 'locales-all' package on the target host unless it is already installed
83
+ #
84
+ # @param host [Beaker::Host] beaker host
85
+ # @return [nil]
86
+ #
87
+ def install_locales_all_on(host)
88
+ install_package(host, 'locales-all') unless check_for_package(host, 'locales-all')
89
+ end
90
+
91
+ # Installs the language pack on the target host for a given language (if necessary)
92
+ #
93
+ # @param host [Beaker::Host] beaker host
94
+ # @param lang [String] the POSIX locale identifier as a string, e.g. 'ja_JP.utf8'
95
+ # @return [nil]
96
+ #
97
+ def install_language_pack_on(host, lang)
98
+ install_package(host, "language-pack-#{lang[0]}")
99
+ install_package(host, 'systemd-services') unless shell('file /sbin/init').stdout =~ %r{systemd}
100
+ end
53
101
  end
54
102
 
55
103
  include Beaker::I18nHelper
@@ -1,5 +1,5 @@
1
1
  module Beaker
2
2
  module I18nHelper
3
- VERSION = '1.0.1'.freeze
3
+ VERSION = '1.1.0'.freeze
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: beaker-i18n_helper
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Eric Putnam
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-09-21 00:00:00.000000000 Z
11
+ date: 2017-09-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rubocop