takuhai 0.0.1
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.
- data/.gitignore +17 -0
- data/.rspec +2 -0
- data/Gemfile +6 -0
- data/LICENSE.txt +22 -0
- data/README.md +195 -0
- data/Rakefile +1 -0
- data/bin/takuhai +30 -0
- data/lib/takuhai/version.rb +3 -0
- data/lib/takuhai_core.rb +112 -0
- data/lib/takuhai_dsl.rb +125 -0
- data/sample/Takuhaifile +14 -0
- data/sample/masked_files20131129211239.txt +9 -0
- data/sample/masked_files20131129211239/file1.txt +3 -0
- data/sample/masked_files20131129211239/file2.txt +3 -0
- data/sample/masked_files20131129211239/file3.txt +3 -0
- data/spec/spec_helper.rb +9 -0
- data/spec/takuhai_core_spec.rb +44 -0
- data/spec/takuhai_dsl_spec.rb +388 -0
- data/takuhai.gemspec +27 -0
- metadata +125 -0
data/.gitignore
ADDED
data/.rspec
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 tbpgr
|
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.md
ADDED
@@ -0,0 +1,195 @@
|
|
1
|
+
# Takuhai
|
2
|
+
|
3
|
+
Takuhai downloads files from remote server by ssh/scp command.
|
4
|
+
|
5
|
+
After download, you can add any logic for each line.
|
6
|
+
|
7
|
+
※Takuhai means deliver.
|
8
|
+
|
9
|
+
## When Use This Gem?
|
10
|
+
|
11
|
+
* You want to download files and any edit or check in regularly. It's boiler template work!
|
12
|
+
|
13
|
+
## Precondition
|
14
|
+
|
15
|
+
* Public key authentication settings must be done.
|
16
|
+
|
17
|
+
## Installation
|
18
|
+
|
19
|
+
Add this line to your application's Gemfile:
|
20
|
+
|
21
|
+
gem 'takuhai'
|
22
|
+
|
23
|
+
And then execute:
|
24
|
+
|
25
|
+
$ bundle
|
26
|
+
|
27
|
+
Or install it yourself as:
|
28
|
+
|
29
|
+
$ gem install takuhai
|
30
|
+
|
31
|
+
## Usage
|
32
|
+
|
33
|
+
Fist, generate Takuhaifile template.
|
34
|
+
|
35
|
+
$ takuhai init
|
36
|
+
|
37
|
+
Second, edit your Takuhaifile file.
|
38
|
+
|
39
|
+
Third, execute. You get converted file from remote.
|
40
|
+
|
41
|
+
$ takuhai
|
42
|
+
|
43
|
+
or
|
44
|
+
|
45
|
+
$ takuhai collect
|
46
|
+
|
47
|
+
You can confirm help
|
48
|
+
|
49
|
+
$ takuhai help
|
50
|
+
$ takuhai h
|
51
|
+
|
52
|
+
You can confirm version
|
53
|
+
|
54
|
+
$ takuhai version
|
55
|
+
$ takuhai v
|
56
|
+
|
57
|
+
## Takuhaifile
|
58
|
+
|
59
|
+
This file defines download ,convert and output spec.
|
60
|
+
|
61
|
+
Template have following contents.
|
62
|
+
|
63
|
+
You can start to edit from this template.
|
64
|
+
|
65
|
+
But if you want to write DSL-text from new file, you can.
|
66
|
+
|
67
|
+
You can confirm dsl syntax from this template file's comments.
|
68
|
+
|
69
|
+
# encoding: utf-8
|
70
|
+
|
71
|
+
# write your ssh login user name. this attribute is required.
|
72
|
+
# ex:user "app"
|
73
|
+
user "TODO: user"
|
74
|
+
|
75
|
+
# write your ssh login server name or server ip. this attribute is required.
|
76
|
+
# ex1:server "some_server"
|
77
|
+
# ex2:user "192.168.10.11"
|
78
|
+
server "TODO: server"
|
79
|
+
|
80
|
+
# write your targets. this attribute is required.
|
81
|
+
# ex1:targets "app.log-2011-10-*"
|
82
|
+
# ex2:targets "app.log-2011-10-01 app.log-2011-10-02 app.log-2011-10-05"
|
83
|
+
targets "TODO: targets"
|
84
|
+
|
85
|
+
# write your log directory. this attribute is required.
|
86
|
+
# ex:target_dir "/home/app/some_system/log/production"
|
87
|
+
target_dir "TODO: target_dir"
|
88
|
+
|
89
|
+
# write your output_base_name. this value is using in tarball file name and output file name. this attribute is required.
|
90
|
+
# ex:output_base_name "server_log"
|
91
|
+
output_base_name "output"
|
92
|
+
|
93
|
+
# write output file's extension. this attribute is required.
|
94
|
+
# ex:output_extension "tsv"
|
95
|
+
output_extension "txt"
|
96
|
+
|
97
|
+
# if you want to execute some logic for line data, edit following code.
|
98
|
+
# ex: if line have "ERROR", append !!ERROR!! to line String.
|
99
|
+
# block do |file, line|
|
100
|
+
# line = "!!ERROR!!" + line if line.include?("ERROR")
|
101
|
+
# line
|
102
|
+
# end
|
103
|
+
block do |file, line|
|
104
|
+
line
|
105
|
+
end
|
106
|
+
|
107
|
+
## Sample Usage
|
108
|
+
### Spec
|
109
|
+
* You get files[file1.txt, file2.txt, file3.txt] from remote server.
|
110
|
+
* file1.txt's contents is following.
|
111
|
+
~~~
|
112
|
+
[user = test1]
|
113
|
+
[operation = search]
|
114
|
+
[password = test1pass]
|
115
|
+
~~~
|
116
|
+
|
117
|
+
* file2.txt's contents is following.
|
118
|
+
~~~
|
119
|
+
[user = test2]
|
120
|
+
[operation = search]
|
121
|
+
[password = test2pass]
|
122
|
+
~~~
|
123
|
+
|
124
|
+
* file3.txt's contents is following.
|
125
|
+
~~~
|
126
|
+
[user = test3]
|
127
|
+
[operation = search]
|
128
|
+
[password = test3pass]
|
129
|
+
~~~
|
130
|
+
|
131
|
+
* If file contain [password = some_password], you mask password.
|
132
|
+
* Before execute takuahi, public key authentication settings must be done.
|
133
|
+
* Remote user is app
|
134
|
+
* Remote server is 192.168.11.11
|
135
|
+
* Target directory is /home/app/some_product/log
|
136
|
+
* Output directory is ./masked_files
|
137
|
+
* Output base name is masked_files
|
138
|
+
* Output extension is txt
|
139
|
+
|
140
|
+
### Steps
|
141
|
+
Create Template
|
142
|
+
|
143
|
+
$ takuhai init
|
144
|
+
|
145
|
+
Edit Takuhaifile
|
146
|
+
|
147
|
+
# encoding: utf-8
|
148
|
+
user "app"
|
149
|
+
server "192.168.11.11"
|
150
|
+
targets "file*txt"
|
151
|
+
# targets "file1.txt file2.txt file3.txt"
|
152
|
+
target_dir "/home/app/some_product/log"
|
153
|
+
output_base_name "masked_files"
|
154
|
+
output_extension "txt"
|
155
|
+
block do |file, line|
|
156
|
+
if line.match /\[password = (.*)\]/
|
157
|
+
line.gsub!($1, '*'*$1.size)
|
158
|
+
end
|
159
|
+
line
|
160
|
+
end
|
161
|
+
|
162
|
+
output file tree is ...
|
163
|
+
|
164
|
+
│ Takuhaifile
|
165
|
+
│ masked_files20131129222450.txt
|
166
|
+
│
|
167
|
+
└─masked_files20131129222450
|
168
|
+
file1.txt
|
169
|
+
file2.txt
|
170
|
+
file3.txt
|
171
|
+
masked_files.20131129222450.tar.gz
|
172
|
+
|
173
|
+
masked_files20131129222450.txt contents is ...
|
174
|
+
|
175
|
+
[user = test1]
|
176
|
+
[operation = search]
|
177
|
+
[password = *********]
|
178
|
+
[user = test2]
|
179
|
+
[operation = search]
|
180
|
+
[password = *********]
|
181
|
+
[user = test3]
|
182
|
+
[operation = search]
|
183
|
+
[password = *********]
|
184
|
+
|
185
|
+
## Constraint
|
186
|
+
|
187
|
+
* This tool have not good performance. So if target file size is huge, you must not use this gem.
|
188
|
+
|
189
|
+
## Contributing
|
190
|
+
|
191
|
+
1. Fork it
|
192
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
193
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
194
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
195
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
data/bin/takuhai
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
require 'takuhai/version'
|
3
|
+
require 'takuhai_core'
|
4
|
+
require "thor"
|
5
|
+
|
6
|
+
module Takuhai
|
7
|
+
#= Takuhai CLI
|
8
|
+
class CLI < Thor
|
9
|
+
class_option :help, :type => :boolean, :aliases => '-h', :desc => 'help message.'
|
10
|
+
class_option :version, :type => :boolean, :desc => 'version'
|
11
|
+
default_task :collect
|
12
|
+
|
13
|
+
desc "collect", "downloads files from remote server by ssh/scp command"
|
14
|
+
def collect
|
15
|
+
Takuhai::Core.new.collect
|
16
|
+
end
|
17
|
+
|
18
|
+
desc "init", "generate Takuhaifile"
|
19
|
+
def init
|
20
|
+
Takuhai::Core.new.init
|
21
|
+
end
|
22
|
+
|
23
|
+
desc "version", "version"
|
24
|
+
def version
|
25
|
+
p Takuhai::VERSION
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
Takuhai::CLI.start(ARGV)
|
data/lib/takuhai_core.rb
ADDED
@@ -0,0 +1,112 @@
|
|
1
|
+
require "takuhai/version"
|
2
|
+
require "takuhai_dsl"
|
3
|
+
require "date"
|
4
|
+
|
5
|
+
module Takuhai
|
6
|
+
class Core
|
7
|
+
TAKUHAI_FILE = "Takuhaifile"
|
8
|
+
|
9
|
+
TAKUHAI_TEMPLATE =<<-EOS
|
10
|
+
# encoding: utf-8
|
11
|
+
|
12
|
+
# write your ssh login user name. this attribute is required.
|
13
|
+
# ex:user "app"
|
14
|
+
user "TODO: user"
|
15
|
+
|
16
|
+
# write your ssh login server_name name or ip. this attribute is required.
|
17
|
+
# ex1:server "some_server"
|
18
|
+
# ex2:user "192.168.10.11"
|
19
|
+
server "TODO: server"
|
20
|
+
|
21
|
+
# write your targets. this attribute is required.
|
22
|
+
# ex1:targets "app.log-2011-10-*"
|
23
|
+
# ex2:targets "app.log-2011-10-01 app.log-2011-10-02 app.log-2011-10-05"
|
24
|
+
targets "TODO: targets"
|
25
|
+
|
26
|
+
# write your log directory. this attribute is required.
|
27
|
+
# ex:target_dir "/home/app/some_system/log/production"
|
28
|
+
target_dir "TODO: target_dir"
|
29
|
+
|
30
|
+
# write your output_base_name.this value is using in tarball file name and output file name. this attribute is required.
|
31
|
+
# ex:output_base_name "server_log"
|
32
|
+
output_base_name "output"
|
33
|
+
|
34
|
+
# write output file's extension.this attribute is required.
|
35
|
+
# ex:output_extension "tsv"
|
36
|
+
output_extension "txt"
|
37
|
+
|
38
|
+
# if you want to execute some logic for line data, edit following code. this attribute is option.
|
39
|
+
# ex: if line have "ERROR", append !!ERROR!! to line String.
|
40
|
+
# block do |file, line|
|
41
|
+
# line = "!!ERROR!!" + line if line.include?("ERROR")
|
42
|
+
# line
|
43
|
+
# end
|
44
|
+
block do |file, line|
|
45
|
+
line
|
46
|
+
end
|
47
|
+
EOS
|
48
|
+
|
49
|
+
def init
|
50
|
+
File.open(TAKUHAI_FILE, "w") {|f|f.puts TAKUHAI_TEMPLATE}
|
51
|
+
end
|
52
|
+
|
53
|
+
def collect
|
54
|
+
src = read_collect_define
|
55
|
+
@dsl = Takuhai::Dsl.new
|
56
|
+
@dsl.instance_eval src
|
57
|
+
|
58
|
+
@outtime = DateTime.now.strftime("%Y%m%d%H%M%S")
|
59
|
+
@target_dir_name = "#{@dsl._output_base_name}#{@outtime}"
|
60
|
+
@tar_gz_name = "#{@dsl._output_base_name}.#{@outtime}.tar.gz"
|
61
|
+
|
62
|
+
tar_compress_log
|
63
|
+
down_load_tar
|
64
|
+
create_target_dir
|
65
|
+
move_tar
|
66
|
+
move_to_target_dir
|
67
|
+
extract_tar
|
68
|
+
read_line_and_execute_defined_login
|
69
|
+
end
|
70
|
+
|
71
|
+
private
|
72
|
+
def read_collect_define
|
73
|
+
File.open(TAKUHAI_FILE) {|f|f.read}
|
74
|
+
end
|
75
|
+
|
76
|
+
def tar_compress_log
|
77
|
+
`ssh #{@dsl._user}@#{@dsl._server} 'cd #{@dsl._target_dir};tar czvf #{@tar_gz_name} #{@dsl._targets}'`
|
78
|
+
end
|
79
|
+
|
80
|
+
def down_load_tar
|
81
|
+
`scp #{@dsl._user}@#{@dsl._server}:#{@dsl._target_dir}/#{@tar_gz_name} .`
|
82
|
+
end
|
83
|
+
|
84
|
+
def create_target_dir
|
85
|
+
Dir.mkdir(@target_dir_name) unless File.exists? @target_dir_name
|
86
|
+
end
|
87
|
+
|
88
|
+
def move_tar
|
89
|
+
`mv #{@tar_gz_name} ./#{@target_dir_name}`
|
90
|
+
end
|
91
|
+
|
92
|
+
def move_to_target_dir
|
93
|
+
Dir.chdir("./#{@target_dir_name}")
|
94
|
+
end
|
95
|
+
|
96
|
+
def extract_tar
|
97
|
+
`tar xvfz #{@tar_gz_name}`
|
98
|
+
end
|
99
|
+
|
100
|
+
def read_line_and_execute_defined_login
|
101
|
+
total_rets = []
|
102
|
+
targets = @dsl._targets.split(" ")
|
103
|
+
targets.each do |target|
|
104
|
+
Dir.glob("./#{target}") do |f|
|
105
|
+
lines = File.open(f) {|f|f.read}
|
106
|
+
lines.each_line {|line|total_rets << @dsl._block.call(f, line)}
|
107
|
+
end
|
108
|
+
File.open("../#{@target_dir_name}.#{@dsl._output_extension}", "w") {|f| f.puts total_rets.join}
|
109
|
+
end
|
110
|
+
end
|
111
|
+
end
|
112
|
+
end
|
data/lib/takuhai_dsl.rb
ADDED
@@ -0,0 +1,125 @@
|
|
1
|
+
require "takuhai/version"
|
2
|
+
|
3
|
+
module Takuhai
|
4
|
+
# Takuhai DSL
|
5
|
+
class Dsl
|
6
|
+
#== target server's ssh login user
|
7
|
+
attr_accessor :_user
|
8
|
+
#== target server name or ip
|
9
|
+
attr_accessor :_server
|
10
|
+
#== target files
|
11
|
+
attr_accessor :_targets
|
12
|
+
#== target directory
|
13
|
+
attr_accessor :_target_dir
|
14
|
+
#== output filename_base
|
15
|
+
attr_accessor :_output_base_name
|
16
|
+
#== output extension
|
17
|
+
attr_accessor :_output_extension
|
18
|
+
#== each line execute logic
|
19
|
+
attr_accessor :_block
|
20
|
+
|
21
|
+
#== set user
|
22
|
+
#- not allow nil
|
23
|
+
#- not allow empty
|
24
|
+
#=== params
|
25
|
+
#- _user: ssh login user
|
26
|
+
def user(_user)
|
27
|
+
raise InvalidUserError.new("#{InvalidUserError::INVALID_MESSAGE} nil") if _user.nil?
|
28
|
+
raise InvalidUserError.new("#{InvalidUserError::INVALID_MESSAGE} empty") if _user.empty?
|
29
|
+
@_user = _user
|
30
|
+
end
|
31
|
+
|
32
|
+
#== set server
|
33
|
+
#- not allow nil
|
34
|
+
#- not allow empty
|
35
|
+
#=== params
|
36
|
+
#- _server: target server name or ip
|
37
|
+
def server(_server)
|
38
|
+
raise InvalidServerError.new("#{InvalidServerError::INVALID_MESSAGE} nil") if _server.nil?
|
39
|
+
raise InvalidServerError.new("#{InvalidServerError::INVALID_MESSAGE} empty") if _server.empty?
|
40
|
+
@_server = _server
|
41
|
+
end
|
42
|
+
|
43
|
+
#== set targets
|
44
|
+
#- not allow nil
|
45
|
+
#- not allow empty
|
46
|
+
#=== params
|
47
|
+
#- _targets: targets files
|
48
|
+
def targets(_targets)
|
49
|
+
raise InvalidTargetsError.new("#{InvalidTargetsError::INVALID_MESSAGE} nil") if _targets.nil?
|
50
|
+
raise InvalidTargetsError.new("#{InvalidTargetsError::INVALID_MESSAGE} empty") if _targets.empty?
|
51
|
+
@_targets = _targets
|
52
|
+
end
|
53
|
+
|
54
|
+
#== set target_dir
|
55
|
+
#- not allow nil
|
56
|
+
#- not allow empty
|
57
|
+
#=== params
|
58
|
+
#- _target_dir: target directory
|
59
|
+
def target_dir(_target_dir)
|
60
|
+
raise InvalidTargetDirError.new("#{InvalidTargetDirError::INVALID_MESSAGE} nil") if _target_dir.nil?
|
61
|
+
raise InvalidTargetDirError.new("#{InvalidTargetDirError::INVALID_MESSAGE} empty") if _target_dir.empty?
|
62
|
+
@_target_dir = _target_dir
|
63
|
+
end
|
64
|
+
|
65
|
+
#== set output_base_name
|
66
|
+
#- not allow nil
|
67
|
+
#- not allow empty
|
68
|
+
#=== params
|
69
|
+
#- _output_base_name: output base-name
|
70
|
+
def output_base_name(_output_base_name)
|
71
|
+
raise InvalidOutputBaseNameError.new("#{InvalidOutputBaseNameError::INVALID_MESSAGE} nil") if _output_base_name.nil?
|
72
|
+
raise InvalidOutputBaseNameError.new("#{InvalidOutputBaseNameError::INVALID_MESSAGE} empty") if _output_base_name.empty?
|
73
|
+
@_output_base_name = _output_base_name
|
74
|
+
end
|
75
|
+
|
76
|
+
#== set output_extension
|
77
|
+
#- not allow nil
|
78
|
+
#- not allow empty
|
79
|
+
#=== params
|
80
|
+
#- _output_extension: output extension
|
81
|
+
def output_extension(_output_extension)
|
82
|
+
raise InvalidOutputExtensionError.new("#{InvalidOutputExtensionError::INVALID_MESSAGE} nil") if _output_extension.nil?
|
83
|
+
raise InvalidOutputExtensionError.new("#{InvalidOutputExtensionError::INVALID_MESSAGE} empty") if _output_extension.empty?
|
84
|
+
@_output_extension = _output_extension
|
85
|
+
end
|
86
|
+
|
87
|
+
#== set block
|
88
|
+
#=== params
|
89
|
+
#- _block: block(each line execute logic)
|
90
|
+
def block(&_block)
|
91
|
+
@_block = _block
|
92
|
+
end
|
93
|
+
|
94
|
+
end
|
95
|
+
|
96
|
+
#= User Setting Error
|
97
|
+
class InvalidUserError < StandardError
|
98
|
+
INVALID_MESSAGE = "user not allow "
|
99
|
+
end
|
100
|
+
|
101
|
+
#= Server Setting Error
|
102
|
+
class InvalidServerError < StandardError
|
103
|
+
INVALID_MESSAGE = "server not allow "
|
104
|
+
end
|
105
|
+
|
106
|
+
#= Targets Setting Error
|
107
|
+
class InvalidTargetsError < StandardError
|
108
|
+
INVALID_MESSAGE = "targets not allow "
|
109
|
+
end
|
110
|
+
|
111
|
+
#= Target Directory Setting Error
|
112
|
+
class InvalidTargetDirError < StandardError
|
113
|
+
INVALID_MESSAGE = "target directory not allow "
|
114
|
+
end
|
115
|
+
|
116
|
+
#= OutputBaseName Setting Error
|
117
|
+
class InvalidOutputBaseNameError < StandardError
|
118
|
+
INVALID_MESSAGE = "output base name not allow "
|
119
|
+
end
|
120
|
+
|
121
|
+
#= OutputExtension Setting Error
|
122
|
+
class InvalidOutputExtensionError < StandardError
|
123
|
+
INVALID_MESSAGE = "output extension not allow "
|
124
|
+
end
|
125
|
+
end
|
data/sample/Takuhaifile
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
user "app"
|
3
|
+
server "192.168.11.11"
|
4
|
+
targets "file*txt"
|
5
|
+
# targets "file1.txt file2.txt file3.txt"
|
6
|
+
target_dir "/home/app/some_product/log"
|
7
|
+
output_base_name "masked_files"
|
8
|
+
output_extension "txt"
|
9
|
+
block do |file, line|
|
10
|
+
if line.match /\[password = (.*)\]/
|
11
|
+
line.gsub!($1, '*'*$1.size)
|
12
|
+
end
|
13
|
+
line
|
14
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,44 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require "spec_helper"
|
3
|
+
require "takuhai_core"
|
4
|
+
|
5
|
+
describe Takuhai::Core do
|
6
|
+
context :init do
|
7
|
+
cases = [
|
8
|
+
{
|
9
|
+
case_no: 1,
|
10
|
+
case_title: "output template",
|
11
|
+
expected: Takuhai::Core::TAKUHAI_TEMPLATE
|
12
|
+
},
|
13
|
+
]
|
14
|
+
|
15
|
+
cases.each do |c|
|
16
|
+
it "|case_no=#{c[:case_no]}|case_title=#{c[:case_title]}" do
|
17
|
+
begin
|
18
|
+
case_before c
|
19
|
+
|
20
|
+
# -- given --
|
21
|
+
takuhai = Takuhai::Core.new
|
22
|
+
|
23
|
+
# -- when --
|
24
|
+
takuhai.init
|
25
|
+
|
26
|
+
# -- then --
|
27
|
+
actual = File.open(Takuhai::Core::TAKUHAI_FILE) {|f|f.read}
|
28
|
+
expect(actual).to eq(c[:expected])
|
29
|
+
ensure
|
30
|
+
case_after c
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
def case_before(c)
|
35
|
+
# implement each case before
|
36
|
+
end
|
37
|
+
|
38
|
+
def case_after(c)
|
39
|
+
return unless File.exists? Takuhai::Core::TAKUHAI_FILE
|
40
|
+
File.delete(Takuhai::Core::TAKUHAI_FILE)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
@@ -0,0 +1,388 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require "spec_helper"
|
3
|
+
require "takuhai_dsl"
|
4
|
+
|
5
|
+
describe Takuhai::Dsl do
|
6
|
+
context :user do
|
7
|
+
cases = [
|
8
|
+
{
|
9
|
+
case_no: 1,
|
10
|
+
case_title: "set valid user",
|
11
|
+
user: "app",
|
12
|
+
expected: "app"
|
13
|
+
},
|
14
|
+
{
|
15
|
+
case_no: 2,
|
16
|
+
case_title: "set nil",
|
17
|
+
user: nil,
|
18
|
+
invalid: true
|
19
|
+
},
|
20
|
+
{
|
21
|
+
case_no: 3,
|
22
|
+
case_title: "set empty",
|
23
|
+
user: "",
|
24
|
+
invalid: true
|
25
|
+
},
|
26
|
+
]
|
27
|
+
|
28
|
+
cases.each do |c|
|
29
|
+
it "|case_no=#{c[:case_no]}|case_title=#{c[:case_title]}" do
|
30
|
+
begin
|
31
|
+
case_before c
|
32
|
+
|
33
|
+
# -- given --
|
34
|
+
takuhai = Takuhai::Dsl.new
|
35
|
+
|
36
|
+
# -- when --
|
37
|
+
if c[:invalid]
|
38
|
+
lambda {takuhai.user(c[:user])}.should raise_error(Takuhai::InvalidUserError)
|
39
|
+
else
|
40
|
+
takuhai.user c[:user]
|
41
|
+
actual = takuhai._user
|
42
|
+
end
|
43
|
+
|
44
|
+
# -- then --
|
45
|
+
expect(actual).to eq(c[:expected])
|
46
|
+
ensure
|
47
|
+
case_after c
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
def case_before(c)
|
52
|
+
# implement each case before
|
53
|
+
end
|
54
|
+
|
55
|
+
def case_after(c)
|
56
|
+
# implement each case after
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
context :server do
|
62
|
+
cases = [
|
63
|
+
{
|
64
|
+
case_no: 1,
|
65
|
+
case_title: "set valid server",
|
66
|
+
server: "some_server",
|
67
|
+
expected: "some_server"
|
68
|
+
},
|
69
|
+
{
|
70
|
+
case_no: 2,
|
71
|
+
case_title: "set nil",
|
72
|
+
server: nil,
|
73
|
+
invalid: true
|
74
|
+
},
|
75
|
+
{
|
76
|
+
case_no: 3,
|
77
|
+
case_title: "set empty",
|
78
|
+
server: "",
|
79
|
+
invalid: true
|
80
|
+
},
|
81
|
+
]
|
82
|
+
|
83
|
+
cases.each do |c|
|
84
|
+
it "|case_no=#{c[:case_no]}|case_title=#{c[:case_title]}" do
|
85
|
+
begin
|
86
|
+
case_before c
|
87
|
+
|
88
|
+
# -- given --
|
89
|
+
takuhai = Takuhai::Dsl.new
|
90
|
+
|
91
|
+
# -- when --
|
92
|
+
if c[:invalid]
|
93
|
+
lambda {takuhai.server(c[:server])}.should raise_error(Takuhai::InvalidServerError)
|
94
|
+
else
|
95
|
+
takuhai.server c[:server]
|
96
|
+
actual = takuhai._server
|
97
|
+
end
|
98
|
+
|
99
|
+
# -- then --
|
100
|
+
expect(actual).to eq(c[:expected])
|
101
|
+
ensure
|
102
|
+
case_after c
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
106
|
+
def case_before(c)
|
107
|
+
# implement each case before
|
108
|
+
end
|
109
|
+
|
110
|
+
def case_after(c)
|
111
|
+
# implement each case after
|
112
|
+
end
|
113
|
+
end
|
114
|
+
end
|
115
|
+
|
116
|
+
context :targets do
|
117
|
+
cases = [
|
118
|
+
{
|
119
|
+
case_no: 1,
|
120
|
+
case_title: "set valid targets",
|
121
|
+
targets: "some_targets",
|
122
|
+
expected: "some_targets"
|
123
|
+
},
|
124
|
+
{
|
125
|
+
case_no: 2,
|
126
|
+
case_title: "set nil",
|
127
|
+
targets: nil,
|
128
|
+
invalid: true
|
129
|
+
},
|
130
|
+
{
|
131
|
+
case_no: 3,
|
132
|
+
case_title: "set empty",
|
133
|
+
targets: "",
|
134
|
+
invalid: true
|
135
|
+
},
|
136
|
+
]
|
137
|
+
|
138
|
+
cases.each do |c|
|
139
|
+
it "|case_no=#{c[:case_no]}|case_title=#{c[:case_title]}" do
|
140
|
+
begin
|
141
|
+
case_before c
|
142
|
+
|
143
|
+
# -- given --
|
144
|
+
takuhai = Takuhai::Dsl.new
|
145
|
+
|
146
|
+
# -- when --
|
147
|
+
if c[:invalid]
|
148
|
+
lambda {takuhai.targets(c[:targets])}.should raise_error(Takuhai::InvalidTargetsError)
|
149
|
+
else
|
150
|
+
takuhai.targets c[:targets]
|
151
|
+
actual = takuhai._targets
|
152
|
+
end
|
153
|
+
|
154
|
+
# -- then --
|
155
|
+
expect(actual).to eq(c[:expected])
|
156
|
+
ensure
|
157
|
+
case_after c
|
158
|
+
end
|
159
|
+
end
|
160
|
+
|
161
|
+
def case_before(c)
|
162
|
+
# implement each case before
|
163
|
+
end
|
164
|
+
|
165
|
+
def case_after(c)
|
166
|
+
# implement each case after
|
167
|
+
end
|
168
|
+
end
|
169
|
+
end
|
170
|
+
|
171
|
+
context :target_dir do
|
172
|
+
cases = [
|
173
|
+
{
|
174
|
+
case_no: 1,
|
175
|
+
case_title: "set valid target_dir",
|
176
|
+
target_dir: "/home/some_user/tmp",
|
177
|
+
expected: "/home/some_user/tmp"
|
178
|
+
},
|
179
|
+
{
|
180
|
+
case_no: 2,
|
181
|
+
case_title: "set nil",
|
182
|
+
target_dir: nil,
|
183
|
+
invalid: true
|
184
|
+
},
|
185
|
+
{
|
186
|
+
case_no: 3,
|
187
|
+
case_title: "set empty",
|
188
|
+
target_dir: "",
|
189
|
+
invalid: true
|
190
|
+
},
|
191
|
+
]
|
192
|
+
|
193
|
+
cases.each do |c|
|
194
|
+
it "|case_no=#{c[:case_no]}|case_title=#{c[:case_title]}" do
|
195
|
+
begin
|
196
|
+
case_before c
|
197
|
+
|
198
|
+
# -- given --
|
199
|
+
takuhai = Takuhai::Dsl.new
|
200
|
+
|
201
|
+
# -- when --
|
202
|
+
if c[:invalid]
|
203
|
+
lambda {takuhai.target_dir(c[:target_dir])}.should raise_error(Takuhai::InvalidTargetDirError)
|
204
|
+
else
|
205
|
+
takuhai.target_dir c[:target_dir]
|
206
|
+
actual = takuhai._target_dir
|
207
|
+
end
|
208
|
+
|
209
|
+
# -- then --
|
210
|
+
expect(actual).to eq(c[:expected])
|
211
|
+
ensure
|
212
|
+
case_after c
|
213
|
+
end
|
214
|
+
end
|
215
|
+
|
216
|
+
def case_before(c)
|
217
|
+
# implement each case before
|
218
|
+
end
|
219
|
+
|
220
|
+
def case_after(c)
|
221
|
+
# implement each case after
|
222
|
+
end
|
223
|
+
end
|
224
|
+
end
|
225
|
+
|
226
|
+
context :output_base_name do
|
227
|
+
cases = [
|
228
|
+
{
|
229
|
+
case_no: 1,
|
230
|
+
case_title: "set valid output_base_name",
|
231
|
+
output_base_name: "base_name",
|
232
|
+
expected: "base_name"
|
233
|
+
},
|
234
|
+
{
|
235
|
+
case_no: 2,
|
236
|
+
case_title: "set nil",
|
237
|
+
output_base_name: nil,
|
238
|
+
invalid: true
|
239
|
+
},
|
240
|
+
{
|
241
|
+
case_no: 3,
|
242
|
+
case_title: "set empty",
|
243
|
+
output_base_name: "",
|
244
|
+
invalid: true
|
245
|
+
},
|
246
|
+
]
|
247
|
+
|
248
|
+
cases.each do |c|
|
249
|
+
it "|case_no=#{c[:case_no]}|case_title=#{c[:case_title]}" do
|
250
|
+
begin
|
251
|
+
case_before c
|
252
|
+
|
253
|
+
# -- given --
|
254
|
+
takuhai = Takuhai::Dsl.new
|
255
|
+
|
256
|
+
# -- when --
|
257
|
+
if c[:invalid]
|
258
|
+
lambda {takuhai.output_base_name(c[:output_base_name])}.should raise_error(Takuhai::InvalidOutputBaseNameError)
|
259
|
+
else
|
260
|
+
takuhai.output_base_name c[:output_base_name]
|
261
|
+
actual = takuhai._output_base_name
|
262
|
+
end
|
263
|
+
|
264
|
+
# -- then --
|
265
|
+
expect(actual).to eq(c[:expected])
|
266
|
+
ensure
|
267
|
+
case_after c
|
268
|
+
end
|
269
|
+
end
|
270
|
+
|
271
|
+
def case_before(c)
|
272
|
+
# implement each case before
|
273
|
+
end
|
274
|
+
|
275
|
+
def case_after(c)
|
276
|
+
# implement each case after
|
277
|
+
end
|
278
|
+
end
|
279
|
+
end
|
280
|
+
|
281
|
+
context :output_extension do
|
282
|
+
cases = [
|
283
|
+
{
|
284
|
+
case_no: 1,
|
285
|
+
case_title: "set valid output_extension",
|
286
|
+
output_extension: "tsv",
|
287
|
+
expected: "tsv"
|
288
|
+
},
|
289
|
+
{
|
290
|
+
case_no: 2,
|
291
|
+
case_title: "set nil",
|
292
|
+
output_extension: nil,
|
293
|
+
invalid: true
|
294
|
+
},
|
295
|
+
{
|
296
|
+
case_no: 3,
|
297
|
+
case_title: "set empty",
|
298
|
+
output_extension: "",
|
299
|
+
invalid: true
|
300
|
+
},
|
301
|
+
]
|
302
|
+
|
303
|
+
cases.each do |c|
|
304
|
+
it "|case_no=#{c[:case_no]}|case_title=#{c[:case_title]}" do
|
305
|
+
begin
|
306
|
+
case_before c
|
307
|
+
|
308
|
+
# -- given --
|
309
|
+
takuhai = Takuhai::Dsl.new
|
310
|
+
|
311
|
+
# -- when --
|
312
|
+
if c[:invalid]
|
313
|
+
lambda {takuhai.output_extension(c[:output_extension])}.should raise_error(Takuhai::InvalidOutputExtensionError)
|
314
|
+
else
|
315
|
+
takuhai.output_extension c[:output_extension]
|
316
|
+
actual = takuhai._output_extension
|
317
|
+
end
|
318
|
+
|
319
|
+
# -- then --
|
320
|
+
expect(actual).to eq(c[:expected])
|
321
|
+
ensure
|
322
|
+
case_after c
|
323
|
+
end
|
324
|
+
end
|
325
|
+
|
326
|
+
def case_before(c)
|
327
|
+
# implement each case before
|
328
|
+
end
|
329
|
+
|
330
|
+
def case_after(c)
|
331
|
+
# implement each case after
|
332
|
+
end
|
333
|
+
end
|
334
|
+
end
|
335
|
+
|
336
|
+
context :block do
|
337
|
+
cases = [
|
338
|
+
{
|
339
|
+
case_no: 1,
|
340
|
+
case_title: "set valid block",
|
341
|
+
block: true,
|
342
|
+
param1: "f",
|
343
|
+
param2: "line",
|
344
|
+
expected: "linetest"
|
345
|
+
},
|
346
|
+
{
|
347
|
+
case_no: 2,
|
348
|
+
case_title: "set nil",
|
349
|
+
block: nil,
|
350
|
+
expected: nil
|
351
|
+
},
|
352
|
+
]
|
353
|
+
|
354
|
+
cases.each do |c|
|
355
|
+
it "|case_no=#{c[:case_no]}|case_title=#{c[:case_title]}" do
|
356
|
+
begin
|
357
|
+
case_before c
|
358
|
+
|
359
|
+
# -- given --
|
360
|
+
takuhai = Takuhai::Dsl.new
|
361
|
+
|
362
|
+
# -- when --
|
363
|
+
if c[:block]
|
364
|
+
takuhai.block {|f, line|line + "test"}
|
365
|
+
actual = takuhai._block.call(c[:param1], c[:param2])
|
366
|
+
else
|
367
|
+
takuhai.block
|
368
|
+
actual = takuhai._block
|
369
|
+
end
|
370
|
+
|
371
|
+
# -- then --
|
372
|
+
expect(actual).to eq(c[:expected])
|
373
|
+
ensure
|
374
|
+
case_after c
|
375
|
+
end
|
376
|
+
end
|
377
|
+
|
378
|
+
def case_before(c)
|
379
|
+
# implement each case before
|
380
|
+
end
|
381
|
+
|
382
|
+
def case_after(c)
|
383
|
+
# implement each case after
|
384
|
+
end
|
385
|
+
end
|
386
|
+
end
|
387
|
+
|
388
|
+
end
|
data/takuhai.gemspec
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'takuhai/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "takuhai"
|
8
|
+
spec.version = Takuhai::VERSION
|
9
|
+
spec.authors = ["tbpgr"]
|
10
|
+
spec.email = ["tbpgr@tbpgr.jp"]
|
11
|
+
spec.description = %q{Takuhai downloads files from remote server by ssh/scp command.}
|
12
|
+
spec.summary = %q{Takuhai downloads files from remote server by ssh/scp command.}
|
13
|
+
spec.homepage = "https://github.com/tbpgr/takuhai"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files`.split($/)
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_runtime_dependency "thor", "~> 0.18.1"
|
22
|
+
|
23
|
+
spec.add_development_dependency "bundler", "~> 1.3"
|
24
|
+
spec.add_development_dependency "rake"
|
25
|
+
spec.add_development_dependency "rspec", "~> 2.14.1"
|
26
|
+
spec.add_development_dependency "simplecov", "~> 0.8.2"
|
27
|
+
end
|
metadata
ADDED
@@ -0,0 +1,125 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: takuhai
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- tbpgr
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2013-11-29 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: thor
|
16
|
+
requirement: &20698824 !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ~>
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: 0.18.1
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: *20698824
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: bundler
|
27
|
+
requirement: &20713632 !ruby/object:Gem::Requirement
|
28
|
+
none: false
|
29
|
+
requirements:
|
30
|
+
- - ~>
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '1.3'
|
33
|
+
type: :development
|
34
|
+
prerelease: false
|
35
|
+
version_requirements: *20713632
|
36
|
+
- !ruby/object:Gem::Dependency
|
37
|
+
name: rake
|
38
|
+
requirement: &20712180 !ruby/object:Gem::Requirement
|
39
|
+
none: false
|
40
|
+
requirements:
|
41
|
+
- - ! '>='
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: '0'
|
44
|
+
type: :development
|
45
|
+
prerelease: false
|
46
|
+
version_requirements: *20712180
|
47
|
+
- !ruby/object:Gem::Dependency
|
48
|
+
name: rspec
|
49
|
+
requirement: &20706552 !ruby/object:Gem::Requirement
|
50
|
+
none: false
|
51
|
+
requirements:
|
52
|
+
- - ~>
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 2.14.1
|
55
|
+
type: :development
|
56
|
+
prerelease: false
|
57
|
+
version_requirements: *20706552
|
58
|
+
- !ruby/object:Gem::Dependency
|
59
|
+
name: simplecov
|
60
|
+
requirement: &20720304 !ruby/object:Gem::Requirement
|
61
|
+
none: false
|
62
|
+
requirements:
|
63
|
+
- - ~>
|
64
|
+
- !ruby/object:Gem::Version
|
65
|
+
version: 0.8.2
|
66
|
+
type: :development
|
67
|
+
prerelease: false
|
68
|
+
version_requirements: *20720304
|
69
|
+
description: Takuhai downloads files from remote server by ssh/scp command.
|
70
|
+
email:
|
71
|
+
- tbpgr@tbpgr.jp
|
72
|
+
executables:
|
73
|
+
- takuhai
|
74
|
+
extensions: []
|
75
|
+
extra_rdoc_files: []
|
76
|
+
files:
|
77
|
+
- .gitignore
|
78
|
+
- .rspec
|
79
|
+
- Gemfile
|
80
|
+
- LICENSE.txt
|
81
|
+
- README.md
|
82
|
+
- Rakefile
|
83
|
+
- bin/takuhai
|
84
|
+
- lib/takuhai/version.rb
|
85
|
+
- lib/takuhai_core.rb
|
86
|
+
- lib/takuhai_dsl.rb
|
87
|
+
- sample/Takuhaifile
|
88
|
+
- sample/masked_files20131129211239.txt
|
89
|
+
- sample/masked_files20131129211239/file1.txt
|
90
|
+
- sample/masked_files20131129211239/file2.txt
|
91
|
+
- sample/masked_files20131129211239/file3.txt
|
92
|
+
- spec/spec_helper.rb
|
93
|
+
- spec/takuhai_core_spec.rb
|
94
|
+
- spec/takuhai_dsl_spec.rb
|
95
|
+
- takuhai.gemspec
|
96
|
+
homepage: https://github.com/tbpgr/takuhai
|
97
|
+
licenses:
|
98
|
+
- MIT
|
99
|
+
post_install_message:
|
100
|
+
rdoc_options: []
|
101
|
+
require_paths:
|
102
|
+
- lib
|
103
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
104
|
+
none: false
|
105
|
+
requirements:
|
106
|
+
- - ! '>='
|
107
|
+
- !ruby/object:Gem::Version
|
108
|
+
version: '0'
|
109
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
110
|
+
none: false
|
111
|
+
requirements:
|
112
|
+
- - ! '>='
|
113
|
+
- !ruby/object:Gem::Version
|
114
|
+
version: '0'
|
115
|
+
requirements: []
|
116
|
+
rubyforge_project:
|
117
|
+
rubygems_version: 1.8.11
|
118
|
+
signing_key:
|
119
|
+
specification_version: 3
|
120
|
+
summary: Takuhai downloads files from remote server by ssh/scp command.
|
121
|
+
test_files:
|
122
|
+
- spec/spec_helper.rb
|
123
|
+
- spec/takuhai_core_spec.rb
|
124
|
+
- spec/takuhai_dsl_spec.rb
|
125
|
+
has_rdoc:
|