script-runner 0.0.2 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +7 -1
- data/README.md +5 -3
- data/lib/script-runner.rb +16 -3
- data/lib/script-runner/main.rb +17 -6
- data/lib/script-runner/version.rb +1 -1
- data/script-runner.gemspec +1 -0
- data/spec/fixtures/nested/one.sh +2 -0
- data/spec/fixtures/non_runnable/scripts/one.sh +2 -0
- data/spec/main_spec.rb +11 -4
- metadata +19 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5adc86a5ade412404f97da960195285a5cd9c9d5
|
4
|
+
data.tar.gz: b4ce5c7742f04412fb7df809b1d6a676547b9d3b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1cffb8d33edaa322fb331e1b91cc73bb2b47cd6fd15e2ccfa6fedad39bfa26d7ac2bf2911e062f0bd69101eb0e9b14e14fbcf0d903fcbf224e5068648bea88b2
|
7
|
+
data.tar.gz: db92f171a17303b7bddb6a679bafbc5f621ea27a677331863c42caddd045a27373f7dc58574f468f4f9559251e1ca54b8036f3be625b522295d37d4c314562a4
|
data/Gemfile.lock
CHANGED
@@ -1,13 +1,18 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
script-runner (0.0.
|
4
|
+
script-runner (0.0.2)
|
5
5
|
thor
|
6
6
|
|
7
7
|
GEM
|
8
8
|
remote: https://rubygems.org/
|
9
9
|
specs:
|
10
10
|
diff-lcs (1.2.4)
|
11
|
+
little-plugger (1.1.3)
|
12
|
+
logging (1.8.1)
|
13
|
+
little-plugger (>= 1.1.3)
|
14
|
+
multi_json (>= 1.3.6)
|
15
|
+
multi_json (1.7.9)
|
11
16
|
rake (10.1.0)
|
12
17
|
rspec (2.14.1)
|
13
18
|
rspec-core (~> 2.14.0)
|
@@ -23,6 +28,7 @@ PLATFORMS
|
|
23
28
|
ruby
|
24
29
|
|
25
30
|
DEPENDENCIES
|
31
|
+
logging (~> 1.8.1)
|
26
32
|
rake (~> 10.1.0)
|
27
33
|
rspec (~> 2.6)
|
28
34
|
script-runner!
|
data/README.md
CHANGED
@@ -6,11 +6,11 @@ A very simple library for running scripts on a file system.
|
|
6
6
|
|
7
7
|
require 'script-runner'
|
8
8
|
ScriptRunner.run( array_of_paths, array_of_env_paths, error_handler, &handle_script_output )
|
9
|
-
|
9
|
+
|
10
10
|
## Example
|
11
11
|
|
12
12
|
If we have the following file structure
|
13
|
-
|
13
|
+
|
14
14
|
|
15
15
|
path-one/
|
16
16
|
script.sh
|
@@ -20,7 +20,7 @@ If we have the following file structure
|
|
20
20
|
script.sh
|
21
21
|
env-one/
|
22
22
|
one.properties
|
23
|
-
|
23
|
+
|
24
24
|
The following:
|
25
25
|
|
26
26
|
require 'script-runner'
|
@@ -46,5 +46,7 @@ Note: for each root_path, all files under are invoked in alphabetical order
|
|
46
46
|
|
47
47
|
|
48
48
|
### Changelog
|
49
|
+
0.0.4 - fixed dependency on logging
|
50
|
+
0.0.3 - Added logging
|
49
51
|
0.0.2 - Added mit license
|
50
52
|
0.0.1 - First version
|
data/lib/script-runner.rb
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
require 'logging'
|
1
2
|
require 'script-runner/main'
|
2
3
|
|
3
4
|
module ScriptRunner
|
@@ -8,10 +9,22 @@ module ScriptRunner
|
|
8
9
|
#
|
9
10
|
# @paths - an array of paths with scripts to invoke
|
10
11
|
# @env_vars - an array of paths that contains .properties files
|
11
|
-
# @
|
12
|
+
# @options -
|
13
|
+
# -- :error_handler - a lambda that gets passed the script file path that exited with a non zero value
|
14
|
+
# -- :log_level - one of :debug, :info, :warn, :errror
|
12
15
|
# @block - a block to handle the output of the script if non is given it is sent to the console
|
13
|
-
def self.run( paths, env_vars,
|
14
|
-
|
16
|
+
def self.run( paths, env_vars, options = {}, &block)
|
17
|
+
|
18
|
+
Logging.appenders.stdout(
|
19
|
+
:layout => Logging.layouts.pattern(:pattern => '[%c][%-5l] %m\n'),
|
20
|
+
:color_scheme => 'bright')
|
21
|
+
|
22
|
+
logger = Logging.logger['script-runner']
|
23
|
+
logger.add_appenders(Logging.appenders.stdout)
|
24
|
+
logger.level = options[:log_level] || :warn
|
25
|
+
|
26
|
+
runner = ScriptRunner::Main.new(logger)
|
27
|
+
error_handler = options[:error_handler]
|
15
28
|
runner.run(paths, env_vars, error_handler, &block)
|
16
29
|
end
|
17
30
|
|
data/lib/script-runner/main.rb
CHANGED
@@ -1,7 +1,14 @@
|
|
1
|
+
require 'logging'
|
2
|
+
|
1
3
|
module ScriptRunner
|
2
4
|
|
3
5
|
class Main
|
4
6
|
|
7
|
+
def initialize(logger)
|
8
|
+
@logger = logger
|
9
|
+
end
|
10
|
+
|
11
|
+
|
5
12
|
# Run a set of scripts
|
6
13
|
#
|
7
14
|
# Note: non executable files are skipped and a warning is sent to the console
|
@@ -11,16 +18,19 @@ module ScriptRunner
|
|
11
18
|
# @error_handler - a callback if a non-zero exit code occured
|
12
19
|
# @block - a block to handle the output of the script if non is given it is sent to the console
|
13
20
|
def run( paths, env_vars, error_handler = nil, &block)
|
21
|
+
|
14
22
|
set_env(env_vars)
|
15
23
|
all_paths = all_files(paths).select{ |p| File.file? p }
|
24
|
+
@logger.debug all_paths
|
16
25
|
runnable = all_paths.select{ |p| File.executable? p }
|
17
26
|
non_runnable = all_paths - runnable
|
18
|
-
|
27
|
+
@logger.debug "non_runnable: #{non_runnable}"
|
28
|
+
@logger.debug "runnable: #{runnable}"
|
19
29
|
non_runnable.each{ |nr|
|
20
|
-
|
30
|
+
@logger.warn "#{nr} is not runnable - skipping"
|
21
31
|
}
|
22
32
|
|
23
|
-
|
33
|
+
runnable.each{ |p|
|
24
34
|
exec(p, error_handler, &block)
|
25
35
|
}
|
26
36
|
end
|
@@ -33,7 +43,7 @@ module ScriptRunner
|
|
33
43
|
if block_given?
|
34
44
|
block.call(line.chomp)
|
35
45
|
else
|
36
|
-
|
46
|
+
@logger.info line.chomp
|
37
47
|
end
|
38
48
|
end
|
39
49
|
io.close
|
@@ -53,8 +63,9 @@ module ScriptRunner
|
|
53
63
|
env_files.each{ |p|
|
54
64
|
File.readlines(p).each do |line|
|
55
65
|
if line.include? "="
|
56
|
-
|
57
|
-
|
66
|
+
key, value = line.split("=")
|
67
|
+
@logger.debug "set: #{key} -> #{value}"
|
68
|
+
ENV[key.strip] = value.strip
|
58
69
|
end
|
59
70
|
end
|
60
71
|
}
|
data/script-runner.gemspec
CHANGED
data/spec/main_spec.rb
CHANGED
@@ -27,19 +27,21 @@ describe ScriptRunner do
|
|
27
27
|
end
|
28
28
|
|
29
29
|
it "should allow errors to be handled" do
|
30
|
-
|
31
|
-
|
30
|
+
options = {
|
31
|
+
:error_handler => lambda{ |p| @error_files << p},
|
32
|
+
:log_level => :debug
|
33
|
+
}
|
34
|
+
|
35
|
+
p = ScriptRunner.run(scripts("one", "has_error"), env("one"), options) { |output| @all_output << output }
|
32
36
|
@error_files.length.should eql 1
|
33
37
|
end
|
34
38
|
|
35
39
|
it "should call nested in alphabetical order" do
|
36
|
-
puts "before : #{@all_output}"
|
37
40
|
p = ScriptRunner.run(scripts("nested"), env("one")) { |output| @all_output << output }
|
38
41
|
@all_output.should eql ["spec/fixtures/nested/scripts/a/one.sh", "spec/fixtures/nested/scripts/one.sh"]
|
39
42
|
end
|
40
43
|
|
41
44
|
it "should call multiple nested in alphabetical order" do
|
42
|
-
puts "before : #{@all_output}"
|
43
45
|
p = ScriptRunner.run(scripts("one", "nested_two", "nested"), env("one")) { |output| @all_output << output }
|
44
46
|
@all_output.should eql [
|
45
47
|
"hello there custom var",
|
@@ -48,4 +50,9 @@ describe ScriptRunner do
|
|
48
50
|
"spec/fixtures/nested/scripts/a/one.sh",
|
49
51
|
"spec/fixtures/nested/scripts/one.sh"]
|
50
52
|
end
|
53
|
+
|
54
|
+
it "should skip non runnable files" do
|
55
|
+
p = ScriptRunner.run(scripts("non_runnable"), env("one")) { |output| @all_output << output }
|
56
|
+
@error_files.length.should eql 0
|
57
|
+
end
|
51
58
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: script-runner
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- ed.eustace
|
@@ -38,6 +38,20 @@ dependencies:
|
|
38
38
|
- - ~>
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: 10.1.0
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: logging
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ~>
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: 1.8.1
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ~>
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 1.8.1
|
41
55
|
- !ruby/object:Gem::Dependency
|
42
56
|
name: thor
|
43
57
|
requirement: !ruby/object:Gem::Requirement
|
@@ -73,12 +87,14 @@ files:
|
|
73
87
|
- script-runner.gemspec
|
74
88
|
- spec/cmds_spec.rb
|
75
89
|
- spec/fixtures/has_error/scripts/error.sh
|
90
|
+
- spec/fixtures/nested/one.sh
|
76
91
|
- spec/fixtures/nested/scripts/a/one.sh
|
77
92
|
- spec/fixtures/nested/scripts/one.sh
|
78
93
|
- spec/fixtures/nested_two/nested/scripts/a/one.sh
|
79
94
|
- spec/fixtures/nested_two/nested/scripts/one.sh
|
80
95
|
- spec/fixtures/nested_two/scripts/a/one.sh
|
81
96
|
- spec/fixtures/nested_two/scripts/one.sh
|
97
|
+
- spec/fixtures/non_runnable/scripts/one.sh
|
82
98
|
- spec/fixtures/one/env/one.properties
|
83
99
|
- spec/fixtures/one/scripts/one.sh
|
84
100
|
- spec/main_spec.rb
|
@@ -109,12 +125,14 @@ summary: it just runs scripts
|
|
109
125
|
test_files:
|
110
126
|
- spec/cmds_spec.rb
|
111
127
|
- spec/fixtures/has_error/scripts/error.sh
|
128
|
+
- spec/fixtures/nested/one.sh
|
112
129
|
- spec/fixtures/nested/scripts/a/one.sh
|
113
130
|
- spec/fixtures/nested/scripts/one.sh
|
114
131
|
- spec/fixtures/nested_two/nested/scripts/a/one.sh
|
115
132
|
- spec/fixtures/nested_two/nested/scripts/one.sh
|
116
133
|
- spec/fixtures/nested_two/scripts/a/one.sh
|
117
134
|
- spec/fixtures/nested_two/scripts/one.sh
|
135
|
+
- spec/fixtures/non_runnable/scripts/one.sh
|
118
136
|
- spec/fixtures/one/env/one.properties
|
119
137
|
- spec/fixtures/one/scripts/one.sh
|
120
138
|
- spec/main_spec.rb
|