script-runner 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.
- checksums.yaml +7 -0
- data/.gitignore +1 -0
- data/.ruby-gemset +1 -0
- data/.ruby-version +1 -0
- data/Gemfile +3 -0
- data/Gemfile.lock +28 -0
- data/README.md +45 -0
- data/Rakefile +7 -0
- data/lib/script-runner.rb +18 -0
- data/lib/script-runner/cmds.rb +19 -0
- data/lib/script-runner/main.rb +66 -0
- data/lib/script-runner/version.rb +4 -0
- data/script-runner.gemspec +22 -0
- data/spec/cmds_spec.rb +11 -0
- data/spec/fixtures/has_error/scripts/error.sh +3 -0
- data/spec/fixtures/nested/scripts/a/one.sh +2 -0
- data/spec/fixtures/nested/scripts/one.sh +2 -0
- data/spec/fixtures/nested_two/nested/scripts/a/one.sh +2 -0
- data/spec/fixtures/nested_two/nested/scripts/one.sh +2 -0
- data/spec/fixtures/nested_two/scripts/a/one.sh +2 -0
- data/spec/fixtures/nested_two/scripts/one.sh +2 -0
- data/spec/fixtures/one/env/one.properties +1 -0
- data/spec/fixtures/one/scripts/one.sh +2 -0
- data/spec/main_spec.rb +51 -0
- metadata +119 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 8f22b256b65aee577b02653246ac9cbe78293160
|
4
|
+
data.tar.gz: 87bfc1a45a8641e30766401b4921ab0a7d06cca9
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: dd472b956d336a913fc90c988dbeb0f26cbc49ebe252f0971bfd4a956d6d4451763a9532d75111e9421368d903826ed66b396e799469714f0d37f71160084631
|
7
|
+
data.tar.gz: 56e000a50487089ba19f66565bdbea1f25426f2b03d0bfc9d6bfcc47087752788cba0d88087dae0fa36a2c1cc14cd9d5eede0a2d677e0cc693a50adf555381c0
|
data/.gitignore
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
pkg
|
data/.ruby-gemset
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
script-runner
|
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
2.0.0
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
script-runner (0.0.1)
|
5
|
+
thor
|
6
|
+
|
7
|
+
GEM
|
8
|
+
remote: https://rubygems.org/
|
9
|
+
specs:
|
10
|
+
diff-lcs (1.2.4)
|
11
|
+
rake (10.1.0)
|
12
|
+
rspec (2.14.1)
|
13
|
+
rspec-core (~> 2.14.0)
|
14
|
+
rspec-expectations (~> 2.14.0)
|
15
|
+
rspec-mocks (~> 2.14.0)
|
16
|
+
rspec-core (2.14.5)
|
17
|
+
rspec-expectations (2.14.2)
|
18
|
+
diff-lcs (>= 1.1.3, < 2.0)
|
19
|
+
rspec-mocks (2.14.3)
|
20
|
+
thor (0.18.1)
|
21
|
+
|
22
|
+
PLATFORMS
|
23
|
+
ruby
|
24
|
+
|
25
|
+
DEPENDENCIES
|
26
|
+
rake (~> 10.1.0)
|
27
|
+
rspec (~> 2.6)
|
28
|
+
script-runner!
|
data/README.md
ADDED
@@ -0,0 +1,45 @@
|
|
1
|
+
# script-runner
|
2
|
+
|
3
|
+
A very simple library for running scripts on a file system.
|
4
|
+
|
5
|
+
## Usage
|
6
|
+
|
7
|
+
require 'script-runner'
|
8
|
+
ScriptRunner.run( array_of_paths, array_of_env_paths, error_handler, &handle_script_output )
|
9
|
+
|
10
|
+
## Example
|
11
|
+
|
12
|
+
If we have the following file structure
|
13
|
+
|
14
|
+
|
15
|
+
path-one/
|
16
|
+
script.sh
|
17
|
+
path-two/
|
18
|
+
path-two-one/
|
19
|
+
script.sh
|
20
|
+
script.sh
|
21
|
+
env-one/
|
22
|
+
one.properties
|
23
|
+
|
24
|
+
The following:
|
25
|
+
|
26
|
+
require 'script-runner'
|
27
|
+
error_handler = lamba{ |script_path| raise "an error occured with: #{script_path}" }
|
28
|
+
ScriptRunner.run( ["path-one", "path-two"], ["env-one"], error_handler ){ |script_output| puts script_output}
|
29
|
+
|
30
|
+
Will:
|
31
|
+
* set env vars as defined in `env-one/one.properties`
|
32
|
+
* run `path-one/script.sh`, `path-two/path-two-one/script.sh`, `path-two/script.sh` - with the env vars defined
|
33
|
+
* the output will be sent to the console using `puts`
|
34
|
+
* any errors will call `error_handler`
|
35
|
+
|
36
|
+
Note: for each root_path, all files under are invoked in alphabetical order
|
37
|
+
|
38
|
+
### installation
|
39
|
+
|
40
|
+
cd script-runner
|
41
|
+
gem install bundler
|
42
|
+
bundle install
|
43
|
+
rake # run tests
|
44
|
+
rake build # make .gem file
|
45
|
+
gem install pkg/script-runner-0.0.1.gem
|
data/Rakefile
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'script-runner/main'
|
2
|
+
|
3
|
+
module ScriptRunner
|
4
|
+
|
5
|
+
# Run a set of scripts
|
6
|
+
#
|
7
|
+
# Note: non executable files are skipped and a warning is sent to the console
|
8
|
+
#
|
9
|
+
# @paths - an array of paths with scripts to invoke
|
10
|
+
# @env_vars - an array of paths that contains .properties files
|
11
|
+
# @error_handler - a callback if a non-zero exit code occured
|
12
|
+
# @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, error_handler = nil, &block)
|
14
|
+
runner = ScriptRunner::Main.new
|
15
|
+
runner.run(paths, env_vars, error_handler, &block)
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
@@ -0,0 +1,66 @@
|
|
1
|
+
module ScriptRunner
|
2
|
+
|
3
|
+
class Main
|
4
|
+
|
5
|
+
# Run a set of scripts
|
6
|
+
#
|
7
|
+
# Note: non executable files are skipped and a warning is sent to the console
|
8
|
+
#
|
9
|
+
# @paths - an array of paths with scripts to invoke
|
10
|
+
# @env_vars - an array of paths that contains .properties files
|
11
|
+
# @error_handler - a callback if a non-zero exit code occured
|
12
|
+
# @block - a block to handle the output of the script if non is given it is sent to the console
|
13
|
+
def run( paths, env_vars, error_handler = nil, &block)
|
14
|
+
set_env(env_vars)
|
15
|
+
all_paths = all_files(paths).select{ |p| File.file? p }
|
16
|
+
runnable = all_paths.select{ |p| File.executable? p }
|
17
|
+
non_runnable = all_paths - runnable
|
18
|
+
|
19
|
+
non_runnable.each{ |nr|
|
20
|
+
puts "warning: #{nr} is not runnable - skipping"
|
21
|
+
}
|
22
|
+
|
23
|
+
all_paths.each{ |p|
|
24
|
+
exec(p, error_handler, &block)
|
25
|
+
}
|
26
|
+
end
|
27
|
+
|
28
|
+
private
|
29
|
+
|
30
|
+
def exec(script_path, error_handler = nil, &block)
|
31
|
+
IO.popen(script_path) do |io|
|
32
|
+
while line = io.gets
|
33
|
+
if block_given?
|
34
|
+
block.call(line.chomp)
|
35
|
+
else
|
36
|
+
puts line.chomp
|
37
|
+
end
|
38
|
+
end
|
39
|
+
io.close
|
40
|
+
error_handler.call(script_path) if $?.to_i != 0 and !error_handler.nil?
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
def all_files(array)
|
45
|
+
array.inject([]){ |acc,y|
|
46
|
+
acc.concat(Dir["#{y}/**/*"].entries)
|
47
|
+
}
|
48
|
+
end
|
49
|
+
|
50
|
+
def set_env(env_paths)
|
51
|
+
env_files = all_files(env_paths)
|
52
|
+
|
53
|
+
env_files.each{ |p|
|
54
|
+
puts "setting env from #{p}"
|
55
|
+
File.readlines(p).each do |line|
|
56
|
+
if line.include? "="
|
57
|
+
values = line.split("=")
|
58
|
+
ENV[values[0].chomp] = values[1].chomp
|
59
|
+
end
|
60
|
+
end
|
61
|
+
}
|
62
|
+
end
|
63
|
+
|
64
|
+
end
|
65
|
+
|
66
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
require File.expand_path('../lib/script-runner/version', __FILE__)
|
3
|
+
|
4
|
+
name = "script-runner"
|
5
|
+
|
6
|
+
Gem::Specification.new do |gem|
|
7
|
+
gem.authors = ["ed.eustace"]
|
8
|
+
gem.email = ["ed.eustace@gmail.com"]
|
9
|
+
gem.description = %q{it just runs scripts}
|
10
|
+
gem.summary = gem.description
|
11
|
+
gem.homepage = "http://github.com/edeustace/script-runner"
|
12
|
+
gem.files = `git ls-files`.split($\)
|
13
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
14
|
+
gem.name = name
|
15
|
+
gem.require_paths = ["lib"]
|
16
|
+
gem.required_ruby_version = '>= 2.0.0'
|
17
|
+
gem.version = ScriptRunner::VERSION
|
18
|
+
gem.add_development_dependency "rspec", "~> 2.6"
|
19
|
+
gem.add_development_dependency "rake", "~> 10.1.0"
|
20
|
+
gem.add_dependency "thor"
|
21
|
+
|
22
|
+
end
|
data/spec/cmds_spec.rb
ADDED
@@ -0,0 +1,11 @@
|
|
1
|
+
require 'script-runner/cmds'
|
2
|
+
|
3
|
+
include ScriptRunner
|
4
|
+
|
5
|
+
describe Commands do
|
6
|
+
it "should ping" do
|
7
|
+
p = Commands::Ping.new
|
8
|
+
p.run("hello world").should eql("hello world")
|
9
|
+
p.run("hello world", :reverse => true).should eql("hello world".reverse)
|
10
|
+
end
|
11
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
CUSTOM_VAR=custom var
|
data/spec/main_spec.rb
ADDED
@@ -0,0 +1,51 @@
|
|
1
|
+
require 'script-runner'
|
2
|
+
|
3
|
+
describe ScriptRunner do
|
4
|
+
|
5
|
+
before(:each) do
|
6
|
+
@test_files = "spec/fixtures"
|
7
|
+
@all_output = []
|
8
|
+
@error_files = []
|
9
|
+
end
|
10
|
+
|
11
|
+
def scripts(*names)
|
12
|
+
file_array("scripts", names)
|
13
|
+
end
|
14
|
+
|
15
|
+
def env(*names)
|
16
|
+
file_array("env", names)
|
17
|
+
end
|
18
|
+
|
19
|
+
def file_array(key,names)
|
20
|
+
names.map{ |n| File.join(@test_files, n, key) }
|
21
|
+
end
|
22
|
+
|
23
|
+
it "should run scripts" do
|
24
|
+
p = ScriptRunner.run(scripts("one"), env("one")) { |output| @all_output << output }
|
25
|
+
@all_output.should eql ["hello there custom var"]
|
26
|
+
@error_files.length.should eql 0
|
27
|
+
end
|
28
|
+
|
29
|
+
it "should allow errors to be handled" do
|
30
|
+
error_handler = lambda{ |p| @error_files << p}
|
31
|
+
p = ScriptRunner.run(scripts("one", "has_error"), env("one"), error_handler) { |output| @all_output << output }
|
32
|
+
@error_files.length.should eql 1
|
33
|
+
end
|
34
|
+
|
35
|
+
it "should call nested in alphabetical order" do
|
36
|
+
puts "before : #{@all_output}"
|
37
|
+
p = ScriptRunner.run(scripts("nested"), env("one")) { |output| @all_output << output }
|
38
|
+
@all_output.should eql ["spec/fixtures/nested/scripts/a/one.sh", "spec/fixtures/nested/scripts/one.sh"]
|
39
|
+
end
|
40
|
+
|
41
|
+
it "should call multiple nested in alphabetical order" do
|
42
|
+
puts "before : #{@all_output}"
|
43
|
+
p = ScriptRunner.run(scripts("one", "nested_two", "nested"), env("one")) { |output| @all_output << output }
|
44
|
+
@all_output.should eql [
|
45
|
+
"hello there custom var",
|
46
|
+
"spec/fixtures/nested_two/scripts/a/one.sh",
|
47
|
+
"spec/fixtures/nested_two/scripts/one.sh",
|
48
|
+
"spec/fixtures/nested/scripts/a/one.sh",
|
49
|
+
"spec/fixtures/nested/scripts/one.sh"]
|
50
|
+
end
|
51
|
+
end
|
metadata
ADDED
@@ -0,0 +1,119 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: script-runner
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- ed.eustace
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2013-08-24 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rspec
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ~>
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '2.6'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '2.6'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ~>
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 10.1.0
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ~>
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 10.1.0
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: thor
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - '>='
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
description: it just runs scripts
|
56
|
+
email:
|
57
|
+
- ed.eustace@gmail.com
|
58
|
+
executables: []
|
59
|
+
extensions: []
|
60
|
+
extra_rdoc_files: []
|
61
|
+
files:
|
62
|
+
- .gitignore
|
63
|
+
- .ruby-gemset
|
64
|
+
- .ruby-version
|
65
|
+
- Gemfile
|
66
|
+
- Gemfile.lock
|
67
|
+
- README.md
|
68
|
+
- Rakefile
|
69
|
+
- lib/script-runner.rb
|
70
|
+
- lib/script-runner/cmds.rb
|
71
|
+
- lib/script-runner/main.rb
|
72
|
+
- lib/script-runner/version.rb
|
73
|
+
- script-runner.gemspec
|
74
|
+
- spec/cmds_spec.rb
|
75
|
+
- spec/fixtures/has_error/scripts/error.sh
|
76
|
+
- spec/fixtures/nested/scripts/a/one.sh
|
77
|
+
- spec/fixtures/nested/scripts/one.sh
|
78
|
+
- spec/fixtures/nested_two/nested/scripts/a/one.sh
|
79
|
+
- spec/fixtures/nested_two/nested/scripts/one.sh
|
80
|
+
- spec/fixtures/nested_two/scripts/a/one.sh
|
81
|
+
- spec/fixtures/nested_two/scripts/one.sh
|
82
|
+
- spec/fixtures/one/env/one.properties
|
83
|
+
- spec/fixtures/one/scripts/one.sh
|
84
|
+
- spec/main_spec.rb
|
85
|
+
homepage: http://github.com/edeustace/script-runner
|
86
|
+
licenses: []
|
87
|
+
metadata: {}
|
88
|
+
post_install_message:
|
89
|
+
rdoc_options: []
|
90
|
+
require_paths:
|
91
|
+
- lib
|
92
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - '>='
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: 2.0.0
|
97
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
98
|
+
requirements:
|
99
|
+
- - '>='
|
100
|
+
- !ruby/object:Gem::Version
|
101
|
+
version: '0'
|
102
|
+
requirements: []
|
103
|
+
rubyforge_project:
|
104
|
+
rubygems_version: 2.0.3
|
105
|
+
signing_key:
|
106
|
+
specification_version: 4
|
107
|
+
summary: it just runs scripts
|
108
|
+
test_files:
|
109
|
+
- spec/cmds_spec.rb
|
110
|
+
- spec/fixtures/has_error/scripts/error.sh
|
111
|
+
- spec/fixtures/nested/scripts/a/one.sh
|
112
|
+
- spec/fixtures/nested/scripts/one.sh
|
113
|
+
- spec/fixtures/nested_two/nested/scripts/a/one.sh
|
114
|
+
- spec/fixtures/nested_two/nested/scripts/one.sh
|
115
|
+
- spec/fixtures/nested_two/scripts/a/one.sh
|
116
|
+
- spec/fixtures/nested_two/scripts/one.sh
|
117
|
+
- spec/fixtures/one/env/one.properties
|
118
|
+
- spec/fixtures/one/scripts/one.sh
|
119
|
+
- spec/main_spec.rb
|