rbatch 2.4.0 → 2.5.0
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +4 -0
- data/README.ja.md +5 -1
- data/README.md +5 -1
- data/bin/rbatch-init +1 -1
- data/lib/rbatch/config.rb +7 -3
- data/lib/rbatch/controller.rb +20 -4
- data/lib/rbatch/variables.rb +2 -0
- data/lib/rbatch/version.rb +1 -1
- data/sample/.rbatchrc +1 -1
- data/spec/rbatch/config_spec.rb +11 -0
- data/spec/rbatch/controller_spec.rb +78 -3
- data/spec/rbatch/variables_spec.rb +2 -0
- metadata +2 -2
data/CHANGELOG
CHANGED
@@ -9,6 +9,10 @@ If you want to know about bug fix, please see commit logs of https://github.com/
|
|
9
9
|
version 2
|
10
10
|
===================
|
11
11
|
|
12
|
+
2.5.0 (2015/06/14)
|
13
|
+
----
|
14
|
+
* [add] support erb format config.
|
15
|
+
|
12
16
|
2.4.0 (2015/06/08)
|
13
17
|
----
|
14
18
|
* [add] new option : "log_output_exit_status"
|
data/README.ja.md
CHANGED
@@ -151,9 +151,13 @@ RBatchは簡単にデフォルトの位置の設定ファイルを読み込め
|
|
151
151
|
p RBatch.config["not_exist"] # => RBatch::ConfigExceptionが発生
|
152
152
|
|
153
153
|
|
154
|
+
もし`erb`を使って`yaml`を記述したい場合は、設定ファイルの名前を`xxx.yaml`から`xxx.yaml.erb`に変えてください。RBatchはまず`erb`を評価した後`yaml`として読み込みます。`xxx.yaml`と`xxx.yaml.erb`の両方がある場合は`xxx.yaml`が読み込まれます。
|
155
|
+
|
154
156
|
#### 共通設定ファイル
|
155
157
|
|
156
158
|
すべてのスクリプトから共通で読み込む設定ファイルを作りたい場合は、`${RB_HOME}/conf/common.yaml`というファイルを作ることで可能です。
|
159
|
+
このファイル名を変えたい場合は`common_conf_name`オプションを利用してください。
|
160
|
+
通常の設定ファイルと同様に`erb`フォーマットも利用可能です。
|
157
161
|
|
158
162
|
### 外部コマンド実行
|
159
163
|
|
@@ -417,7 +421,7 @@ Run-Conf(`${RB_HOME}/.rbatchrc`)のサンプルは以下の通り
|
|
417
421
|
# exitステータスをログに出すかどうか
|
418
422
|
#
|
419
423
|
# デフォルトはtrue。
|
420
|
-
# ログブロック内で "
|
424
|
+
# ログブロック内で "exit" メソッドを使った時に、
|
421
425
|
# exitステータスをログファイルに出力する。
|
422
426
|
#
|
423
427
|
#log_output_exit_status : true
|
data/README.md
CHANGED
@@ -161,12 +161,15 @@ p RBatch.config["array"] # => ["item1", "item2", "item3"]
|
|
161
161
|
p RBatch.config["not_exist"] # => Raise RBatch::ConfigException
|
162
162
|
```
|
163
163
|
|
164
|
+
If you want to describe `yaml` by using `erb`, rename config file from `xxx.yaml` into `xxx.yaml.erb`. RBatch evaluates config file as `erb` after that read it as `yaml`. When both `xxx.yaml` and `xxx.yaml.erb` exist, `xxx.yaml` is read.
|
165
|
+
|
164
166
|
#### Common Config
|
165
167
|
|
166
168
|
By putting shard config file at `${RB_HOME}/conf/common.yaml`, the
|
167
169
|
values in the file are shared by all scripts.
|
168
170
|
If you want to change the name of the config file, you cau use the
|
169
171
|
`common_conf_name` option.
|
172
|
+
It accepts `erb` format like above normal config.
|
170
173
|
|
171
174
|
### External Command Wrapper
|
172
175
|
|
@@ -444,7 +447,7 @@ Sample of RBatch Run-Conf `${RB_HOME}/.rbatchrc`.
|
|
444
447
|
# Output Exit Status
|
445
448
|
#
|
446
449
|
# Default is true.
|
447
|
-
# When you use the "
|
450
|
+
# When you use the "exit" method in a log block,
|
448
451
|
# output exit status into the log file.
|
449
452
|
#
|
450
453
|
#log_output_exit_status : true
|
@@ -511,6 +514,7 @@ opt = {
|
|
511
514
|
:delete_old_log => false,
|
512
515
|
:delete_old_log_date => 7,
|
513
516
|
:bufferd => false,
|
517
|
+
:output_exit_status => true,
|
514
518
|
:send_mail => false,
|
515
519
|
:mail_to => nil,
|
516
520
|
:mail_from => "rbatch.localhost",
|
data/bin/rbatch-init
CHANGED
@@ -145,7 +145,7 @@ contents[".rbatchrc"] = <<EOF
|
|
145
145
|
# Output Exit Status
|
146
146
|
#
|
147
147
|
# Default is true.
|
148
|
-
# When you use the "
|
148
|
+
# When you use the "exit" method in a log block,
|
149
149
|
# output exit status into the log file.
|
150
150
|
#
|
151
151
|
#log_output_exit_status : true
|
data/lib/rbatch/config.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
require 'yaml'
|
2
2
|
require 'pathname'
|
3
|
-
|
3
|
+
require 'erb'
|
4
4
|
module RBatch
|
5
5
|
|
6
6
|
class Config
|
@@ -11,10 +11,14 @@ module RBatch
|
|
11
11
|
@hash
|
12
12
|
|
13
13
|
# @param [String] path Config file path
|
14
|
-
def initialize(path)
|
14
|
+
def initialize(path,is_erb = false)
|
15
15
|
@path = path
|
16
16
|
begin
|
17
|
-
|
17
|
+
if is_erb
|
18
|
+
@hash = ConfigElement.new(YAML::load(ERB.new(IO.read(@path)).result))
|
19
|
+
else
|
20
|
+
@hash = ConfigElement.new(YAML::load_file(@path))
|
21
|
+
end
|
18
22
|
rescue Errno::ENOENT => e
|
19
23
|
@hash = nil
|
20
24
|
end
|
data/lib/rbatch/controller.rb
CHANGED
@@ -22,10 +22,26 @@ module RBatch
|
|
22
22
|
@journal.put 1, "RB_HOME : \"#{@vars[:home_dir]}\""
|
23
23
|
@journal.put 1, "Load Run-Conf: \"#{@vars[:run_conf_path]}\""
|
24
24
|
@journal.put 2, "RBatch Variables : #{@vars.inspect}"
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
25
|
+
if File.exist?(@vars[:common_config_path])
|
26
|
+
@common_config = RBatch::Config.new(@vars[:common_config_path],false)
|
27
|
+
elsif File.exist?(@vars[:common_config_erb_path])
|
28
|
+
@common_config = RBatch::Config.new(@vars[:common_config_erb_path],true)
|
29
|
+
else
|
30
|
+
# If neither exist, make normal config instance.
|
31
|
+
# This avoid outputting "undefined method `[]'" when RBatch.config[xx] is called.
|
32
|
+
@common_config = RBatch::Config.new(@vars[:common_config_path],false)
|
33
|
+
end
|
34
|
+
@journal.put 1, "Load Config : \"#{@common_config.path}\"" if @common_config.exist?
|
35
|
+
if File.exist?(@vars[:config_path])
|
36
|
+
@config = RBatch::Config.new(@vars[:config_path],false)
|
37
|
+
elsif File.exist?(@vars[:config_erb_path])
|
38
|
+
@config = RBatch::Config.new(@vars[:config_erb_path],true)
|
39
|
+
else
|
40
|
+
# If neither exist, make normal config instance.
|
41
|
+
# This avoid outputting "undefined method `[]'" when RBatch.config[xx] is called.
|
42
|
+
@config = RBatch::Config.new(@vars[:config_path],false)
|
43
|
+
end
|
44
|
+
@journal.put 1, "Load Config : \"#{@config.path}\"" if @config.exist?
|
29
45
|
|
30
46
|
# double_run_check
|
31
47
|
if ( @vars[:forbid_double_run])
|
data/lib/rbatch/variables.rb
CHANGED
@@ -34,7 +34,9 @@ module RBatch
|
|
34
34
|
@run_conf = RunConf.new(@vars[:run_conf_path]) # load run_conf
|
35
35
|
@vars.merge!(@run_conf.opt)
|
36
36
|
@vars[:common_config_path] = File.join(@vars[:conf_dir],@vars[:common_conf_name])
|
37
|
+
@vars[:common_config_erb_path] = @vars[:common_config_path] + ".erb"
|
37
38
|
@vars[:config_path] = File.join(@vars[:conf_dir],@vars[:program_noext] + ".yaml")
|
39
|
+
@vars[:config_erb_path] = @vars[:config_path] + ".erb"
|
38
40
|
end #end def
|
39
41
|
|
40
42
|
def[](key)
|
data/lib/rbatch/version.rb
CHANGED
data/sample/.rbatchrc
CHANGED
data/spec/rbatch/config_spec.rb
CHANGED
@@ -64,6 +64,17 @@ describe RBatch::Config do
|
|
64
64
|
RBatch::Config.new(@path)["key"]
|
65
65
|
}.to raise_error(RBatch::ConfigException)
|
66
66
|
end
|
67
|
+
|
68
|
+
it "read yaml format" do
|
69
|
+
open( @path , "w" ){|f| f.write("key: <%= \"hoge\" %>")}
|
70
|
+
expect(RBatch::Config.new(@path,false)["key"]).to eq "<%= \"hoge\" %>"
|
71
|
+
end
|
72
|
+
|
73
|
+
it "read erb format" do
|
74
|
+
open( @path , "w" ){|f| f.write("key: <%= \"hoge\" %>" )}
|
75
|
+
expect(RBatch::Config.new(@path,true)["key"]).to eq "hoge"
|
76
|
+
end
|
77
|
+
|
67
78
|
end
|
68
79
|
|
69
80
|
describe RBatch::ConfigElement do
|
@@ -6,13 +6,88 @@ require 'rbatch/controller'
|
|
6
6
|
describe RBatch::Controller do
|
7
7
|
|
8
8
|
before :all do
|
9
|
-
@home = File.join(Dir.tmpdir, "rbatch_test_" + rand.to_s)
|
10
9
|
end
|
11
10
|
|
12
11
|
after :each do
|
13
12
|
end
|
14
13
|
|
15
|
-
it "
|
16
|
-
|
14
|
+
it "can reads yaml config" do
|
15
|
+
@rand = "rbatch_test_" + rand.to_s
|
16
|
+
@home = File.join(Dir.tmpdir, @rand)
|
17
|
+
@log_dir = File.join(@home,"log")
|
18
|
+
@conf_dir = File.join(@home,"conf")
|
19
|
+
ENV["RB_HOME"]=@home
|
20
|
+
|
21
|
+
Dir.mkdir(@home)
|
22
|
+
Dir.mkdir(@conf_dir)
|
23
|
+
open( File.join(@conf_dir,"rspec.yaml") , "a" ){|f|
|
24
|
+
f.write("key1 : <%= \"hoge1\" %>")
|
25
|
+
}
|
26
|
+
|
27
|
+
open( File.join(@conf_dir,"common.yaml") , "a" ){|f|
|
28
|
+
f.write("key2 : <%= \"hoge2\" %>")
|
29
|
+
}
|
30
|
+
$stdout = File.open("/tmp/rbatch.std.out", "w") # change stdout
|
31
|
+
ctrl = RBatch::Controller.new()
|
32
|
+
$stdout = STDOUT# restore stdout
|
33
|
+
|
34
|
+
expect(ctrl.config["key1"]).to eq "<%= \"hoge1\" %>"
|
35
|
+
expect(ctrl.common_config["key2"]).to eq "<%= \"hoge2\" %>"
|
36
|
+
end
|
37
|
+
|
38
|
+
it "reads erb config" do
|
39
|
+
@rand = "rbatch_test_" + rand.to_s
|
40
|
+
@home = File.join(Dir.tmpdir, @rand)
|
41
|
+
@log_dir = File.join(@home,"log")
|
42
|
+
@conf_dir = File.join(@home,"conf")
|
43
|
+
ENV["RB_HOME"]=@home
|
44
|
+
|
45
|
+
Dir.mkdir(@home)
|
46
|
+
Dir.mkdir(@conf_dir)
|
47
|
+
open( File.join(@conf_dir,"rspec.yaml.erb") , "a" ){|f|
|
48
|
+
f.write("key1 : <%= \"hoge1\" %>")
|
49
|
+
}
|
50
|
+
|
51
|
+
open( File.join(@conf_dir,"common.yaml.erb") , "a" ){|f|
|
52
|
+
f.write("key2 : <%= \"hoge2\" %>")
|
53
|
+
}
|
54
|
+
$stdout = File.open("/tmp/rbatch.std.out", "w") # change stdout
|
55
|
+
ctrl = RBatch::Controller.new()
|
56
|
+
$stdout = STDOUT# restore stdout
|
57
|
+
|
58
|
+
expect(ctrl.config["key1"]).to eq "hoge1"
|
59
|
+
expect(ctrl.common_config["key2"]).to eq "hoge2"
|
17
60
|
end
|
61
|
+
|
62
|
+
it "reads yaml config when both yaml and erb exist" do
|
63
|
+
@rand = "rbatch_test_" + rand.to_s
|
64
|
+
@home = File.join(Dir.tmpdir, @rand)
|
65
|
+
@log_dir = File.join(@home,"log")
|
66
|
+
@conf_dir = File.join(@home,"conf")
|
67
|
+
ENV["RB_HOME"]=@home
|
68
|
+
|
69
|
+
Dir.mkdir(@home)
|
70
|
+
Dir.mkdir(@conf_dir)
|
71
|
+
open( File.join(@conf_dir,"rspec.yaml") , "a" ){|f|
|
72
|
+
f.write("key1 : <%= \"hoge1\" %>")
|
73
|
+
}
|
74
|
+
open( File.join(@conf_dir,"rspec.yaml.erb") , "a" ){|f|
|
75
|
+
f.write("key1 : <%= \"hoge1\" %>")
|
76
|
+
}
|
77
|
+
|
78
|
+
open( File.join(@conf_dir,"common.yaml") , "a" ){|f|
|
79
|
+
f.write("key2 : <%= \"hoge2\" %>")
|
80
|
+
}
|
81
|
+
open( File.join(@conf_dir,"common.yaml.erb") , "a" ){|f|
|
82
|
+
f.write("key2 : <%= \"hoge2\" %>")
|
83
|
+
}
|
84
|
+
$stdout = File.open("/tmp/rbatch.std.out", "w") # change stdout
|
85
|
+
ctrl = RBatch::Controller.new()
|
86
|
+
$stdout = STDOUT# restore stdout
|
87
|
+
|
88
|
+
expect(ctrl.config["key1"]).to eq "<%= \"hoge1\" %>"
|
89
|
+
expect(ctrl.common_config["key2"]).to eq "<%= \"hoge2\" %>"
|
90
|
+
end
|
91
|
+
|
92
|
+
|
18
93
|
end
|
@@ -26,7 +26,9 @@ describe RBatch::Variables do
|
|
26
26
|
expect(@vars[:lib_dir]).to eq File.join(@home,"lib")
|
27
27
|
expect(@vars[:run_conf_path]).to eq File.join(@home,".rbatchrc")
|
28
28
|
expect(@vars[:config_path]).to eq File.join(@home,"conf","rspec.yaml")
|
29
|
+
expect(@vars[:config_erb_path]).to eq File.join(@home,"conf","rspec.yaml.erb")
|
29
30
|
expect(@vars[:common_config_path]).to eq File.join(@home,"conf","common.yaml")
|
31
|
+
expect(@vars[:common_config_erb_path]).to eq File.join(@home,"conf","common.yaml.erb")
|
30
32
|
expect(@vars.run_conf[:log_dir]).to eq "<home>/log"
|
31
33
|
expect(@vars.run_conf[:conf_dir]).to eq "<home>/conf"
|
32
34
|
expect(@vars.run_conf[:lib_dir]).to eq "<home>/lib"
|
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: rbatch
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 2.
|
5
|
+
version: 2.5.0
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- fetaro
|
@@ -10,7 +10,7 @@ autorequire:
|
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
12
|
|
13
|
-
date: 2015-06-
|
13
|
+
date: 2015-06-13 00:00:00 Z
|
14
14
|
dependencies: []
|
15
15
|
|
16
16
|
description: Batch Script Framework
|