rbatch 1.11.0 → 1.12.0

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG CHANGED
@@ -52,4 +52,9 @@ initial
52
52
 
53
53
  1.11.0(2013/02/24)
54
54
  ----
55
- * support MAC environment (change handling of the environment variable about hostname and temporary directory)
55
+ * support MAC environment (change handling of the environment variable about hostname and temporary directory)
56
+
57
+ 1.12.0(2013/11/19)
58
+ ----
59
+ * add Common Config Function
60
+ * document enhance
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 fetaro@gmail.com
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.ja.md CHANGED
@@ -11,22 +11,50 @@ RBatchについて
11
11
  主な機能は以下のとおり。
12
12
 
13
13
  * 自動ログ出力
14
+ * 自動メール送信
14
15
  * 自動設定ファイル読み込み
15
16
  * 外部コマンド実行
16
- * ファイル名・ディレクトリ構造制約
17
17
  * 二重起動チェック
18
18
 
19
- このフレームワークはRuby 1.9.x以降で動作します。また、Rubyプラットフォームは"linux","mswin","mingw","cygwin"で動作します。
19
+ 注意:このフレームワークはRuby 1.9.x以降で動作します。また、Rubyプラットフォームは"linux","mswin","mingw","cygwin"で動作します。
20
+
21
+ ### はじめに
22
+
23
+ RBatchでは、実行スクリプト、設定ファイルおよびログファイルについて、
24
+ 配置場所および命名規則が規約で決まっています。
25
+
26
+ 具体的には、"bin/hoge.rb"というバッチスクリプトでは、"conf/hoge.yaml"という設定ファイルを読み、
27
+ "log/YYYYMMDD_HHMMSS_hoge.rb"というログを出力するという規則です。
28
+
29
+ 例を示すと以下の通りです。
30
+
31
+ ```
32
+ $RB_HOME
33
+ |-bin ←実行スクリプト配置場所
34
+ | |- A.rb
35
+ | |- B.rb
36
+ |
37
+ |-conf ←設定ファイル配置場所
38
+ | |- A.yaml
39
+ | |- B.yaml
40
+ | |- rbatch.yaml ←RBatch全体設定ファイル
41
+ |
42
+ |-log ←ログ出力場所
43
+ |- YYYYMMDD_HHMMSS_A.log
44
+ |- YYYYMMDD_HHMMSS_B.log
45
+ ```
46
+
47
+ 注意:$RB_HOMEは環境変数として定義する必要はありません。$RB_HOMEは"(実行するスクリプトのパス)/../"として定義されています
20
48
 
21
49
  ### 自動ログ出力
50
+
22
51
  Logging blockを使うことで、自動的にログファイルに出力することができます。
23
- ログファイルはデフォルトで"../log/YYYYMMDD_HHMMSS_${PROG_NAME}.log"に出力されます。
52
+ ログファイルはデフォルトで"$RB_HOME/log/YYYYMMDD_HHMMSS_${PROG_NAME}.log"に出力されます。
24
53
  例外が発生した場合でも、ログにスタックトレースを出力することができます。
25
- また、エラーが発生した場合に自動でメールを送信することもできます。
26
54
 
27
55
  サンプル
28
56
 
29
- スクリプト : ./bin/sample1.rb
57
+ スクリプト : $RB_HOME/bin/sample1.rb
30
58
  ```
31
59
  require 'rbatch'
32
60
 
@@ -37,7 +65,7 @@ RBatch::Log.new(){ |log| # Logging block
37
65
  }
38
66
  ```
39
67
 
40
- ログファイル : ./log/20121020_005953_sample1.log
68
+ ログファイル : $RB_HOME/log/20121020_005953_sample1.log
41
69
  ```
42
70
  # Logfile created on 2012-10-20 00:59:53 +0900 by logger.rb/25413
43
71
  [2012-10-20 00:59:53 +900] [INFO ] info string
@@ -50,6 +78,10 @@ RBatch::Log.new(){ |log| # Logging block
50
78
  [backtrace] test.rb:3:in `<main>'
51
79
  ```
52
80
 
81
+ ### 自動メール送信
82
+
83
+ "log_send_mail"オプションを使う事により、スクリプトでエラーが発生した場合に、自動でメールを送信することができます。
84
+
53
85
  ### 自動設定ファイル読み込み
54
86
 
55
87
  RBatchは簡単にデフォルトの位置の設定ファイルを読み込めます。
@@ -57,7 +89,7 @@ RBatchは簡単にデフォルトの位置の設定ファイルを読み込め
57
89
 
58
90
  サンプル
59
91
 
60
- 設定ファイル : ./conf/sample2.yaml
92
+ 設定ファイル : $RB_HOME/conf/sample2.yaml
61
93
  ```
62
94
  key: value
63
95
  array:
@@ -66,7 +98,7 @@ array:
66
98
  - item3
67
99
  ```
68
100
 
69
- スクリプト : ./bin/sample2.rb
101
+ スクリプト : $RB_HOME/bin/sample2.rb
70
102
  ```
71
103
  require 'rbatch'
72
104
  p RBatch::config
@@ -96,28 +128,6 @@ p r.status
96
128
  => 0
97
129
  ```
98
130
 
99
- ### ファイル名・ディレクトリ構造制約
100
-
101
- RBatchでは、「設定より規約」(convention over configuration)という原則に従い、バッチスクリプトで必要になるファイル群に、ファイル名とディレクトリ構造の制約をもたせます。
102
-
103
- 具体的には、"bin/hoge.rb"というバッチスクリプトでは、"conf/hoge.yaml"という設定ファイルを読み、
104
- "log/YYYYMMDD_HHMMSS_hoge.rb"というログを出力するという規則です。
105
-
106
- これにより、バッチスクリプトの可読性・保守性が向上します。
107
-
108
- ```
109
- ./
110
- |-bin
111
- | |- hoge.rb
112
- | |- bar.rb
113
- |-conf
114
- | |- hoge.yaml
115
- | |- bar.yaml
116
- |-log
117
- |- YYYYMMDD_HHMMSS_hoge.log
118
- |- YYYYMMDD_HHMMSS_bar.log
119
- ```
120
-
121
131
  ### 二重起動チェック
122
132
 
123
133
  RBatchの共通設定ファイルに"forbid_double_run: true"の設定を書けば、RBatchを利用したスクリプトの二重起動チェックができます。
@@ -136,7 +146,7 @@ RBatchの共通設定ファイルに"forbid_double_run: true"の設定を書け
136
146
 
137
147
  RBatchではオプションの指定の仕方は以下の二つがあります。
138
148
 
139
- 1. 全体設定ファイル(conf/rbatch.yaml)に書く
149
+ 1. 全体設定ファイル($RB_HOME/conf/rbatch.yaml)に書く
140
150
  2. コンストラクタの引数に指定する
141
151
 
142
152
  全体設定ファイルにオプションを書くと、全てのスクリプトに効果がありますが、コンストラクタの引数に指定した場合はそのインスタンスのみ効果があります。
@@ -151,7 +161,7 @@ RBatchではオプションの指定の仕方は以下の二つがあります
151
161
  以下の場所にRBatch全体設定ファイルを配置すると、全てのスクリプトにてオプションが適用されます。
152
162
 
153
163
 
154
- (スクリプトのパス)/../conf/rbatch.yaml
164
+ $RB_HOME/conf/rbatch.yaml
155
165
 
156
166
 
157
167
  設定ファイルのサンプルは以下の通り
data/README.md CHANGED
@@ -5,27 +5,54 @@ RBatch:Ruby-base Simple Batch Framework
5
5
 
6
6
  About RBatch
7
7
  --------------
8
- This is a Ruby-base Batch Script Framework. RBatch offer a convenient function as a framework, when you write a batch script such as "data backup script" or "proccess start script".
8
+ This is Ruby-base Batch Script Framework. RBatch offers convenient functions, when you write batch scripts such as "data backup script" or "proccess starting script".
9
9
 
10
10
  There are following functions.
11
11
 
12
12
  * Auto Logging
13
+ * Auto Mail Sending
13
14
  * Auto Config Reading
14
15
  * External Command Wrapper
15
- * Directory Structure convention
16
16
  * Double Run Check
17
17
 
18
- This work on Ruby 1.9.x or later, and on Ruby platform of "linux","mswin","mingw","cygwin".
18
+
19
+ Note: RBatch works on Ruby 1.9.x or later, and on Ruby platform of "linux","mswin","mingw","cygwin".
20
+
21
+ ### First
22
+
23
+ RBach has convention of file naming and directorory structure.
24
+
25
+ If you make "$RB_HOME/bin/hoge.rb", you should name config file to "$RB_HOME/conf/hoge.yaml". And the name of log file is decided on "$RB_HOME/log/YYYYMMDD_HHMMSS_hoge.rb"
26
+
27
+ For example
28
+ ```
29
+ $RB_HOME/ <--- RBatch home
30
+ |-bin <--- Scripts
31
+ | |- A.rb
32
+ | |- B.rb
33
+ |
34
+ |-conf <--- Configuration files
35
+ | |- A.yaml
36
+ | |- B.yaml
37
+ | |- rbatch.yaml <--- RBatch global config
38
+ |
39
+ |-log <--- Log files
40
+ |- YYYYMMDD_HHMMSS_A.log
41
+ |- YYYYMMDD_HHMMSS_B.log
42
+ ```
43
+
44
+ Note: It is not necessary to define $RB_HOME as an environment variable. $RB_HOME is defined as "(running script path)/../"
45
+
19
46
 
20
47
  ### Auto Logging
21
- Use Auto Logging block, RBatch automatically write to logfile.
22
- Log file default location is "(script file path)/../log/YYYYMMDD_HHMMSS_${PROG_NAME}.log" .
23
- If exception occuerd, then RBatch write stack trace to logfile.
24
- When an error occurs, there is also a function to send an error by e-mail automatically.
48
+
49
+ Use "Auto Logging block", RBatch automatically writes to logfile.
50
+ The default location of log file is $RB_HOME/log/YYYYMMDD_HHMMSS_${PROG_NAME}.log .
51
+ If an exception occuerd, then RBatch write a stack trace to logfile.
25
52
 
26
53
  sample
27
54
 
28
- script : ./bin/sample1.rb
55
+ script : $RB_HOME/bin/sample1.rb
29
56
  ```
30
57
  require 'rbatch'
31
58
 
@@ -36,7 +63,7 @@ RBatch::Log.new(){ |log| # Logging block
36
63
  }
37
64
  ```
38
65
 
39
- logfile : ./log/20121020_005953_sample1.log
66
+ logfile : $RB_HOME/log/20121020_005953_sample1.log
40
67
  ```
41
68
  # Logfile created on 2012-10-20 00:59:53 +0900 by logger.rb/25413
42
69
  [2012-10-20 00:59:53 +900] [INFO ] info string
@@ -49,13 +76,21 @@ logfile : ./log/20121020_005953_sample1.log
49
76
  [backtrace] test.rb:3:in `<main>'
50
77
  ```
51
78
 
79
+ ### Auto Mail Sending
80
+
81
+ By using "log_send_mail" option, when an error occurs in script, RBatch sends an error-mail automatically.
82
+
83
+
52
84
  ### Auto Config Reading
53
85
 
54
- RBatch easy to read config file (located on "(script file path)/../conf/${PROG_NAME}.yaml")
86
+ By using RBatch, your script read a configuration file easily.
87
+ First you make configuration file which is named "(script base name).yaml" ,
88
+ Then, put it to $RB_HOME/conf/ .
89
+ So your script read it automatically.
55
90
 
56
91
  sample
57
92
 
58
- config : ./conf/sample2.yaml
93
+ config : $RB_HOME/conf/sample2.yaml
59
94
  ```
60
95
  key: value
61
96
  array:
@@ -64,7 +99,7 @@ array:
64
99
  - item3
65
100
  ```
66
101
 
67
- script : ./bin/sample2.rb
102
+ script : $RB_HOME/bin/sample2.rb
68
103
  ```
69
104
  require 'rbatch'
70
105
  p RBatch::config
@@ -77,7 +112,11 @@ p RBatch::config["not_exist"]
77
112
  => Raise Exception
78
113
  ```
79
114
 
115
+ If you can use common configuration file which is read from all scripts,
116
+ you make "$RB_HOME/conf/common.yaml" .
117
+
80
118
  ### External Command Wrapper
119
+
81
120
  RBatch provide a function which wrap external command (such as 'ls').
82
121
 
83
122
  This function return a result object which contain command's STDOUT, STDERR ,and exit status.
@@ -94,30 +133,10 @@ p r.status
94
133
  => 0
95
134
  ```
96
135
 
97
- ### Directory Structure Convention
98
-
99
- Follow the axiom of "convention over configuration", RBatch restrict file naming rule and directory structure.
100
-
101
- For exsample, If you make "bin/hoge.rb", you should name config file to "conf/hoge.yaml". And the name of log file is decided on "log/YYYYMMDD_HHMMSS_hoge.rb"
102
-
103
- In this way, maintainability and readability of batch script get higher.
104
-
105
- ```
106
- ./
107
- |-bin
108
- | |- hoge.rb
109
- | |- bar.rb
110
- |-conf
111
- | |- hoge.yaml
112
- | |- bar.yaml
113
- |-log
114
- |- YYYYMMDD_HHMMSS_hoge.log
115
- |- YYYYMMDD_HHMMSS_bar.log
116
- ```
117
-
118
136
  ### Double Run Check
119
137
 
120
- Forbit double run of the RBatch script by writing option "forbid_double_run: true" to the common configuration file.
138
+ Using "forbid_double_run" option, you forbit double run of the RBatch script.
139
+
121
140
 
122
141
  Quick Start
123
142
  --------------
@@ -146,7 +165,7 @@ The name of the key to global configuration file and the name of the key to cons
146
165
  If you make follow config file, option value effect to all scripts.
147
166
 
148
167
  ```
149
- (script file path)/../conf/rbatch.yaml
168
+ $RB_HOME/conf/rbatch.yaml
150
169
  ```
151
170
 
152
171
  Config Sample
@@ -245,9 +245,9 @@ is 0 sec ( 0 means disable) .
245
245
  52: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">opt</span> <span class="ruby-operator">!=</span> <span class="ruby-keyword kw">nil</span> <span class="ruby-operator">&amp;&amp;</span> <span class="ruby-identifier">opt</span>[<span class="ruby-identifier">key</span>] <span class="ruby-operator">!=</span> <span class="ruby-keyword kw">nil</span>
246
246
  53: <span class="ruby-comment cmt"># use argument</span>
247
247
  54: <span class="ruby-ivar">@opt</span>[<span class="ruby-identifier">key</span>] = <span class="ruby-identifier">opt</span>[<span class="ruby-identifier">key</span>]
248
- 55: <span class="ruby-keyword kw">elsif</span> <span class="ruby-constant">RBatch</span>.<span class="ruby-identifier">common_config</span> <span class="ruby-operator">!=</span> <span class="ruby-keyword kw">nil</span> <span class="ruby-operator">&amp;&amp;</span> <span class="ruby-constant">RBatch</span>.<span class="ruby-identifier">common_config</span>[<span class="ruby-value str">&quot;cmd_&quot;</span> <span class="ruby-operator">+</span> <span class="ruby-identifier">key</span>.<span class="ruby-identifier">to_s</span>] <span class="ruby-operator">!=</span> <span class="ruby-keyword kw">nil</span>
248
+ 55: <span class="ruby-keyword kw">elsif</span> <span class="ruby-constant">RBatch</span>.<span class="ruby-identifier">rbatch_config</span> <span class="ruby-operator">!=</span> <span class="ruby-keyword kw">nil</span> <span class="ruby-operator">&amp;&amp;</span> <span class="ruby-constant">RBatch</span>.<span class="ruby-identifier">rbatch_config</span>[<span class="ruby-value str">&quot;cmd_&quot;</span> <span class="ruby-operator">+</span> <span class="ruby-identifier">key</span>.<span class="ruby-identifier">to_s</span>] <span class="ruby-operator">!=</span> <span class="ruby-keyword kw">nil</span>
249
249
  56: <span class="ruby-comment cmt"># use config</span>
250
- 57: <span class="ruby-ivar">@opt</span>[<span class="ruby-identifier">key</span>] = <span class="ruby-constant">RBatch</span>.<span class="ruby-identifier">common_config</span>[<span class="ruby-value str">&quot;cmd_&quot;</span> <span class="ruby-operator">+</span> <span class="ruby-identifier">key</span>.<span class="ruby-identifier">to_s</span>]
250
+ 57: <span class="ruby-ivar">@opt</span>[<span class="ruby-identifier">key</span>] = <span class="ruby-constant">RBatch</span>.<span class="ruby-identifier">rbatch_config</span>[<span class="ruby-value str">&quot;cmd_&quot;</span> <span class="ruby-operator">+</span> <span class="ruby-identifier">key</span>.<span class="ruby-identifier">to_s</span>]
251
251
  58: <span class="ruby-keyword kw">else</span>
252
252
  59: <span class="ruby-comment cmt"># use default</span>
253
253
  60: <span class="ruby-keyword kw">end</span>
@@ -288,9 +288,9 @@ is true.
288
288
  100: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">opt</span> <span class="ruby-operator">!=</span> <span class="ruby-keyword kw">nil</span> <span class="ruby-operator">&amp;&amp;</span> <span class="ruby-identifier">opt</span>[<span class="ruby-identifier">key</span>] <span class="ruby-operator">!=</span> <span class="ruby-keyword kw">nil</span>
289
289
  101: <span class="ruby-comment cmt"># use argument</span>
290
290
  102: <span class="ruby-ivar">@opt</span>[<span class="ruby-identifier">key</span>] = <span class="ruby-identifier">opt</span>[<span class="ruby-identifier">key</span>]
291
- 103: <span class="ruby-keyword kw">elsif</span> <span class="ruby-constant">RBatch</span>.<span class="ruby-identifier">common_config</span> <span class="ruby-operator">!=</span> <span class="ruby-keyword kw">nil</span> <span class="ruby-operator">&amp;&amp;</span> <span class="ruby-constant">RBatch</span>.<span class="ruby-identifier">common_config</span>[<span class="ruby-value str">&quot;log_&quot;</span> <span class="ruby-operator">+</span> <span class="ruby-identifier">key</span>.<span class="ruby-identifier">to_s</span>] <span class="ruby-operator">!=</span> <span class="ruby-keyword kw">nil</span>
291
+ 103: <span class="ruby-keyword kw">elsif</span> <span class="ruby-constant">RBatch</span>.<span class="ruby-identifier">rbatch_config</span> <span class="ruby-operator">!=</span> <span class="ruby-keyword kw">nil</span> <span class="ruby-operator">&amp;&amp;</span> <span class="ruby-constant">RBatch</span>.<span class="ruby-identifier">rbatch_config</span>[<span class="ruby-value str">&quot;log_&quot;</span> <span class="ruby-operator">+</span> <span class="ruby-identifier">key</span>.<span class="ruby-identifier">to_s</span>] <span class="ruby-operator">!=</span> <span class="ruby-keyword kw">nil</span>
292
292
  104: <span class="ruby-comment cmt"># use config</span>
293
- 105: <span class="ruby-ivar">@opt</span>[<span class="ruby-identifier">key</span>] = <span class="ruby-constant">RBatch</span>.<span class="ruby-identifier">common_config</span>[<span class="ruby-value str">&quot;log_&quot;</span> <span class="ruby-operator">+</span> <span class="ruby-identifier">key</span>.<span class="ruby-identifier">to_s</span>]
293
+ 105: <span class="ruby-ivar">@opt</span>[<span class="ruby-identifier">key</span>] = <span class="ruby-constant">RBatch</span>.<span class="ruby-identifier">rbatch_config</span>[<span class="ruby-value str">&quot;log_&quot;</span> <span class="ruby-operator">+</span> <span class="ruby-identifier">key</span>.<span class="ruby-identifier">to_s</span>]
294
294
  106: <span class="ruby-keyword kw">else</span>
295
295
  107: <span class="ruby-comment cmt"># use default</span>
296
296
  108: <span class="ruby-keyword kw">end</span>
data/doc/rdoc/RBatch.html CHANGED
@@ -90,9 +90,9 @@
90
90
 
91
91
  <li><a href="#method-i-cmd">#cmd</a></li>
92
92
 
93
- <li><a href="#method-i-common_config">#common_config</a></li>
93
+ <li><a href="#method-i-rbatch_config">#rbatch_config</a></li>
94
94
 
95
- <li><a href="#method-i-common_config_path">#common_config_path</a></li>
95
+ <li><a href="#method-i-rbatch_config_path">#rbatch_config_path</a></li>
96
96
 
97
97
  <li><a href="#method-i-config">#config</a></li>
98
98
 
@@ -224,11 +224,11 @@ shortcut of <a href="RBatch/Cmd.html">RBatch::Cmd</a>
224
224
 
225
225
 
226
226
  <div id="common-config-method" class="method-detail ">
227
- <a name="method-i-common_config"></a>
227
+ <a name="method-i-rbatch_config"></a>
228
228
 
229
229
  <div class="method-heading">
230
230
 
231
- <span class="method-name">common_config</span><span
231
+ <span class="method-name">rbatch_config</span><span
232
232
  class="method-args">()</span>
233
233
  <span class="method-click-advice">click to toggle source</span>
234
234
 
@@ -244,9 +244,9 @@ shortcut of <a href="RBatch/Cmd.html">RBatch::Cmd</a>
244
244
  id="common-config-source">
245
245
  <pre>
246
246
  <span class="ruby-comment cmt"># File lib/rbatch.rb, line 21</span>
247
- 21: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">common_config</span>
248
- 22: <span class="ruby-keyword kw">if</span> <span class="ruby-constant">File</span>.<span class="ruby-identifier">exist?</span>(<span class="ruby-constant">RBatch</span>.<span class="ruby-identifier">common_config_path</span>)
249
- 23: <span class="ruby-identifier">yaml</span> = <span class="ruby-constant">YAML</span><span class="ruby-operator">::</span><span class="ruby-identifier">load_file</span>(<span class="ruby-constant">RBatch</span>.<span class="ruby-identifier">common_config_path</span>)
247
+ 21: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">rbatch_config</span>
248
+ 22: <span class="ruby-keyword kw">if</span> <span class="ruby-constant">File</span>.<span class="ruby-identifier">exist?</span>(<span class="ruby-constant">RBatch</span>.<span class="ruby-identifier">rbatch_config_path</span>)
249
+ 23: <span class="ruby-identifier">yaml</span> = <span class="ruby-constant">YAML</span><span class="ruby-operator">::</span><span class="ruby-identifier">load_file</span>(<span class="ruby-constant">RBatch</span>.<span class="ruby-identifier">rbatch_config_path</span>)
250
250
  24: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">yaml</span>
251
251
  25: <span class="ruby-keyword kw">return</span> <span class="ruby-identifier">yaml</span>
252
252
  26: <span class="ruby-keyword kw">else</span>
@@ -268,11 +268,11 @@ shortcut of <a href="RBatch/Cmd.html">RBatch::Cmd</a>
268
268
 
269
269
 
270
270
  <div id="common-config-path-method" class="method-detail ">
271
- <a name="method-i-common_config_path"></a>
271
+ <a name="method-i-rbatch_config_path"></a>
272
272
 
273
273
  <div class="method-heading">
274
274
 
275
- <span class="method-name">common_config_path</span><span
275
+ <span class="method-name">rbatch_config_path</span><span
276
276
  class="method-args">()</span>
277
277
  <span class="method-click-advice">click to toggle source</span>
278
278
 
@@ -288,7 +288,7 @@ shortcut of <a href="RBatch/Cmd.html">RBatch::Cmd</a>
288
288
  id="common-config-path-source">
289
289
  <pre>
290
290
  <span class="ruby-comment cmt"># File lib/rbatch.rb, line 18</span>
291
- 18: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">common_config_path</span>
291
+ 18: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">rbatch_config_path</span>
292
292
  19: <span class="ruby-constant">File</span>.<span class="ruby-identifier">join</span>(<span class="ruby-constant">File</span>.<span class="ruby-identifier">dirname</span>(<span class="ruby-constant">RBatch</span>.<span class="ruby-identifier">program_name</span>),<span class="ruby-value str">&quot;..&quot;</span>,<span class="ruby-value str">&quot;conf&quot;</span>,<span class="ruby-value str">&quot;rbatch.yaml&quot;</span>)
293
293
  20: <span class="ruby-keyword kw">end</span></pre>
294
294
  </div>
@@ -358,7 +358,7 @@ Alias of RBatch::Config.new
358
358
  <span class="ruby-comment cmt"># File lib/rbatch.rb, line 34</span>
359
359
  34: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">double_run_check</span>
360
360
  35: <span class="ruby-comment cmt"># double run check</span>
361
- 36: <span class="ruby-keyword kw">if</span> ( <span class="ruby-constant">RBatch</span><span class="ruby-operator">::</span><span class="ruby-identifier">common_config</span> <span class="ruby-operator">!=</span> <span class="ruby-keyword kw">nil</span> <span class="ruby-operator">&amp;&amp;</span> <span class="ruby-constant">RBatch</span><span class="ruby-operator">::</span><span class="ruby-identifier">common_config</span>[<span class="ruby-value str">&quot;forbid_double_run&quot;</span>] )
361
+ 36: <span class="ruby-keyword kw">if</span> ( <span class="ruby-constant">RBatch</span><span class="ruby-operator">::</span><span class="ruby-identifier">rbatch_config</span> <span class="ruby-operator">!=</span> <span class="ruby-keyword kw">nil</span> <span class="ruby-operator">&amp;&amp;</span> <span class="ruby-constant">RBatch</span><span class="ruby-operator">::</span><span class="ruby-identifier">rbatch_config</span>[<span class="ruby-value str">&quot;forbid_double_run&quot;</span>] )
362
362
  37: <span class="ruby-identifier">lock_file</span>=<span class="ruby-value str">&quot;rbatch_lock_&quot;</span> <span class="ruby-operator">+</span> <span class="ruby-constant">Digest</span><span class="ruby-operator">::</span><span class="ruby-constant">MD5</span>.<span class="ruby-identifier">hexdigest</span>(<span class="ruby-identifier">@@program_name</span>)
363
363
  38: <span class="ruby-keyword kw">if</span> <span class="ruby-constant">Dir</span>.<span class="ruby-identifier">exists?</span> <span class="ruby-constant">RBatch</span><span class="ruby-operator">::</span><span class="ruby-identifier">tmp_dir</span>
364
364
  39: <span class="ruby-constant">Dir</span><span class="ruby-operator">::</span><span class="ruby-identifier">foreach</span>(<span class="ruby-constant">RBatch</span><span class="ruby-operator">::</span><span class="ruby-identifier">tmp_dir</span>) <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">f</span><span class="ruby-operator">|</span>
data/doc/rdoc/index.html CHANGED
@@ -81,9 +81,9 @@
81
81
 
82
82
  <li><a href="RBatch/CmdResult.html#method-i-cmd_str">#cmd_str &mdash; RBatch::CmdResult</a></li>
83
83
 
84
- <li><a href="RBatch.html#method-i-common_config">#common_config &mdash; RBatch</a></li>
84
+ <li><a href="RBatch.html#method-i-rbatch_config">#rbatch_config &mdash; RBatch</a></li>
85
85
 
86
- <li><a href="RBatch.html#method-i-common_config_path">#common_config_path &mdash; RBatch</a></li>
86
+ <li><a href="RBatch.html#method-i-rbatch_config_path">#rbatch_config_path &mdash; RBatch</a></li>
87
87
 
88
88
  <li><a href="RBatch.html#method-i-config">#config &mdash; RBatch</a></li>
89
89
 
data/lib/rbatch/cmd.rb CHANGED
@@ -52,10 +52,10 @@ module RBatch
52
52
  if opt != nil && opt[key] != nil
53
53
  # use argument
54
54
  @opt[key] = opt[key]
55
- elsif RBatch.common_config != nil \
56
- && RBatch.common_config["cmd_" + key.to_s] != nil
55
+ elsif RBatch.rbatch_config != nil \
56
+ && RBatch.rbatch_config["cmd_" + key.to_s] != nil
57
57
  # use config
58
- @opt[key] = RBatch.common_config["cmd_" + key.to_s]
58
+ @opt[key] = RBatch.rbatch_config["cmd_" + key.to_s]
59
59
  else
60
60
  # use default
61
61
  end
@@ -0,0 +1,44 @@
1
+ require 'yaml'
2
+ require 'pathname'
3
+
4
+ module RBatch
5
+
6
+ module_function
7
+
8
+ # Alias of RBatch::CommonConfig.new
9
+ def common_config ; CommonConfig.new end
10
+
11
+ # Read common config file and return hash opject.
12
+ #
13
+ # Default common config file path is "../conf/common.yaml"
14
+ # ==== Sample
15
+ # config : ./conf/common.yaml
16
+ # key: value
17
+ # array:
18
+ # - item1
19
+ # - item2
20
+ # - item3
21
+ # script : ./bin/sample.rb
22
+ # require 'rbatch'
23
+ # p RBatch::common_config
24
+ # => {"key" => "value", "array" => ["item1", "item2", "item3"]}
25
+ class CommonConfig
26
+ @path
27
+ @config
28
+ def initialize
29
+ file = "common.yaml"
30
+ dir = File.join(File.join(File.dirname(RBatch.program_name),".."),"conf")
31
+ @path = File.join(dir,file)
32
+ @config = YAML::load_file(@path)
33
+ end
34
+ def[](key)
35
+ raise RBatch::CommonConfig::Exception, "Value of key=\"#{key}\" is nil" if @config[key].nil?
36
+ @config[key]
37
+ end
38
+ def path ; @path ; end
39
+ def to_s ; @config.to_s ;end
40
+ end
41
+
42
+ class RBatch::CommonConfig::Exception < Exception; end
43
+ end
44
+
data/lib/rbatch/log.rb CHANGED
@@ -100,10 +100,10 @@ module RBatch
100
100
  if opt != nil && opt[key] != nil
101
101
  # use argument
102
102
  @opt[key] = opt[key]
103
- elsif RBatch.common_config != nil \
104
- && RBatch.common_config["log_" + key.to_s] != nil
103
+ elsif RBatch.rbatch_config != nil \
104
+ && RBatch.rbatch_config["log_" + key.to_s] != nil
105
105
  # use config
106
- @opt[key] = RBatch.common_config["log_" + key.to_s]
106
+ @opt[key] = RBatch.rbatch_config["log_" + key.to_s]
107
107
  else
108
108
  # use default
109
109
  end
@@ -1,3 +1,3 @@
1
1
  module Rbatch
2
- VERSION = "1.11.0"
2
+ VERSION = "1.12.0"
3
3
  end
data/lib/rbatch.rb CHANGED
@@ -35,12 +35,12 @@ module RBatch
35
35
  end
36
36
  end
37
37
  end
38
- def common_config_path
38
+ def rbatch_config_path
39
39
  File.join(File.dirname(RBatch.program_name),"..","conf","rbatch.yaml")
40
40
  end
41
- def common_config
42
- if File.exist?(RBatch.common_config_path)
43
- yaml = YAML::load_file(RBatch.common_config_path)
41
+ def rbatch_config
42
+ if File.exist?(RBatch.rbatch_config_path)
43
+ yaml = YAML::load_file(RBatch.rbatch_config_path)
44
44
  if yaml
45
45
  return yaml
46
46
  else
@@ -53,7 +53,7 @@ module RBatch
53
53
  end
54
54
  def double_run_check
55
55
  # double run check
56
- if ( RBatch::common_config != nil && RBatch::common_config["forbid_double_run"] )
56
+ if ( RBatch::rbatch_config != nil && RBatch::rbatch_config["forbid_double_run"] )
57
57
  lock_file="rbatch_lock_" + Digest::MD5.hexdigest(@@program_name)
58
58
  if Dir.exists? RBatch::tmp_dir
59
59
  Dir::foreach(RBatch::tmp_dir) do |f|
@@ -76,6 +76,7 @@ class RBatchException < Exception ; end
76
76
  # main
77
77
  require 'rbatch/log'
78
78
  require 'rbatch/config'
79
+ require 'rbatch/common_config'
79
80
  require 'rbatch/cmd'
80
81
 
81
82
  RBatch::double_run_check
@@ -6,7 +6,7 @@ class RuncherTest < Test::Unit::TestCase
6
6
  @config_dir = File.join(File.dirname(RBatch.program_name), "..", "conf")
7
7
  Dir::mkdir(@config_dir) if ! Dir.exists? @config_dir
8
8
  confstr = ""
9
- open( RBatch.common_config_path , "w" ){|f| f.write(confstr)}
9
+ open( RBatch.rbatch_config_path , "w" ){|f| f.write(confstr)}
10
10
  end
11
11
 
12
12
  def test_cmd_exists
@@ -104,7 +104,7 @@ class RuncherTest < Test::Unit::TestCase
104
104
  end
105
105
  def test_opt_raise_true_status_1_by_conf
106
106
  confstr = "cmd_raise: true "
107
- open( RBatch.common_config_path , "a" ){|f| f.write(confstr)}
107
+ open( RBatch.rbatch_config_path , "a" ){|f| f.write(confstr)}
108
108
  cmd_str = "ruby -e 'STDOUT.print 1; STDERR.print 2; exit 1;'"
109
109
  assert_raise(RBatch::CmdException){
110
110
  RBatch::Cmd.new(cmd_str).run
@@ -0,0 +1,41 @@
1
+ require 'test/unit'
2
+ require 'rbatch'
3
+
4
+ class RuncherTest < Test::Unit::TestCase
5
+ def setup
6
+ @config_dir = File.join(File.dirname(RBatch.program_name), "..", "conf")
7
+ @config_file = File.join(@config_dir,"common.yaml")
8
+ Dir::mkdir(@config_dir) if ! Dir.exists? @config_dir
9
+ end
10
+
11
+ def teardown
12
+ File.delete @config_file if File.exist? @config_file
13
+ end
14
+
15
+ def test_require
16
+ end
17
+
18
+ def test_config
19
+ open( @config_file , "w" ){|f| f.write("key: value")}
20
+ assert_equal "value", RBatch.common_config["key"]
21
+ end
22
+
23
+ def test_read_error
24
+ assert_raise(Errno::ENOENT){
25
+ RBatch.common_config
26
+ }
27
+ end
28
+
29
+ def test_double_read
30
+ open( @config_file , "w" ){|f| f.write("key: value")}
31
+ assert_equal "value", RBatch.common_config["key"]
32
+ assert_equal "value", RBatch.common_config["key"]
33
+ end
34
+
35
+ def test_not_exist_key
36
+ open( @config_file , "w" ){|f| f.write("key: value")}
37
+ assert_raise(RBatch::CommonConfig::Exception){
38
+ RBatch.common_config["not_exist"]
39
+ }
40
+ end
41
+ end
@@ -13,12 +13,12 @@ class LoggerTest < Test::Unit::TestCase
13
13
  # RBatch::Log.verbose = true
14
14
  # set STDOUT Logger stop
15
15
  confstr = "log_quiet: true\n"
16
- open( RBatch.common_config_path , "w" ){|f| f.write(confstr)}
16
+ open( RBatch.rbatch_config_path , "w" ){|f| f.write(confstr)}
17
17
 
18
18
  end
19
19
 
20
20
  def teardown
21
- File::delete(RBatch.common_config_path) if File.exists?(RBatch.common_config_path)
21
+ File::delete(RBatch.rbatch_config_path) if File.exists?(RBatch.rbatch_config_path)
22
22
  if Dir.exists? @dir
23
23
  Dir::foreach(@dir) do |f|
24
24
  File::delete(File.join(@dir , f)) if ! (/\.+$/ =~ f)
@@ -84,7 +84,7 @@ class LoggerTest < Test::Unit::TestCase
84
84
 
85
85
  def test_change_name_by_config
86
86
  confstr = "log_name: name1"
87
- open( RBatch.common_config_path , "a" ){|f| f.write(confstr)}
87
+ open( RBatch.rbatch_config_path , "a" ){|f| f.write(confstr)}
88
88
  RBatch::Log.new({:name => "name1.log" }) do | log |
89
89
  log.info("test_change_name_by_config")
90
90
  end
@@ -109,7 +109,7 @@ class LoggerTest < Test::Unit::TestCase
109
109
 
110
110
  def test_change_log_dir_by_config
111
111
  confstr = "log_dir: " + @dir2
112
- open( RBatch.common_config_path , "a" ){|f| f.write(confstr)}
112
+ open( RBatch.rbatch_config_path , "a" ){|f| f.write(confstr)}
113
113
  RBatch::Log.new({:output_dir=> @dir2 }) do | log |
114
114
  log.info("test_change_log_dir_by_config")
115
115
  end
@@ -135,7 +135,7 @@ class LoggerTest < Test::Unit::TestCase
135
135
 
136
136
  def test_opt_overwite_config
137
137
  confstr = "log_name: " + "name1"
138
- open( RBatch.common_config_path , "a" ){|f| f.write(confstr)}
138
+ open( RBatch.rbatch_config_path , "a" ){|f| f.write(confstr)}
139
139
  RBatch::Log.new({:name => "name2" }) do | log |
140
140
  log.info("test_opt_overwite_config")
141
141
  end
@@ -175,7 +175,7 @@ class LoggerTest < Test::Unit::TestCase
175
175
 
176
176
  def test_append_by_conf
177
177
  confstr = "log_append: true"
178
- open( RBatch.common_config_path , "a" ){|f| f.write(confstr)}
178
+ open( RBatch.rbatch_config_path , "a" ){|f| f.write(confstr)}
179
179
 
180
180
  RBatch::Log.new({:name => "test_append" }) do | log |
181
181
  log.info("test_append1")
@@ -192,7 +192,7 @@ class LoggerTest < Test::Unit::TestCase
192
192
 
193
193
  def test_no_append_by_conf
194
194
  confstr = "log_append: false"
195
- open( RBatch.common_config_path , "a" ){|f| f.write(confstr)}
195
+ open( RBatch.rbatch_config_path , "a" ){|f| f.write(confstr)}
196
196
 
197
197
  RBatch::Log.new({ :name => "test_append" }) do | log |
198
198
  log.info("test_append1")
@@ -318,7 +318,7 @@ class LoggerTest < Test::Unit::TestCase
318
318
 
319
319
  def test_log_level_debug_by_conf
320
320
  confstr = "log_level: debug"
321
- open( RBatch.common_config_path , "a" ){|f| f.write(confstr)}
321
+ open( RBatch.rbatch_config_path , "a" ){|f| f.write(confstr)}
322
322
 
323
323
  RBatch::Log.new({ :name => "test_level" }) do | log |
324
324
  log.debug("test_debug")
@@ -339,7 +339,7 @@ class LoggerTest < Test::Unit::TestCase
339
339
 
340
340
  def test_log_level_info_by_conf
341
341
  confstr = "log_level: info"
342
- open( RBatch.common_config_path , "a" ){|f| f.write(confstr)}
342
+ open( RBatch.rbatch_config_path , "a" ){|f| f.write(confstr)}
343
343
  RBatch::Log.new({ :name => "test_level" }) do | log |
344
344
  log.debug("test_debug")
345
345
  log.info("test_info")
@@ -359,7 +359,7 @@ class LoggerTest < Test::Unit::TestCase
359
359
 
360
360
  def test_log_level_warn_by_conf
361
361
  confstr = "log_level: warn"
362
- open( RBatch.common_config_path , "a" ){|f| f.write(confstr)}
362
+ open( RBatch.rbatch_config_path , "a" ){|f| f.write(confstr)}
363
363
  RBatch::Log.new({ :name => "test_level" }) do | log |
364
364
  log.debug("test_debug")
365
365
  log.info("test_info")
@@ -379,7 +379,7 @@ class LoggerTest < Test::Unit::TestCase
379
379
 
380
380
  def test_log_level_error_by_conf
381
381
  confstr = "log_level: error"
382
- open( RBatch.common_config_path , "a" ){|f| f.write(confstr)}
382
+ open( RBatch.rbatch_config_path , "a" ){|f| f.write(confstr)}
383
383
  RBatch::Log.new({ :name => "test_level" }) do | log |
384
384
  log.debug("test_debug")
385
385
  log.info("test_info")
@@ -399,7 +399,7 @@ class LoggerTest < Test::Unit::TestCase
399
399
 
400
400
  def test_log_level_fatal_by_conf
401
401
  confstr = "log_level: fatal"
402
- open( RBatch.common_config_path , "a" ){|f| f.write(confstr)}
402
+ open( RBatch.rbatch_config_path , "a" ){|f| f.write(confstr)}
403
403
  RBatch::Log.new({ :name => "test_level" }) do | log |
404
404
  log.debug("test_debug")
405
405
  log.info("test_info")
@@ -509,7 +509,7 @@ class LoggerTest < Test::Unit::TestCase
509
509
 
510
510
  def test_i_log_level_debug_by_conf
511
511
  confstr = "log_level: debug"
512
- open( RBatch.common_config_path , "a" ){|f| f.write(confstr)}
512
+ open( RBatch.rbatch_config_path , "a" ){|f| f.write(confstr)}
513
513
 
514
514
  log = RBatch::Log.new({ :name => "test_level" })
515
515
  log.debug("test_debug")
@@ -544,7 +544,7 @@ class LoggerTest < Test::Unit::TestCase
544
544
  end
545
545
  def test_delete_old_log_by_config
546
546
  confstr = "log_delete_old_log: true"
547
- open( RBatch.common_config_path , "a" ){|f| f.write(confstr)}
547
+ open( RBatch.rbatch_config_path , "a" ){|f| f.write(confstr)}
548
548
 
549
549
  loglist = [*0..20].map do |day|
550
550
  File.join(@dir , (Date.today - day).strftime("%Y%m%d") + "_test_delete.log")
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: rbatch
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 1.11.0
5
+ version: 1.12.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: 2013-02-23 00:00:00 Z
13
+ date: 2013-11-18 00:00:00 Z
14
14
  dependencies: []
15
15
 
16
16
  description: Ruby-based simple batch framework
@@ -27,7 +27,7 @@ files:
27
27
  - CHANGELOG
28
28
  - Gemfile
29
29
  - HOW_TO_TEST.md
30
- - LICENSE
30
+ - LICENSE.txt
31
31
  - README.ja.md
32
32
  - README.md
33
33
  - Rakefile
@@ -75,6 +75,7 @@ files:
75
75
  - doc/rdoc/rdoc.css
76
76
  - lib/rbatch.rb
77
77
  - lib/rbatch/cmd.rb
78
+ - lib/rbatch/common_config.rb
78
79
  - lib/rbatch/config.rb
79
80
  - lib/rbatch/log.rb
80
81
  - lib/rbatch/version.rb
@@ -104,6 +105,7 @@ files:
104
105
  - sample/data/amAuthentication.error.2012-07-10
105
106
  - sample/log/empty
106
107
  - test/cases/test_cmd.rb
108
+ - test/cases/test_common_config.rb
107
109
  - test/cases/test_config.rb
108
110
  - test/cases/test_log.rb
109
111
  - test/mocks/PrintArgs.exe
@@ -137,6 +139,7 @@ specification_version: 3
137
139
  summary: Ruby-based simple batch framework
138
140
  test_files:
139
141
  - test/cases/test_cmd.rb
142
+ - test/cases/test_common_config.rb
140
143
  - test/cases/test_config.rb
141
144
  - test/cases/test_log.rb
142
145
  - test/mocks/PrintArgs.exe
data/LICENSE DELETED
File without changes