pi_build_modifier 0.3.0.pre.alpha → 0.3.1.pre.alpha
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +24 -12
- data/.travis.yml +26 -4
- data/CODE_OF_CONDUCT.md +74 -0
- data/LICENSE +21 -0
- data/README.md +208 -2
- data/Rakefile +134 -6
- data/Vagrantfile +27 -0
- data/docs/concept.md +27 -0
- data/docs/incubation.md +38 -0
- data/pi_build_modifier/.gitignore +12 -0
- data/{.rspec → pi_build_modifier/.rspec} +0 -0
- data/{Gemfile → pi_build_modifier/Gemfile} +0 -0
- data/{LICENSE.txt → pi_build_modifier/LICENSE.txt} +1 -1
- data/pi_build_modifier/README.md +3 -0
- data/pi_build_modifier/Rakefile +13 -0
- data/{bin → pi_build_modifier/bin}/pi_build_modifier +1 -1
- data/{lib → pi_build_modifier/lib}/pi_build_modifier/boot-files/boot.rb +1 -1
- data/{lib → pi_build_modifier/lib}/pi_build_modifier/boot-files/templates/07-resize-init.diff.erb +0 -0
- data/{lib → pi_build_modifier/lib}/pi_build_modifier/config/logex.rb +1 -1
- data/{lib → pi_build_modifier/lib}/pi_build_modifier/locale/locale_debconf.rb +1 -1
- data/{lib → pi_build_modifier/lib}/pi_build_modifier/locale/templates/00-debconf.erb +1 -1
- data/{lib → pi_build_modifier/lib}/pi_build_modifier/modifier/erb_mapper.rb +1 -1
- data/{lib → pi_build_modifier/lib}/pi_build_modifier/modifier/mapper.rb +1 -1
- data/{lib → pi_build_modifier/lib}/pi_build_modifier/modifier/pi_modifier.rb +1 -1
- data/{lib → pi_build_modifier/lib}/pi_build_modifier/modifier_task.rb +10 -3
- data/{lib → pi_build_modifier/lib}/pi_build_modifier/net-tweaks/templates/wpa_supplicant.conf.erb +0 -0
- data/{lib → pi_build_modifier/lib}/pi_build_modifier/net-tweaks/wifi_network.rb +1 -1
- data/{lib → pi_build_modifier/lib}/pi_build_modifier/sys_tweaks/run_modifier.rb +1 -1
- data/{lib → pi_build_modifier/lib}/pi_build_modifier/sys_tweaks/ssh.rb +1 -1
- data/{lib → pi_build_modifier/lib}/pi_build_modifier/sys_tweaks/templates/ssh.sh.erb +0 -0
- data/{lib → pi_build_modifier/lib}/pi_build_modifier/system/system_type.rb +1 -1
- data/{lib → pi_build_modifier/lib}/pi_build_modifier/version.rb +2 -2
- data/{lib → pi_build_modifier/lib}/pi_build_modifier.rb +4 -1
- data/{pi_build_modifier.gemspec → pi_build_modifier/pi_build_modifier.gemspec} +7 -7
- data/pi_build_modifier/spec/fixtures/config.json +26 -0
- data/pi_build_modifier/spec/pi_build_modifier/boot/boot_spec.rb +103 -0
- data/pi_build_modifier/spec/pi_build_modifier/locale/locale_spec.rb +87 -0
- data/pi_build_modifier/spec/pi_build_modifier/modifier/mapper_spec.rb +105 -0
- data/pi_build_modifier/spec/pi_build_modifier/modifier/modifier_spec.rb +83 -0
- data/pi_build_modifier/spec/pi_build_modifier/modifier_task_spec.rb +63 -0
- data/pi_build_modifier/spec/pi_build_modifier/net-tweaks/wifi_network_spec.rb +91 -0
- data/pi_build_modifier/spec/pi_build_modifier/sys_tweaks/run_modifier_spec.rb +74 -0
- data/pi_build_modifier/spec/pi_build_modifier/sys_tweaks/ssh_spec.rb +73 -0
- data/pi_build_modifier/spec/pi_build_modifier/system/system_spec.rb +66 -0
- data/pi_build_modifier/spec/pi_build_modifier_spec.rb +73 -0
- data/pi_build_modifier/spec/spec_helper.rb +10 -0
- data/pi_customizer/.rspec +2 -0
- data/pi_customizer/Gemfile +3 -0
- data/pi_customizer/LICENSE +21 -0
- data/pi_customizer/README.md +3 -0
- data/pi_customizer/Rakefile +13 -0
- data/pi_customizer/Vagrantfile +16 -0
- data/pi_customizer/bin/pi_customizer +25 -0
- data/pi_customizer/envs/aws/outputs.tf +3 -0
- data/pi_customizer/envs/aws/pi-build-env.tf +160 -0
- data/pi_customizer/envs/aws/variables.tf +55 -0
- data/pi_customizer/envs/docker/Dockerfile +6 -0
- data/pi_customizer/envs/sh/build-pi-img.sh +28 -0
- data/pi_customizer/lib/pi_customizer/build/builder/build_executor.rb +149 -0
- data/pi_customizer/lib/pi_customizer/build/builder/builder.rb +59 -0
- data/pi_customizer/lib/pi_customizer/build/builder/prepare_start_execute_builder.rb +43 -0
- data/pi_customizer/lib/pi_customizer/build/builder/start_prepare_execute_builder.rb +43 -0
- data/pi_customizer/lib/pi_customizer/build/environment/aws/aws.rb +76 -0
- data/pi_customizer/lib/pi_customizer/build/environment/docker/docker.rb +94 -0
- data/pi_customizer/lib/pi_customizer/build/environment/environment.rb +73 -0
- data/pi_customizer/lib/pi_customizer/build/environment/environment_builder_factory.rb +81 -0
- data/pi_customizer/lib/pi_customizer/build/environment/vagrant/templates/Vagrantfile.erb +61 -0
- data/pi_customizer/lib/pi_customizer/build/environment/vagrant/vagrant.rb +77 -0
- data/pi_customizer/lib/pi_customizer/build/environment/vagrant/vagrant_file.rb +95 -0
- data/pi_customizer/lib/pi_customizer/build/workspace/local_workspace.rb +92 -0
- data/pi_customizer/lib/pi_customizer/build/workspace/remote_workspace.rb +79 -0
- data/pi_customizer/lib/pi_customizer/utils/logex.rb +25 -0
- data/pi_customizer/lib/pi_customizer/version.rb +27 -0
- data/pi_customizer/lib/pi_customizer/write/image_writer.rb +67 -0
- data/pi_customizer/lib/pi_customizer.rb +84 -0
- data/pi_customizer/pi_customizer.gemspec +30 -0
- data/pi_customizer/spec/fixtures/TestVagrantfile +61 -0
- data/pi_customizer/spec/fixtures/image.img +1 -0
- data/pi_customizer/spec/fixtures/image.zip +0 -0
- data/pi_customizer/spec/pi_customizer/builder/build_executor_spec.rb +64 -0
- data/pi_customizer/spec/pi_customizer/environment/aws_spec.rb +57 -0
- data/pi_customizer/spec/pi_customizer/environment/environment_builder_factory_spec.rb +48 -0
- data/pi_customizer/spec/pi_customizer/environment/environment_spec.rb +75 -0
- data/pi_customizer/spec/pi_customizer/environment/vagrant/vagrant_file_spec.rb +63 -0
- data/pi_customizer/spec/pi_customizer/environment/vagrant/vagrant_spec.rb +41 -0
- data/pi_customizer/spec/pi_customizer/version_spec.rb +29 -0
- data/pi_customizer/spec/pi_customizer/workspace/local_workspace_spec.rb +74 -0
- data/pi_customizer/spec/pi_customizer/workspace/remote_workspace_spec.rb +51 -0
- data/pi_customizer/spec/pi_customizer/write/image_writer_spec.rb +59 -0
- data/pi_customizer/spec/pi_customizer_spec.rb +93 -0
- data/pi_customizer/spec/spec_helper.rb +10 -0
- data/version.rb +21 -0
- metadata +106 -41
@@ -1,6 +1,6 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
|
3
|
-
# Copyright (c) 2017-
|
3
|
+
# Copyright (c) 2017-2019 Beate Ottenwälder
|
4
4
|
#
|
5
5
|
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
6
|
# of this software and associated documentation files (the "Software"), to deal
|
data/{lib → pi_build_modifier/lib}/pi_build_modifier/boot-files/templates/07-resize-init.diff.erb
RENAMED
File without changes
|
@@ -3,4 +3,4 @@
|
|
3
3
|
locales locales/locales_to_be_generated multiselect <%= @gen_locales.join(', ') %>
|
4
4
|
# Default locale for the system environment:
|
5
5
|
# Choices: None, C.UTF-8, en_GB.UTF-8
|
6
|
-
locales locales/default_environmentg_locale
|
6
|
+
locales locales/default_environmentg_locale select <%= @sys_locale %>
|
@@ -1,4 +1,4 @@
|
|
1
|
-
# Copyright (c) 2017-
|
1
|
+
# Copyright (c) 2017-2019 Beate Ottenwälder
|
2
2
|
#
|
3
3
|
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
4
4
|
# of this software and associated documentation files (the "Software"), to deal
|
@@ -39,15 +39,20 @@ module PiBuildModifier
|
|
39
39
|
|
40
40
|
attr_reader :pi_modifier
|
41
41
|
|
42
|
+
##
|
43
|
+
# Initialization and configuration of the mappers that are used to change in the pi-gen build sources
|
44
|
+
|
42
45
|
def initialize(config, workspace, pi_modifier = PiModifier.new)
|
43
46
|
@mappers = create_mappers
|
44
|
-
@mappers[:run_modifier].append(@mappers[:ssh]) #TODO: This connection has to be established somewhere else
|
45
47
|
@pi_modifier = pi_modifier
|
46
48
|
configure_pi_modifier(config, workspace)
|
47
49
|
end
|
48
50
|
|
51
|
+
##
|
52
|
+
# Defines all mappers
|
53
|
+
|
49
54
|
private def create_mappers
|
50
|
-
{
|
55
|
+
mappers = {
|
51
56
|
:wpa_supplicant => WPASupplicant.new,
|
52
57
|
:system => System.new,
|
53
58
|
:ssh => Ssh.new,
|
@@ -55,6 +60,8 @@ module PiBuildModifier
|
|
55
60
|
:locale => Locale.new,
|
56
61
|
:boot => Boot.new
|
57
62
|
}
|
63
|
+
mappers[:run_modifier].append(mappers[:ssh]) #TODO: This connection has to be established somewhere else
|
64
|
+
mappers
|
58
65
|
end
|
59
66
|
|
60
67
|
private def configure_pi_modifier(config, workspace)
|
data/{lib → pi_build_modifier/lib}/pi_build_modifier/net-tweaks/templates/wpa_supplicant.conf.erb
RENAMED
File without changes
|
File without changes
|
@@ -1,4 +1,4 @@
|
|
1
|
-
# Copyright (c) 2017-
|
1
|
+
# Copyright (c) 2017-2019 Beate Ottenwälder
|
2
2
|
#
|
3
3
|
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
4
4
|
# of this software and associated documentation files (the "Software"), to deal
|
@@ -19,5 +19,5 @@
|
|
19
19
|
# SOFTWARE.
|
20
20
|
|
21
21
|
module PiBuildModifier
|
22
|
-
VERSION = '0.3.
|
22
|
+
VERSION = '0.3.1.pre.alpha'
|
23
23
|
end
|
@@ -1,4 +1,4 @@
|
|
1
|
-
# Copyright (c) 2017-
|
1
|
+
# Copyright (c) 2017-2019 Beate Ottenwälder
|
2
2
|
#
|
3
3
|
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
4
4
|
# of this software and associated documentation files (the "Software"), to deal
|
@@ -32,6 +32,9 @@ module PiBuildModifier
|
|
32
32
|
|
33
33
|
class PiBuildModifier < Thor
|
34
34
|
|
35
|
+
##
|
36
|
+
# The modify command allows users to modify pi-gen sources in a given workspace based on a given configuration
|
37
|
+
|
35
38
|
desc 'modify CONFIG WORKSPACE', 'Modify the pi image sources at the specified WORKSPACE with the specified configuration file CONFIG.'
|
36
39
|
def modify(config, workspace)
|
37
40
|
$logger.debug "Modifying with a configuration read from '#{config}' in the workspace '#{workspace}'"
|
@@ -21,12 +21,12 @@ Gem::Specification.new do |spec|
|
|
21
21
|
spec.executables = spec.files.grep(%r{^bin/}) {|f| File.basename(f)}
|
22
22
|
spec.require_paths = ['lib']
|
23
23
|
|
24
|
-
spec.add_development_dependency 'bundler', '~>
|
25
|
-
spec.add_development_dependency 'rake', '~>
|
26
|
-
spec.add_development_dependency 'rspec', '~> 3.
|
27
|
-
spec.add_development_dependency 'simplecov', '~> 0'
|
28
|
-
spec.add_development_dependency 'rdoc', '~>
|
24
|
+
spec.add_development_dependency 'bundler', '~> 2.0'
|
25
|
+
spec.add_development_dependency 'rake', '~> 12.3'
|
26
|
+
spec.add_development_dependency 'rspec', '~> 3.8'
|
27
|
+
spec.add_development_dependency 'simplecov', '~> 0.16'
|
28
|
+
spec.add_development_dependency 'rdoc', '~> 6.1'
|
29
29
|
spec.add_runtime_dependency 'thor', '~> 0.20'
|
30
|
-
spec.add_runtime_dependency 'json', '~> 2.
|
31
|
-
spec.add_runtime_dependency 'openssl', '~> 2.
|
30
|
+
spec.add_runtime_dependency 'json', '~> 2.2'
|
31
|
+
spec.add_runtime_dependency 'openssl', '~> 2.1'
|
32
32
|
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
{
|
2
|
+
"system": {
|
3
|
+
"name" : "chiipi",
|
4
|
+
"type" : "lite"
|
5
|
+
},
|
6
|
+
"ssh" : {
|
7
|
+
"enabled" : true
|
8
|
+
},
|
9
|
+
"locale": {
|
10
|
+
"gen" : ["en_GB.UTF-8 UTF-8", "de_DE.UTF-8 UTF-8"],
|
11
|
+
"sys" : "en_GB.UTF-8"
|
12
|
+
},
|
13
|
+
"cgroups": {
|
14
|
+
"memory": true
|
15
|
+
},
|
16
|
+
"wifi": {
|
17
|
+
"networks": [
|
18
|
+
{
|
19
|
+
"ssid": "ssid_test",
|
20
|
+
"passphrase": "wpsk_test",
|
21
|
+
"wpa_passphrase": "wpsk_test"
|
22
|
+
}
|
23
|
+
],
|
24
|
+
"wpa_country": "DE"
|
25
|
+
}
|
26
|
+
}
|
@@ -0,0 +1,103 @@
|
|
1
|
+
# Copyright (c) 2017-2019 Beate Ottenwälder
|
2
|
+
#
|
3
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
4
|
+
# of this software and associated documentation files (the "Software"), to deal
|
5
|
+
# in the Software without restriction, including without limitation the rights
|
6
|
+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
7
|
+
# copies of the Software, and to permit persons to whom the Software is
|
8
|
+
# furnished to do so, subject to the following conditions:
|
9
|
+
#
|
10
|
+
# The above copyright notice and this permission notice shall be included in all
|
11
|
+
# copies or substantial portions of the Software.
|
12
|
+
#
|
13
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
14
|
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
15
|
+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
16
|
+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
17
|
+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
18
|
+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
19
|
+
# SOFTWARE.
|
20
|
+
|
21
|
+
require_relative '../../spec_helper'
|
22
|
+
require 'rspec'
|
23
|
+
require 'fileutils'
|
24
|
+
require 'pi_build_modifier/boot-files/boot'
|
25
|
+
require 'pi_build_modifier/modifier/erb_mapper'
|
26
|
+
require 'pi_build_modifier/modifier/pi_modifier'
|
27
|
+
|
28
|
+
RSpec.describe PiBuildModifier::Boot do
|
29
|
+
|
30
|
+
let(:empty_json_config) {'config_empty.json'}
|
31
|
+
let(:full_json_config) {'config_full.json'}
|
32
|
+
let(:disabled_json_config) {'config_disabled.json'}
|
33
|
+
let(:workspace) {File.dirname(__FILE__) + '/workspace_boot'}
|
34
|
+
|
35
|
+
before(:each) do
|
36
|
+
FileUtils.mkdir_p workspace
|
37
|
+
File.open(full_json_config, 'w') {|file| file.write('{ "cgroups": {
|
38
|
+
"memory" : true
|
39
|
+
}}')}
|
40
|
+
File.open(disabled_json_config, 'w') {|file| file.write('{ "cgroups": {
|
41
|
+
"memory" : false
|
42
|
+
}}')}
|
43
|
+
File.open(empty_json_config, 'w') {|file| file.write('{}')}
|
44
|
+
end
|
45
|
+
|
46
|
+
after(:each) do
|
47
|
+
FileUtils.rm(empty_json_config)
|
48
|
+
FileUtils.rm(full_json_config)
|
49
|
+
FileUtils.rm(disabled_json_config)
|
50
|
+
FileUtils.rm_rf workspace
|
51
|
+
end
|
52
|
+
|
53
|
+
it 'should create a cmdline.txt file with all cgroups enabled when they are specified in the resources.json' do
|
54
|
+
#Given
|
55
|
+
modifier = PiBuildModifier::PiModifier.new
|
56
|
+
boot = PiBuildModifier::Boot.new
|
57
|
+
mapper = PiBuildModifier::ERBMapper.new(boot, workspace)
|
58
|
+
|
59
|
+
#When
|
60
|
+
modifier.with_json_configuration(full_json_config)
|
61
|
+
modifier.with_mapper(mapper)
|
62
|
+
modifier.modify
|
63
|
+
|
64
|
+
#Then
|
65
|
+
expect(Pathname.new(workspace + '/' + boot.relative_output_path)).to be_file
|
66
|
+
expect(File.read(workspace + '/' + boot.relative_output_path)).to match(/ cgroup_memory=1 /)
|
67
|
+
end
|
68
|
+
|
69
|
+
it 'should create a cmdline.txt file without cgroups enabled when they are disabled in the resources.json' do
|
70
|
+
#Given
|
71
|
+
modifier = PiBuildModifier::PiModifier.new
|
72
|
+
boot = PiBuildModifier::Boot.new
|
73
|
+
mapper = PiBuildModifier::ERBMapper.new(boot, workspace)
|
74
|
+
|
75
|
+
#When
|
76
|
+
modifier.with_json_configuration(disabled_json_config)
|
77
|
+
modifier.with_mapper(mapper)
|
78
|
+
modifier.modify
|
79
|
+
|
80
|
+
#Then
|
81
|
+
expect(Pathname.new(workspace + '/' + boot.relative_output_path)).to be_file
|
82
|
+
expect(File.read(workspace + '/' + boot.relative_output_path)).to_not match(/ cgroup_memory=1 /)
|
83
|
+
|
84
|
+
end
|
85
|
+
|
86
|
+
it 'should create a cmdline.txt file without cgroups enabled when they are not specified' do
|
87
|
+
#Given
|
88
|
+
modifier = PiBuildModifier::PiModifier.new
|
89
|
+
boot = PiBuildModifier::Boot.new
|
90
|
+
mapper = PiBuildModifier::ERBMapper.new(boot, workspace)
|
91
|
+
|
92
|
+
#When
|
93
|
+
modifier.with_json_configuration(empty_json_config)
|
94
|
+
modifier.with_mapper(mapper)
|
95
|
+
modifier.modify
|
96
|
+
|
97
|
+
#Then
|
98
|
+
expect(Pathname.new(workspace + '/' + boot.relative_output_path)).to be_file
|
99
|
+
expect(File.read(workspace + '/' + boot.relative_output_path)).to_not match(/ cgroup_memory=1 /)
|
100
|
+
|
101
|
+
end
|
102
|
+
end
|
103
|
+
|
@@ -0,0 +1,87 @@
|
|
1
|
+
# Copyright (c) 2017-2019 Beate Ottenwälder
|
2
|
+
#
|
3
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
4
|
+
# of this software and associated documentation files (the "Software"), to deal
|
5
|
+
# in the Software without restriction, including without limitation the rights
|
6
|
+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
7
|
+
# copies of the Software, and to permit persons to whom the Software is
|
8
|
+
# furnished to do so, subject to the following conditions:
|
9
|
+
#
|
10
|
+
# The above copyright notice and this permission notice shall be included in all
|
11
|
+
# copies or substantial portions of the Software.
|
12
|
+
#
|
13
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
14
|
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
15
|
+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
16
|
+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
17
|
+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
18
|
+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
19
|
+
# SOFTWARE.
|
20
|
+
|
21
|
+
require_relative '../../spec_helper'
|
22
|
+
require 'rspec'
|
23
|
+
require 'fileutils'
|
24
|
+
require 'pi_build_modifier/locale/locale_debconf'
|
25
|
+
require 'pi_build_modifier/sys_tweaks/run_modifier'
|
26
|
+
require 'pi_build_modifier/modifier/erb_mapper'
|
27
|
+
require 'pi_build_modifier/modifier/pi_modifier'
|
28
|
+
|
29
|
+
|
30
|
+
RSpec.describe PiBuildModifier::Locale do
|
31
|
+
|
32
|
+
let(:empty_json_config) {'config_empty.json'}
|
33
|
+
let(:json_config) {'config_full.json'}
|
34
|
+
let(:workspace) {File.dirname(__FILE__) + '/workspace'}
|
35
|
+
|
36
|
+
before(:each) do
|
37
|
+
FileUtils.mkdir_p workspace
|
38
|
+
File.open(json_config, 'w') {|file| file.write('{ "locale": {
|
39
|
+
"gen" : ["aaa", "bbb"],
|
40
|
+
"sys" : "ccc"
|
41
|
+
}}')}
|
42
|
+
File.open(empty_json_config, 'w') {|file| file.write('{}')}
|
43
|
+
end
|
44
|
+
|
45
|
+
after(:each) do
|
46
|
+
FileUtils.rm(empty_json_config)
|
47
|
+
FileUtils.rm(json_config)
|
48
|
+
FileUtils.rm_rf workspace
|
49
|
+
end
|
50
|
+
|
51
|
+
# 'en_GB.UTF-8 UTF-8', 'de_DE.UTF-8 UTF-8'
|
52
|
+
|
53
|
+
it 'should create a debconf file' do
|
54
|
+
#Given
|
55
|
+
|
56
|
+
modifier = PiBuildModifier::PiModifier.new
|
57
|
+
locale = PiBuildModifier::Locale.new
|
58
|
+
mapper = PiBuildModifier::ERBMapper.new(locale, workspace)
|
59
|
+
|
60
|
+
#When
|
61
|
+
modifier.with_json_configuration(json_config)
|
62
|
+
modifier.with_mapper(mapper)
|
63
|
+
modifier.modify
|
64
|
+
|
65
|
+
#Then
|
66
|
+
expect(Pathname.new(workspace + '/' + locale.relative_output_path)).to be_file
|
67
|
+
expect(File.read(workspace + '/' + locale.relative_output_path)).to match(/aaa, bbb/)
|
68
|
+
expect(File.read(workspace + '/' + locale.relative_output_path)).to match(/ccc/)
|
69
|
+
end
|
70
|
+
|
71
|
+
it 'should create a default debconf file' do
|
72
|
+
#Given
|
73
|
+
modifier = PiBuildModifier::PiModifier.new
|
74
|
+
locale = PiBuildModifier::Locale.new
|
75
|
+
mapper = PiBuildModifier::ERBMapper.new(locale, workspace)
|
76
|
+
|
77
|
+
#When
|
78
|
+
modifier.with_json_configuration(empty_json_config)
|
79
|
+
modifier.with_mapper(mapper)
|
80
|
+
modifier.modify
|
81
|
+
|
82
|
+
#Then
|
83
|
+
expect(Pathname.new(workspace + '/' + locale.relative_output_path)).to be_file
|
84
|
+
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
@@ -0,0 +1,105 @@
|
|
1
|
+
# Copyright (c) 2017-2019 Beate Ottenwälder
|
2
|
+
#
|
3
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
4
|
+
# of this software and associated documentation files (the "Software"), to deal
|
5
|
+
# in the Software without restriction, including without limitation the rights
|
6
|
+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
7
|
+
# copies of the Software, and to permit persons to whom the Software is
|
8
|
+
# furnished to do so, subject to the following conditions:
|
9
|
+
#
|
10
|
+
# The above copyright notice and this permission notice shall be included in all
|
11
|
+
# copies or substantial portions of the Software.
|
12
|
+
#
|
13
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
14
|
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
15
|
+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
16
|
+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
17
|
+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
18
|
+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
19
|
+
# SOFTWARE.
|
20
|
+
|
21
|
+
require_relative '../../spec_helper'
|
22
|
+
require 'rspec'
|
23
|
+
require 'fileutils'
|
24
|
+
require 'json'
|
25
|
+
require 'pi_build_modifier/modifier/erb_mapper'
|
26
|
+
require 'pi_build_modifier/modifier/mapper'
|
27
|
+
|
28
|
+
module PiBuildModifier
|
29
|
+
|
30
|
+
RSpec.describe Mapper do
|
31
|
+
it 'should implement a method modify' do
|
32
|
+
expect(Mapper.new(nil)).to respond_to(:modify)
|
33
|
+
end
|
34
|
+
it 'should implement a method map' do
|
35
|
+
expect(Mapper.new(nil)).to respond_to(:map)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
RSpec.describe ERBMapper do
|
40
|
+
|
41
|
+
let(:test_text) {'Test Text'}
|
42
|
+
let(:json_path) {'test.json'}
|
43
|
+
let(:template_path) {'template.erb'}
|
44
|
+
let(:output_path) {File.dirname(__FILE__) + '/' + 'output.config'}
|
45
|
+
let(:output_file_name) {'output.config'}
|
46
|
+
|
47
|
+
@json_data = nil
|
48
|
+
|
49
|
+
before do
|
50
|
+
File.open(json_path, 'w') {|file| file.write('{"test":"%s"}' % [test_text])}
|
51
|
+
File.open(json_path, 'r+') {|f| @json_data = JSON.parse(f.read)}
|
52
|
+
File.open(template_path, 'w') {|file| file.write('<%= @test %>')}
|
53
|
+
end
|
54
|
+
|
55
|
+
after do
|
56
|
+
FileUtils.rm(json_path)
|
57
|
+
FileUtils.rm(template_path)
|
58
|
+
end
|
59
|
+
|
60
|
+
it 'should implement a Mapper' do
|
61
|
+
expect(ERBMapper.new(TestData.new(template_path, output_file_name), '')).to be_a Mapper
|
62
|
+
end
|
63
|
+
|
64
|
+
it 'should raise an error when created with invalid data (i.e., the mapped data is nil)' do
|
65
|
+
expect {ERBMapper.new(nil, '')}.to raise_error
|
66
|
+
end
|
67
|
+
|
68
|
+
it 'should map a json configuration and an erb template to a config file' do
|
69
|
+
|
70
|
+
#Given
|
71
|
+
mapper = ERBMapper.new(TestData.new(template_path, output_file_name), File.dirname(__FILE__))
|
72
|
+
|
73
|
+
#When
|
74
|
+
mapper.map(@json_data)
|
75
|
+
mapper.modify
|
76
|
+
|
77
|
+
#Then
|
78
|
+
expect(Pathname.new(output_path)).to be_file
|
79
|
+
expect(IO.binread(Pathname.new(output_path))).to eq test_text
|
80
|
+
|
81
|
+
#Clean up
|
82
|
+
FileUtils.rm(output_path)
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
class TestData
|
87
|
+
|
88
|
+
attr_accessor :test
|
89
|
+
attr_reader :template_path, :relative_output_path
|
90
|
+
|
91
|
+
def initialize(template_path, relative_output_path)
|
92
|
+
@template_path = template_path
|
93
|
+
@relative_output_path = relative_output_path
|
94
|
+
end
|
95
|
+
|
96
|
+
def map(data)
|
97
|
+
@test = data['test']
|
98
|
+
end
|
99
|
+
|
100
|
+
def get_binding
|
101
|
+
binding
|
102
|
+
end
|
103
|
+
end
|
104
|
+
|
105
|
+
end
|
@@ -0,0 +1,83 @@
|
|
1
|
+
# Copyright (c) 2017-2019 Beate Ottenwälder
|
2
|
+
#
|
3
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
4
|
+
# of this software and associated documentation files (the "Software"), to deal
|
5
|
+
# in the Software without restriction, including without limitation the rights
|
6
|
+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
7
|
+
# copies of the Software, and to permit persons to whom the Software is
|
8
|
+
# furnished to do so, subject to the following conditions:
|
9
|
+
#
|
10
|
+
# The above copyright notice and this permission notice shall be included in all
|
11
|
+
# copies or substantial portions of the Software.
|
12
|
+
#
|
13
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
14
|
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
15
|
+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
16
|
+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
17
|
+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
18
|
+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
19
|
+
# SOFTWARE.
|
20
|
+
|
21
|
+
require_relative '../../spec_helper'
|
22
|
+
require 'rspec'
|
23
|
+
require 'fileutils'
|
24
|
+
require 'pi_build_modifier/modifier/pi_modifier'
|
25
|
+
require 'pi_build_modifier/modifier/mapper'
|
26
|
+
|
27
|
+
|
28
|
+
module PiBuildModifier
|
29
|
+
RSpec.describe PiModifier do
|
30
|
+
|
31
|
+
let(:tmp_json_config) {'tmp_config.json'}
|
32
|
+
|
33
|
+
before do
|
34
|
+
File.open(tmp_json_config, 'w') {|file| file.write('{"a":1,"b":2}')}
|
35
|
+
end
|
36
|
+
|
37
|
+
after do
|
38
|
+
FileUtils.rm(tmp_json_config)
|
39
|
+
end
|
40
|
+
|
41
|
+
it 'only accepts mappers that are a class Mapper' do
|
42
|
+
#Given
|
43
|
+
pi_modifier = PiModifier.new
|
44
|
+
|
45
|
+
#When #Then
|
46
|
+
expect{ pi_modifier.with_mapper(nil) }.to raise_error
|
47
|
+
|
48
|
+
end
|
49
|
+
|
50
|
+
it 'performs a modification task on a mapper object with the specification given in a json configuration' do
|
51
|
+
|
52
|
+
#Given
|
53
|
+
pi_modifier = PiModifier.new
|
54
|
+
test_sum_component = TestSumComponent.new(nil)
|
55
|
+
|
56
|
+
#When
|
57
|
+
pi_modifier.with_json_configuration(tmp_json_config)
|
58
|
+
pi_modifier.with_mapper(test_sum_component)
|
59
|
+
pi_modifier.modify
|
60
|
+
|
61
|
+
#Then
|
62
|
+
expect(test_sum_component.a).to equal 1
|
63
|
+
expect(test_sum_component.b).to equal 2
|
64
|
+
expect(test_sum_component.sum).to equal 3
|
65
|
+
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
class TestSumComponent < Mapper
|
70
|
+
attr_accessor :a, :b, :sum
|
71
|
+
|
72
|
+
def map(json_data)
|
73
|
+
@a = json_data['a']
|
74
|
+
@b = json_data['b']
|
75
|
+
end
|
76
|
+
|
77
|
+
def modify
|
78
|
+
@sum = @a + @b
|
79
|
+
end
|
80
|
+
|
81
|
+
end
|
82
|
+
|
83
|
+
end
|
@@ -0,0 +1,63 @@
|
|
1
|
+
# Copyright (c) 2017-2019 Beate Ottenwälder
|
2
|
+
#
|
3
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
4
|
+
# of this software and associated documentation files (the "Software"), to deal
|
5
|
+
# in the Software without restriction, including without limitation the rights
|
6
|
+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
7
|
+
# copies of the Software, and to permit persons to whom the Software is
|
8
|
+
# furnished to do so, subject to the following conditions:
|
9
|
+
#
|
10
|
+
# The above copyright notice and this permission notice shall be included in all
|
11
|
+
# copies or substantial portions of the Software.
|
12
|
+
#
|
13
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
14
|
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
15
|
+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
16
|
+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
17
|
+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
18
|
+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
19
|
+
# SOFTWARE.
|
20
|
+
|
21
|
+
require_relative '../spec_helper'
|
22
|
+
require 'rspec'
|
23
|
+
require 'fileutils'
|
24
|
+
require 'pi_build_modifier/modifier/pi_modifier'
|
25
|
+
require 'pi_build_modifier/modifier_task'
|
26
|
+
|
27
|
+
|
28
|
+
module PiBuildModifier
|
29
|
+
RSpec.describe Task::Modifier do
|
30
|
+
|
31
|
+
let(:json_config) {File.dirname(__FILE__) + '/../fixtures/config.json'}
|
32
|
+
let(:workspace) {File.dirname(__FILE__) + '/' + 'tmp_workspace'}
|
33
|
+
|
34
|
+
before do
|
35
|
+
FileUtils::mkdir_p workspace
|
36
|
+
end
|
37
|
+
|
38
|
+
after do
|
39
|
+
FileUtils.rm_rf workspace
|
40
|
+
end
|
41
|
+
|
42
|
+
it 'registers all default mappers' do
|
43
|
+
#Given
|
44
|
+
pi_modifier = PiModifier.new
|
45
|
+
#When
|
46
|
+
Task::Modifier.new(json_config, workspace, pi_modifier)
|
47
|
+
#Then
|
48
|
+
expect(pi_modifier.mappers.size).to be >= 1
|
49
|
+
end
|
50
|
+
|
51
|
+
it 'when the modification task is executed, modifications are made to the workspace directory' do
|
52
|
+
#Given
|
53
|
+
pi_modifier_task = Task::Modifier.new(json_config, workspace)
|
54
|
+
|
55
|
+
#When
|
56
|
+
pi_modifier_task.execute
|
57
|
+
|
58
|
+
#Then
|
59
|
+
expect(Dir["#{workspace}/**/*"].length).to be > 0
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
end
|