roku_builder 3.12.8 → 3.13.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.rubocop.yml +2 -2
- data/CHANGELOG +9 -0
- data/Gemfile.lock +17 -11
- data/bin/roku +4 -8
- data/lib/roku_builder.rb +16 -24
- data/lib/roku_builder/config.rb +213 -0
- data/lib/roku_builder/config_parser.rb +304 -267
- data/lib/roku_builder/config_validator.rb +149 -126
- data/lib/roku_builder/controller.rb +34 -184
- data/lib/roku_builder/controller_commands.rb +85 -79
- data/lib/roku_builder/error_handler.rb +0 -11
- data/lib/roku_builder/errors.rb +12 -0
- data/lib/roku_builder/inspector.rb +6 -4
- data/lib/roku_builder/keyer.rb +1 -1
- data/lib/roku_builder/loader.rb +1 -1
- data/lib/roku_builder/logger.rb +32 -0
- data/lib/roku_builder/manifest_manager.rb +2 -2
- data/lib/roku_builder/monitor.rb +1 -1
- data/lib/roku_builder/options.rb +113 -0
- data/lib/roku_builder/stager.rb +2 -2
- data/lib/roku_builder/tester.rb +57 -11
- data/lib/roku_builder/util.rb +3 -4
- data/lib/roku_builder/version.rb +1 -1
- data/roku_builder.gemspec +2 -1
- data/test/roku_builder/test_config.rb +168 -0
- data/test/roku_builder/test_config_parser.rb +347 -394
- data/test/roku_builder/test_config_validator.rb +193 -190
- data/test/roku_builder/test_controller.rb +59 -178
- data/test/roku_builder/test_controller_commands.rb +407 -394
- data/test/roku_builder/test_error_handler.rb +67 -69
- data/test/roku_builder/test_files/config_test/bad.json +2 -0
- data/test/roku_builder/test_files/config_test/child.json +11 -0
- data/test/roku_builder/test_files/config_test/config.json +29 -0
- data/test/roku_builder/test_files/config_test/non_json.json +1 -0
- data/test/roku_builder/test_files/config_test/parent.json +21 -0
- data/test/roku_builder/test_files/config_test/parent_projects.json +35 -0
- data/test/roku_builder/test_files/manifest_manager_test/manifest_template_2 +1 -1
- data/test/roku_builder/test_helper.rb +55 -45
- data/test/roku_builder/test_inspector.rb +278 -213
- data/test/roku_builder/test_keyer.rb +144 -147
- data/test/roku_builder/test_linker.rb +91 -95
- data/test/roku_builder/test_loader.rb +279 -289
- data/test/roku_builder/test_logger.rb +47 -0
- data/test/roku_builder/test_manifest_manager.rb +92 -94
- data/test/roku_builder/test_monitor.rb +101 -103
- data/test/roku_builder/test_navigator.rb +240 -245
- data/test/roku_builder/test_options.rb +156 -0
- data/test/roku_builder/test_packager.rb +108 -108
- data/test/roku_builder/test_profiler.rb +20 -19
- data/test/roku_builder/test_scripter.rb +83 -81
- data/test/roku_builder/test_stager.rb +299 -311
- data/test/roku_builder/test_tester.rb +112 -115
- data/test/roku_builder/test_util.rb +18 -17
- metadata +39 -6
- data/lib/roku_builder/config_manager.rb +0 -161
- data/test/roku_builder/test_config_manager.rb +0 -372
|
@@ -1,133 +1,130 @@
|
|
|
1
1
|
# ********** Copyright Viacom, Inc. Apache 2.0 **********
|
|
2
|
-
|
|
3
2
|
require_relative "test_helper.rb"
|
|
4
3
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
4
|
+
module RokuBuilder
|
|
5
|
+
class TesterTest < Minitest::Test
|
|
6
|
+
def test_tester_runtests
|
|
7
|
+
connection = Minitest::Mock.new
|
|
8
|
+
loader = Minitest::Mock.new
|
|
9
|
+
linker = Minitest::Mock.new
|
|
10
|
+
device_config = {
|
|
11
|
+
ip: "111.222.333",
|
|
12
|
+
user: "user",
|
|
13
|
+
password: "password",
|
|
14
|
+
init_params: {root_dir: "root/dir/path"}
|
|
15
|
+
}
|
|
16
|
+
loader_config = {
|
|
17
|
+
root_dir: "root/dir/path",
|
|
18
|
+
branch: "branch",
|
|
19
|
+
folders: ["source"],
|
|
20
|
+
files: ["manifest"]
|
|
21
|
+
}
|
|
22
|
+
tester = Tester.new(**device_config)
|
|
23
|
+
|
|
24
|
+
loader.expect(:sideload, [SUCCESS, ""], [loader_config])
|
|
25
|
+
linker.expect(:launch, nil, [{options: "RunTests:true"}])
|
|
26
|
+
connection.expect(:waitfor, nil, [/\*+\s*End testing\s*\*+/])
|
|
27
|
+
connection.expect(:puts, nil, ["cont\n"])
|
|
28
|
+
|
|
29
|
+
Loader.stub(:new, loader) do
|
|
30
|
+
Linker.stub(:new, linker) do
|
|
31
|
+
Net::Telnet.stub(:new, connection) do
|
|
32
|
+
tester.run_tests(sideload_config: loader_config)
|
|
33
|
+
end
|
|
34
|
+
end
|
|
30
35
|
end
|
|
31
|
-
end
|
|
32
36
|
|
|
33
|
-
|
|
34
|
-
|
|
37
|
+
connection.verify
|
|
38
|
+
end
|
|
35
39
|
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
assert_equal(
|
|
40
|
+
def test_tester_runtests_and_handle
|
|
41
|
+
waitfor = Proc.new do |end_reg, &blk|
|
|
42
|
+
assert_equal(/\*+\s*End testing\s*\*+/, end_reg)
|
|
39
43
|
txt = "Fake Text"
|
|
40
44
|
blk.call(txt) == false
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
45
|
+
end
|
|
46
|
+
connection = Minitest::Mock.new
|
|
47
|
+
loader = Minitest::Mock.new
|
|
48
|
+
linker = Minitest::Mock.new
|
|
49
|
+
device_config = {
|
|
50
|
+
ip: "111.222.333",
|
|
51
|
+
user: "user",
|
|
52
|
+
password: "password",
|
|
53
|
+
init_params: {root_dir: "root/dir/path"}
|
|
54
|
+
}
|
|
55
|
+
loader_config = {
|
|
56
|
+
root_dir: "root/dir/path",
|
|
57
|
+
branch: "branch",
|
|
58
|
+
folders: ["source"],
|
|
59
|
+
files: ["manifest"]
|
|
60
|
+
}
|
|
61
|
+
tester = Tester.new(**device_config)
|
|
62
|
+
|
|
63
|
+
loader.expect(:sideload, [SUCCESS, ""], [loader_config])
|
|
64
|
+
linker.expect(:launch, nil, [{options: "RunTests:true"}])
|
|
65
|
+
connection.expect(:waitfor, nil, &waitfor)
|
|
66
|
+
connection.expect(:puts, nil, ["cont\n"])
|
|
67
|
+
|
|
68
|
+
Loader.stub(:new, loader) do
|
|
69
|
+
Net::Telnet.stub(:new, connection) do
|
|
70
|
+
Linker.stub(:new, linker) do
|
|
71
|
+
tester.stub(:handle_text, false) do
|
|
72
|
+
tester.run_tests(sideload_config: loader_config)
|
|
73
|
+
end
|
|
74
|
+
end
|
|
66
75
|
end
|
|
67
76
|
end
|
|
68
|
-
end
|
|
69
|
-
|
|
70
|
-
connection.verify
|
|
71
|
-
end
|
|
72
|
-
|
|
73
|
-
def test_tester_handle_text_no_text
|
|
74
|
-
logger = Minitest::Mock.new
|
|
75
|
-
device_config = {
|
|
76
|
-
ip: "111.222.333",
|
|
77
|
-
user: "user",
|
|
78
|
-
password: "password",
|
|
79
|
-
logger: logger
|
|
80
|
-
}
|
|
81
|
-
tester = RokuBuilder::Tester.new(**device_config)
|
|
82
|
-
|
|
83
|
-
text = "this\nis\na\ntest\nparagraph"
|
|
84
77
|
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
logger.verify
|
|
88
|
-
end
|
|
89
|
-
|
|
90
|
-
def test_tester_handle_text_all_text
|
|
91
|
-
logger = Minitest::Mock.new
|
|
92
|
-
device_config = {
|
|
93
|
-
ip: "111.222.333",
|
|
94
|
-
user: "user",
|
|
95
|
-
password: "password",
|
|
96
|
-
logger: logger
|
|
97
|
-
}
|
|
98
|
-
tester = RokuBuilder::Tester.new(**device_config)
|
|
99
|
-
|
|
100
|
-
text = "this\nis\na\ntest\nparagraph"
|
|
101
|
-
|
|
102
|
-
logger.expect(:unknown, nil, ["this"])
|
|
103
|
-
logger.expect(:unknown, nil, ["is"])
|
|
104
|
-
logger.expect(:unknown, nil, ["a"])
|
|
105
|
-
logger.expect(:unknown, nil, ["test"])
|
|
106
|
-
logger.expect(:unknown, nil, ["paragraph"])
|
|
107
|
-
|
|
108
|
-
assert tester.send(:handle_text, {txt: text, in_tests: true})
|
|
109
|
-
|
|
110
|
-
logger.verify
|
|
111
|
-
end
|
|
78
|
+
connection.verify
|
|
79
|
+
end
|
|
112
80
|
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
tester = RokuBuilder::Tester.new(**device_config)
|
|
81
|
+
def test_tester_handle_text_no_text
|
|
82
|
+
device_config = {
|
|
83
|
+
ip: "111.222.333",
|
|
84
|
+
user: "user",
|
|
85
|
+
password: "password",
|
|
86
|
+
init_params: {root_dir: "root/dir/path"}
|
|
87
|
+
}
|
|
88
|
+
tester = Tester.new(**device_config)
|
|
122
89
|
|
|
123
|
-
|
|
90
|
+
text = "this\nis\na\ntest\nparagraph"
|
|
91
|
+
tester.send(:handle_text, {txt: text})
|
|
124
92
|
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
logger.expect(:unknown, nil, ["test"])
|
|
93
|
+
refute tester.instance_variable_get(:@in_tests)
|
|
94
|
+
end
|
|
128
95
|
|
|
129
|
-
|
|
96
|
+
def test_tester_handle_text_all_text
|
|
97
|
+
device_config = {
|
|
98
|
+
ip: "111.222.333",
|
|
99
|
+
user: "user",
|
|
100
|
+
password: "password",
|
|
101
|
+
init_params: {root_dir: "root/dir/path"}
|
|
102
|
+
}
|
|
103
|
+
tester = Tester.new(**device_config)
|
|
104
|
+
tester.instance_variable_set(:@in_tests, true)
|
|
105
|
+
|
|
106
|
+
text = ["this","is","a","test","paragraph"]
|
|
107
|
+
|
|
108
|
+
tester.send(:handle_text, {txt: text.join("\n")})
|
|
109
|
+
assert_equal text, tester.instance_variable_get(:@logs)
|
|
110
|
+
assert tester.instance_variable_get(:@in_tests)
|
|
111
|
+
end
|
|
130
112
|
|
|
131
|
-
|
|
113
|
+
def test_tester_handle_text_partial_text
|
|
114
|
+
device_config = {
|
|
115
|
+
ip: "111.222.333",
|
|
116
|
+
user: "user",
|
|
117
|
+
password: "password",
|
|
118
|
+
init_params: {root_dir: "root/dir/path"}
|
|
119
|
+
}
|
|
120
|
+
tester = Tester.new(**device_config)
|
|
121
|
+
|
|
122
|
+
text = ["this","*Start testing*","is","a","test","*End testing*","paragraph"]
|
|
123
|
+
verify_text = ["***************","***************","*Start testing*","is","a","test","*End testing*","*************","*************"]
|
|
124
|
+
|
|
125
|
+
tester.send(:handle_text, {txt: text.join("\n")})
|
|
126
|
+
refute tester.instance_variable_get(:@in_tests)
|
|
127
|
+
assert_equal verify_text, tester.instance_variable_get(:@logs)
|
|
128
|
+
end
|
|
132
129
|
end
|
|
133
130
|
end
|
|
@@ -2,24 +2,25 @@
|
|
|
2
2
|
|
|
3
3
|
require_relative "test_helper.rb"
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
5
|
+
module RokuBuilder
|
|
6
|
+
class UtilTest < Minitest::Test
|
|
7
|
+
def test_util_init
|
|
8
|
+
device_config = {
|
|
9
|
+
ip: "111.222.333",
|
|
10
|
+
user: "user",
|
|
11
|
+
password: "password"
|
|
12
|
+
}
|
|
13
|
+
test = TestClass.new(**device_config)
|
|
14
|
+
assert test.inited
|
|
15
|
+
end
|
|
15
16
|
end
|
|
16
|
-
end
|
|
17
17
|
|
|
18
|
-
class TestClass <
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
18
|
+
class TestClass < Util
|
|
19
|
+
def init
|
|
20
|
+
@inited = true
|
|
21
|
+
end
|
|
22
|
+
def inited
|
|
23
|
+
@inited || false
|
|
24
|
+
end
|
|
24
25
|
end
|
|
25
26
|
end
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: roku_builder
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 3.
|
|
4
|
+
version: 3.13.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- greeneca
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2017-
|
|
11
|
+
date: 2017-05-17 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: rubyzip
|
|
@@ -108,6 +108,20 @@ dependencies:
|
|
|
108
108
|
- - "~>"
|
|
109
109
|
- !ruby/object:Gem::Version
|
|
110
110
|
version: '1.7'
|
|
111
|
+
- !ruby/object:Gem::Dependency
|
|
112
|
+
name: win32-security
|
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
|
114
|
+
requirements:
|
|
115
|
+
- - "~>"
|
|
116
|
+
- !ruby/object:Gem::Version
|
|
117
|
+
version: '0.5'
|
|
118
|
+
type: :runtime
|
|
119
|
+
prerelease: false
|
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
121
|
+
requirements:
|
|
122
|
+
- - "~>"
|
|
123
|
+
- !ruby/object:Gem::Version
|
|
124
|
+
version: '0.5'
|
|
111
125
|
- !ruby/object:Gem::Dependency
|
|
112
126
|
name: bundler
|
|
113
127
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -297,19 +311,22 @@ files:
|
|
|
297
311
|
- config.json.example
|
|
298
312
|
- config.json.min
|
|
299
313
|
- lib/roku_builder.rb
|
|
300
|
-
- lib/roku_builder/
|
|
314
|
+
- lib/roku_builder/config.rb
|
|
301
315
|
- lib/roku_builder/config_parser.rb
|
|
302
316
|
- lib/roku_builder/config_validator.rb
|
|
303
317
|
- lib/roku_builder/controller.rb
|
|
304
318
|
- lib/roku_builder/controller_commands.rb
|
|
305
319
|
- lib/roku_builder/error_handler.rb
|
|
320
|
+
- lib/roku_builder/errors.rb
|
|
306
321
|
- lib/roku_builder/inspector.rb
|
|
307
322
|
- lib/roku_builder/keyer.rb
|
|
308
323
|
- lib/roku_builder/linker.rb
|
|
309
324
|
- lib/roku_builder/loader.rb
|
|
325
|
+
- lib/roku_builder/logger.rb
|
|
310
326
|
- lib/roku_builder/manifest_manager.rb
|
|
311
327
|
- lib/roku_builder/monitor.rb
|
|
312
328
|
- lib/roku_builder/navigator.rb
|
|
329
|
+
- lib/roku_builder/options.rb
|
|
313
330
|
- lib/roku_builder/packager.rb
|
|
314
331
|
- lib/roku_builder/profiler.rb
|
|
315
332
|
- lib/roku_builder/scripter.rb
|
|
@@ -319,12 +336,18 @@ files:
|
|
|
319
336
|
- lib/roku_builder/version.rb
|
|
320
337
|
- rakefile
|
|
321
338
|
- roku_builder.gemspec
|
|
322
|
-
- test/roku_builder/
|
|
339
|
+
- test/roku_builder/test_config.rb
|
|
323
340
|
- test/roku_builder/test_config_parser.rb
|
|
324
341
|
- test/roku_builder/test_config_validator.rb
|
|
325
342
|
- test/roku_builder/test_controller.rb
|
|
326
343
|
- test/roku_builder/test_controller_commands.rb
|
|
327
344
|
- test/roku_builder/test_error_handler.rb
|
|
345
|
+
- test/roku_builder/test_files/config_test/bad.json
|
|
346
|
+
- test/roku_builder/test_files/config_test/child.json
|
|
347
|
+
- test/roku_builder/test_files/config_test/config.json
|
|
348
|
+
- test/roku_builder/test_files/config_test/non_json.json
|
|
349
|
+
- test/roku_builder/test_files/config_test/parent.json
|
|
350
|
+
- test/roku_builder/test_files/config_test/parent_projects.json
|
|
328
351
|
- test/roku_builder/test_files/controller_config_test/valid_config.json
|
|
329
352
|
- test/roku_builder/test_files/controller_test/load_config_test.json
|
|
330
353
|
- test/roku_builder/test_files/controller_test/parent_config.json
|
|
@@ -347,9 +370,11 @@ files:
|
|
|
347
370
|
- test/roku_builder/test_keyer.rb
|
|
348
371
|
- test/roku_builder/test_linker.rb
|
|
349
372
|
- test/roku_builder/test_loader.rb
|
|
373
|
+
- test/roku_builder/test_logger.rb
|
|
350
374
|
- test/roku_builder/test_manifest_manager.rb
|
|
351
375
|
- test/roku_builder/test_monitor.rb
|
|
352
376
|
- test/roku_builder/test_navigator.rb
|
|
377
|
+
- test/roku_builder/test_options.rb
|
|
353
378
|
- test/roku_builder/test_packager.rb
|
|
354
379
|
- test/roku_builder/test_profiler.rb
|
|
355
380
|
- test/roku_builder/test_ruby_git.rb
|
|
@@ -359,7 +384,7 @@ files:
|
|
|
359
384
|
- test/roku_builder/test_util.rb
|
|
360
385
|
homepage: ''
|
|
361
386
|
licenses:
|
|
362
|
-
-
|
|
387
|
+
- Apache-2.0
|
|
363
388
|
metadata: {}
|
|
364
389
|
post_install_message:
|
|
365
390
|
rdoc_options: []
|
|
@@ -382,12 +407,18 @@ signing_key:
|
|
|
382
407
|
specification_version: 4
|
|
383
408
|
summary: Build Tool for Roku Apps
|
|
384
409
|
test_files:
|
|
385
|
-
- test/roku_builder/
|
|
410
|
+
- test/roku_builder/test_config.rb
|
|
386
411
|
- test/roku_builder/test_config_parser.rb
|
|
387
412
|
- test/roku_builder/test_config_validator.rb
|
|
388
413
|
- test/roku_builder/test_controller.rb
|
|
389
414
|
- test/roku_builder/test_controller_commands.rb
|
|
390
415
|
- test/roku_builder/test_error_handler.rb
|
|
416
|
+
- test/roku_builder/test_files/config_test/bad.json
|
|
417
|
+
- test/roku_builder/test_files/config_test/child.json
|
|
418
|
+
- test/roku_builder/test_files/config_test/config.json
|
|
419
|
+
- test/roku_builder/test_files/config_test/non_json.json
|
|
420
|
+
- test/roku_builder/test_files/config_test/parent.json
|
|
421
|
+
- test/roku_builder/test_files/config_test/parent_projects.json
|
|
391
422
|
- test/roku_builder/test_files/controller_config_test/valid_config.json
|
|
392
423
|
- test/roku_builder/test_files/controller_test/load_config_test.json
|
|
393
424
|
- test/roku_builder/test_files/controller_test/parent_config.json
|
|
@@ -410,9 +441,11 @@ test_files:
|
|
|
410
441
|
- test/roku_builder/test_keyer.rb
|
|
411
442
|
- test/roku_builder/test_linker.rb
|
|
412
443
|
- test/roku_builder/test_loader.rb
|
|
444
|
+
- test/roku_builder/test_logger.rb
|
|
413
445
|
- test/roku_builder/test_manifest_manager.rb
|
|
414
446
|
- test/roku_builder/test_monitor.rb
|
|
415
447
|
- test/roku_builder/test_navigator.rb
|
|
448
|
+
- test/roku_builder/test_options.rb
|
|
416
449
|
- test/roku_builder/test_packager.rb
|
|
417
450
|
- test/roku_builder/test_profiler.rb
|
|
418
451
|
- test/roku_builder/test_ruby_git.rb
|
|
@@ -1,161 +0,0 @@
|
|
|
1
|
-
# ********** Copyright Viacom, Inc. Apache 2.0 **********
|
|
2
|
-
|
|
3
|
-
module RokuBuilder
|
|
4
|
-
|
|
5
|
-
# Load and validate config files.
|
|
6
|
-
class ConfigManager
|
|
7
|
-
|
|
8
|
-
# Load config file and generate intermeidate configs
|
|
9
|
-
# @param options [Hash] The options hash
|
|
10
|
-
# @param logger [Logger] system logger
|
|
11
|
-
# @return [Integer] Return code
|
|
12
|
-
# @return [Hash] Loaded config
|
|
13
|
-
# @return [Hash] Intermeidate configs
|
|
14
|
-
def self.load_config(options:, logger:)
|
|
15
|
-
config_file = File.expand_path(options[:config])
|
|
16
|
-
return MISSING_CONFIG unless File.exist?(config_file)
|
|
17
|
-
code = SUCCESS
|
|
18
|
-
config = ConfigManager.get_config(config: config_file, logger: logger)
|
|
19
|
-
return INVALID_CONFIG unless config
|
|
20
|
-
codes = ConfigValidator.validate_config(config: config)
|
|
21
|
-
fatal = false
|
|
22
|
-
warning = false
|
|
23
|
-
codes.each {|a_code|
|
|
24
|
-
if a_code > 0
|
|
25
|
-
logger.fatal "Invalid Config: "+ ConfigValidator.error_codes()[a_code]
|
|
26
|
-
fatal = true
|
|
27
|
-
elsif a_code < 0
|
|
28
|
-
logger.warn "Depricated Config: "+ ConfigValidator.error_codes()[a_code]
|
|
29
|
-
warning = true
|
|
30
|
-
elsif a_code == 0 and options[:validate]
|
|
31
|
-
logger.info "Config Valid"
|
|
32
|
-
end
|
|
33
|
-
}
|
|
34
|
-
return [INVALID_CONFIG, nil, nil] if fatal
|
|
35
|
-
code = DEPRICATED_CONFIG if warning
|
|
36
|
-
|
|
37
|
-
parse_code, configs = ConfigParser.parse_config(options: options, config: config, logger: logger)
|
|
38
|
-
unless parse_code == SUCCESS
|
|
39
|
-
return [parse_code, nil, nil]
|
|
40
|
-
end
|
|
41
|
-
[code, config, configs]
|
|
42
|
-
end
|
|
43
|
-
|
|
44
|
-
# Loads the roku config from file
|
|
45
|
-
# @param config [String] path for the roku config
|
|
46
|
-
# @return [Hash] roku config object
|
|
47
|
-
def self.get_config(config:, logger:)
|
|
48
|
-
begin
|
|
49
|
-
config = build_config(config: config, logger: logger)
|
|
50
|
-
return nil unless config
|
|
51
|
-
config[:devices][:default] = config[:devices][:default].to_sym
|
|
52
|
-
if config[:projects]
|
|
53
|
-
config[:projects][:default] = config[:projects][:default].to_sym
|
|
54
|
-
config[:projects].each_pair do |key,value|
|
|
55
|
-
next if key == :default
|
|
56
|
-
next if key == :project_dir
|
|
57
|
-
if value[:stage_method]
|
|
58
|
-
value[:stage_method] = value[:stage_method].to_sym
|
|
59
|
-
end
|
|
60
|
-
end
|
|
61
|
-
config[:projects].each_pair do |key, value|
|
|
62
|
-
unless key == :default or key == :project_dir
|
|
63
|
-
if value[:parent] and config[:projects][value[:parent].to_sym]
|
|
64
|
-
new_value = config[:projects][value[:parent].to_sym]
|
|
65
|
-
new_value = new_value.deep_merge value
|
|
66
|
-
config[:projects][key] = new_value
|
|
67
|
-
end
|
|
68
|
-
end
|
|
69
|
-
end
|
|
70
|
-
end
|
|
71
|
-
config
|
|
72
|
-
rescue JSON::ParserError
|
|
73
|
-
logger.fatal "Config file is not valid JSON"
|
|
74
|
-
nil
|
|
75
|
-
end
|
|
76
|
-
end
|
|
77
|
-
|
|
78
|
-
def self.build_config(config:, logger:)
|
|
79
|
-
config = {parent_config: config}
|
|
80
|
-
depth = 1
|
|
81
|
-
while config[:parent_config]
|
|
82
|
-
config_parent = JSON.parse(File.open(config[:parent_config]).read, {symbolize_names: true})
|
|
83
|
-
config.delete(:parent_config)
|
|
84
|
-
config.merge!(config_parent) {|_key, v1, _v2| v1}
|
|
85
|
-
depth += 1
|
|
86
|
-
if depth > 10
|
|
87
|
-
logger.fatal "Parent configs too deep."
|
|
88
|
-
return nil
|
|
89
|
-
end
|
|
90
|
-
end
|
|
91
|
-
config
|
|
92
|
-
end
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
# Edit the roku config
|
|
96
|
-
# @param config [String] path for the roku config
|
|
97
|
-
# @param options [String] options to set in the config
|
|
98
|
-
# @param stage[String] which stage to use
|
|
99
|
-
# @return [Boolean] success
|
|
100
|
-
def self.edit_config(config:, options:, logger:)
|
|
101
|
-
config_object = get_config(config: config, logger: logger)
|
|
102
|
-
return false unless config_object
|
|
103
|
-
project = options[:project].to_sym if options[:project]
|
|
104
|
-
project = config_object[:projects][:default] unless options[:project]
|
|
105
|
-
device = options[:device].to_sym if options[:device]
|
|
106
|
-
device = config_object[:devices][:default] unless options[:device]
|
|
107
|
-
stage = options[:stage].to_sym if options[:stage]
|
|
108
|
-
stage ||= config_object[:projects][project][:stages].keys[0].to_sym
|
|
109
|
-
state = {
|
|
110
|
-
project: project,
|
|
111
|
-
device: device,
|
|
112
|
-
stage: stage
|
|
113
|
-
}
|
|
114
|
-
apply_options(config_object: config_object, options: options[:edit_params], state: state)
|
|
115
|
-
config_string = JSON.pretty_generate(config_object)
|
|
116
|
-
file = File.open(config, "w")
|
|
117
|
-
file.write(config_string)
|
|
118
|
-
file.close
|
|
119
|
-
return true
|
|
120
|
-
end
|
|
121
|
-
|
|
122
|
-
# Apply the changes in the options string to the config object
|
|
123
|
-
# @param config_object [Hash] The config loaded from file
|
|
124
|
-
# @param options [String] The string of options passed in by the user
|
|
125
|
-
# @param state [Hash] The state of the config the user is editing
|
|
126
|
-
def self.apply_options(config_object:, options:, state:)
|
|
127
|
-
changes = Util.options_parse(options: options)
|
|
128
|
-
changes.each {|key,value|
|
|
129
|
-
if [:ip, :user, :password].include?(key)
|
|
130
|
-
config_object[:devices][state[:device]][key] = value
|
|
131
|
-
elsif [:directory, :app_name].include?(key) #:folders, :files
|
|
132
|
-
config_object[:projects][state[:project]][key] = value
|
|
133
|
-
elsif [:branch].include?(key)
|
|
134
|
-
config_object[:projects][state[:project]][:stages][state[:stage]][key] = value
|
|
135
|
-
end
|
|
136
|
-
}
|
|
137
|
-
end
|
|
138
|
-
private_class_method :apply_options
|
|
139
|
-
|
|
140
|
-
# Update the intermeidate configs
|
|
141
|
-
# @param configs [Hash] Intermeidate configs hash
|
|
142
|
-
# @param options [Hash] Options hash
|
|
143
|
-
# @return [Hash] New intermeidate configs hash
|
|
144
|
-
def self.update_configs(configs:, options:)
|
|
145
|
-
if options[:build_version]
|
|
146
|
-
configs[:package_config][:app_name_version] = "#{configs[:project_config][:app_name]} - #{configs[:stage]} - #{options[:build_version]}" if configs[:package_config]
|
|
147
|
-
unless configs[:out][:file]
|
|
148
|
-
configs[:out][:file] = "#{configs[:project_config][:app_name]}_#{configs[:stage]}_#{options[:build_version]}"
|
|
149
|
-
end
|
|
150
|
-
pathname = File.join(configs[:out][:folder], configs[:out][:file])
|
|
151
|
-
configs[:package_config][:out_file] = pathname if configs[:package_config]
|
|
152
|
-
configs[:build_config][:out_file] = pathname if configs[:build_config]
|
|
153
|
-
if configs[:sideload_config] and options[:out]
|
|
154
|
-
configs[:sideload_config][:out_file] = pathname
|
|
155
|
-
end
|
|
156
|
-
configs[:inspect_config][:pkg] = configs[:package_config][:out_file] if configs[:inspect_config] and configs[:package_config]
|
|
157
|
-
end
|
|
158
|
-
return configs
|
|
159
|
-
end
|
|
160
|
-
end
|
|
161
|
-
end
|