maestro_shell 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +18 -0
- data/.rvmrc +1 -0
- data/Gemfile +3 -0
- data/Gemfile.lock +43 -0
- data/LICENSE.txt +22 -0
- data/README.md +83 -0
- data/Rakefile +17 -0
- data/lib/shell.rb +2 -0
- data/lib/util/logging.rb +21 -0
- data/lib/util/shell.rb +121 -0
- data/lib/util/version.rb +7 -0
- data/maestro_shell.gemspec +31 -0
- data/pom.xml +55 -0
- data/spec/shell_spec.rb +136 -0
- data/spec/spec_helper.rb +15 -0
- metadata +159 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 38403db26c3a5efb5b432a820decf1f2903400b4
|
4
|
+
data.tar.gz: efd918de63d982acac5623e41d483e32e33b7ce6
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 48f1468bbe9cd070fd9179499c30702caa957687bbad57f28bab347822363eee1bcd65b584b2aeb96d3fc70886f05e5090a563fa3709915d341b24e3482e0254
|
7
|
+
data.tar.gz: a7a615eab7b4ef79e509d1128d56fcb5054326426b0f07d7cf9824179f8fcfffe0759f0e6215043a4ae9c740dc77411c47fb913bd6eef0634b298d8953888641
|
data/.gitignore
ADDED
data/.rvmrc
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
rvm use jruby-1.7.4
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,43 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
maestro_shell (0.0.1)
|
5
|
+
json (>= 1.4.6)
|
6
|
+
logging (= 1.8.0)
|
7
|
+
rubyzip (= 0.9.8)
|
8
|
+
|
9
|
+
GEM
|
10
|
+
remote: https://rubygems.org/
|
11
|
+
specs:
|
12
|
+
diff-lcs (1.2.4)
|
13
|
+
json (1.8.0)
|
14
|
+
json (1.8.0-java)
|
15
|
+
little-plugger (1.1.3)
|
16
|
+
logging (1.8.0)
|
17
|
+
little-plugger (>= 1.1.3)
|
18
|
+
multi_json (>= 1.3.6)
|
19
|
+
metaclass (0.0.1)
|
20
|
+
mocha (0.14.0)
|
21
|
+
metaclass (~> 0.0.1)
|
22
|
+
multi_json (1.7.7)
|
23
|
+
rake (10.0.4)
|
24
|
+
rspec (2.13.0)
|
25
|
+
rspec-core (~> 2.13.0)
|
26
|
+
rspec-expectations (~> 2.13.0)
|
27
|
+
rspec-mocks (~> 2.13.0)
|
28
|
+
rspec-core (2.13.1)
|
29
|
+
rspec-expectations (2.13.0)
|
30
|
+
diff-lcs (>= 1.1.3, < 2.0)
|
31
|
+
rspec-mocks (2.13.1)
|
32
|
+
rubyzip (0.9.8)
|
33
|
+
|
34
|
+
PLATFORMS
|
35
|
+
java
|
36
|
+
ruby
|
37
|
+
|
38
|
+
DEPENDENCIES
|
39
|
+
bundler (~> 1.3)
|
40
|
+
maestro_shell!
|
41
|
+
mocha (>= 0.10.0)
|
42
|
+
rake
|
43
|
+
rspec (~> 2.13.0)
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 Etienne Pelletier
|
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,83 @@
|
|
1
|
+
Maestro Shell Utility Gem
|
2
|
+
=========================
|
3
|
+
|
4
|
+
Library For Executing Shell commands on Linux and Windows
|
5
|
+
=========================================================
|
6
|
+
|
7
|
+
# Introduction
|
8
|
+
|
9
|
+
This gem provides a simple class that allows shell commands to be run, with output gathered (both stdout and stderr) and
|
10
|
+
return-code availability.
|
11
|
+
Callbacks are available to deliver output in real-time as it occurs, or it may be read at the end of execution.
|
12
|
+
|
13
|
+
Important:
|
14
|
+
This gem utilizes the IO::popen4 functionality available in JRUBY.
|
15
|
+
It is not intended to work in a non-JRUBY environment.
|
16
|
+
|
17
|
+
# Installation
|
18
|
+
|
19
|
+
Add this line to your application's Gemfile:
|
20
|
+
|
21
|
+
gem 'maestro_shell'
|
22
|
+
|
23
|
+
And then execute:
|
24
|
+
|
25
|
+
$ bundle
|
26
|
+
|
27
|
+
Or install it yourself as:
|
28
|
+
|
29
|
+
$ gem install maestro_shell
|
30
|
+
|
31
|
+
# Usage
|
32
|
+
|
33
|
+
In code:
|
34
|
+
|
35
|
+
require 'shell'
|
36
|
+
|
37
|
+
## Simple single-function-call:
|
38
|
+
|
39
|
+
result = Maestro::Util::Shell.run_command('ls')
|
40
|
+
|
41
|
+
puts "Return Code: #{result[0]}"
|
42
|
+
puts "Output: #{result[1]}"
|
43
|
+
|
44
|
+
## More complete example:
|
45
|
+
|
46
|
+
This requires a delegate class/method that can read and process output as it is generated.
|
47
|
+
The signature of the delegate method should be:
|
48
|
+
def method(text, is_stderr)
|
49
|
+
|
50
|
+
Example code:
|
51
|
+
|
52
|
+
shell = Maestro::Util::Shell.new()
|
53
|
+
shell.create_script('ls')
|
54
|
+
shell.run_script_with_delegate(delegate, on_output)
|
55
|
+
|
56
|
+
if shell.exit_code.success?
|
57
|
+
puts 'Yay!'
|
58
|
+
else
|
59
|
+
puts 'Boo!!'
|
60
|
+
end
|
61
|
+
|
62
|
+
puts "Script exit code: #{script.exit_code.exit_code}
|
63
|
+
puts "Entire output: #{script}" # or #{script.to_s}, or #{script.output}
|
64
|
+
|
65
|
+
|
66
|
+
# The +text+ parameter is not necessarily a line of text... it could just be a "." being
|
67
|
+
# output from a long-running process. It could also include non-printable characters
|
68
|
+
# as it is the raw stream from the command.
|
69
|
+
def output_handler(text, is_stderr)
|
70
|
+
# is_stderr is set if the text came from stderr vs normal stdout.
|
71
|
+
# This is so you can process separately if you wish
|
72
|
+
if is_stderr
|
73
|
+
handle_error_text(text)
|
74
|
+
end
|
75
|
+
|
76
|
+
print my_logging_class.debug(text)
|
77
|
+
end
|
78
|
+
|
79
|
+
Notes
|
80
|
+
-----
|
81
|
+
|
82
|
+
* The 'command' passed to the shell is actually written to a script file, which is then executed. As such, it is possible to execute multi-line commands - just pass the entire string to be written to the script file as a command.
|
83
|
+
* The script file is run by the native shell on the target OS, in the case of Linux this is the bash shell, in Windows this is the default command processor.
|
data/Rakefile
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
require 'bundler/gem_tasks'
|
2
|
+
require 'rspec/core/rake_task'
|
3
|
+
require 'rake/clean'
|
4
|
+
|
5
|
+
#require File.expand_path('../lib/maestro_plugin/version', __FILE__)
|
6
|
+
|
7
|
+
CLEAN.include('pkg')
|
8
|
+
CLOBBER.include('.bundle', '.config', 'coverage', 'InstalledFiles', 'spec/reports', 'rdoc', 'test', 'tmp')
|
9
|
+
|
10
|
+
task :default => [:clean, :bundle, :spec, :build]
|
11
|
+
|
12
|
+
RSpec::Core::RakeTask.new
|
13
|
+
|
14
|
+
desc 'Get dependencies with Bundler'
|
15
|
+
task :bundle do
|
16
|
+
sh %{bundle install}
|
17
|
+
end
|
data/lib/shell.rb
ADDED
data/lib/util/logging.rb
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
# Copyright 2013 (c) MaestroDev. All rights reserved.
|
2
|
+
require 'logging'
|
3
|
+
|
4
|
+
module Maestro
|
5
|
+
|
6
|
+
unless Maestro.const_defined?('Logging')
|
7
|
+
|
8
|
+
module Logging
|
9
|
+
|
10
|
+
def log
|
11
|
+
::Logging::Logger.new(STDOUT)
|
12
|
+
end
|
13
|
+
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
class << self
|
18
|
+
include Maestro::Logging unless Maestro.include?(Maestro::Logging)
|
19
|
+
end
|
20
|
+
|
21
|
+
end
|
data/lib/util/shell.rb
ADDED
@@ -0,0 +1,121 @@
|
|
1
|
+
# Copyright 2011 (c) MaestroDev. All rights reserved.
|
2
|
+
|
3
|
+
require 'tempfile'
|
4
|
+
require 'rbconfig'
|
5
|
+
|
6
|
+
module Maestro
|
7
|
+
module Util
|
8
|
+
class Shell
|
9
|
+
|
10
|
+
attr_reader :script_file
|
11
|
+
attr_reader :output_file
|
12
|
+
attr_reader :shell
|
13
|
+
attr_reader :exit_code
|
14
|
+
|
15
|
+
class ExitCode
|
16
|
+
attr_reader :exit_code
|
17
|
+
|
18
|
+
def initialize(status)
|
19
|
+
@exit_code = status.exitstatus
|
20
|
+
end
|
21
|
+
|
22
|
+
def success?
|
23
|
+
@exit_code == 0
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
# Utility variables
|
28
|
+
IS_WINDOWS = RbConfig::CONFIG['host_os'] =~ /mswin/
|
29
|
+
SEPARATOR = IS_WINDOWS ? "\\" : "/"
|
30
|
+
MOVE_COMMAND = IS_WINDOWS ? 'move' : 'mv'
|
31
|
+
ENV_EXPORT_COMMAND = IS_WINDOWS ? 'set' : 'export'
|
32
|
+
COMMAND_SEPARATOR = '&&' # IS_WINDOWS ? '&&' : '&&'
|
33
|
+
SCRIPT_EXTENSION = IS_WINDOWS ? '.bat' : '.shell'
|
34
|
+
SHELL_EXECUTABLE = IS_WINDOWS ? '' : 'bash '
|
35
|
+
|
36
|
+
def Shell.unset_env_variable(var)
|
37
|
+
IS_WINDOWS ? "set #{var}=" : "unset #{var}"
|
38
|
+
end
|
39
|
+
|
40
|
+
def Shell.run_command(command)
|
41
|
+
shell = Shell.new
|
42
|
+
shell.create_script(command)
|
43
|
+
shell.run_script
|
44
|
+
return shell.exit_code, shell.to_s
|
45
|
+
end
|
46
|
+
|
47
|
+
def create_script(contents)
|
48
|
+
raise "Script Cannot Be Empty" if contents.nil? or contents.empty?
|
49
|
+
|
50
|
+
@script_file = Tempfile.new(["script", SCRIPT_EXTENSION])
|
51
|
+
@output_file = Tempfile.new(['output','log'])
|
52
|
+
# Run any commands in the default system Ruby environment, rather
|
53
|
+
# than the one the agent is currently using (which within the wrapper,
|
54
|
+
# sets clean values for these to avoid RVM or System gems that might
|
55
|
+
# conflict). If the caller needs a specific Ruby environment, it should
|
56
|
+
# establish that itself (as the rake task does through rvm if chosen)
|
57
|
+
# Add clear env variable commands to head of script, since we don't necessarily have access to env here (depending on
|
58
|
+
# version of ruby/bugs)
|
59
|
+
contents = "#{Shell.unset_env_variable('GEM_HOME')}\n#{Shell.unset_env_variable('GEM_PATH')}\n#{contents}"
|
60
|
+
@script_file.write(contents)
|
61
|
+
@script_file.close
|
62
|
+
Maestro.log.debug "Writing Script File To #{@script_file.path}"
|
63
|
+
return get_command(@script_file.path)
|
64
|
+
end
|
65
|
+
|
66
|
+
def run_script
|
67
|
+
run_script_with_delegate(nil, nil)
|
68
|
+
end
|
69
|
+
|
70
|
+
# if +delegate+ provided, the method named/symbolized by +on_output+ value will be called for each line
|
71
|
+
# of output to either stdout or stderr.
|
72
|
+
# two parameters are passed:
|
73
|
+
# +text+ String Output text. This may be any amount of data from 1 character to many lines.
|
74
|
+
# do not assume it always represents a single line.
|
75
|
+
# +err+ Boolean True if line is from stderr
|
76
|
+
def run_script_with_delegate(delegate, on_output)
|
77
|
+
File.open(@output_file.path, 'a') do |out_file|
|
78
|
+
status = IO.popen4(@command_line) do |pid, stdin, stdout, stderr|
|
79
|
+
threads = []
|
80
|
+
# Read stdout/stderr and push to output
|
81
|
+
[ stdout, stderr ].each do |stream|
|
82
|
+
threads << Thread.new do
|
83
|
+
while !stream.eof? && text = stream.readpartial(1024)
|
84
|
+
out_file.write(text)
|
85
|
+
|
86
|
+
if delegate && on_output
|
87
|
+
delegate.send(on_output, text, stream == stderr)
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
# Wait for stream handler threads to exit
|
94
|
+
threads.each { |t| t.join }
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
98
|
+
@exit_code = ExitCode.new($?)
|
99
|
+
|
100
|
+
return @exit_code
|
101
|
+
end
|
102
|
+
|
103
|
+
def to_s
|
104
|
+
@output_file.read if @output_file
|
105
|
+
end
|
106
|
+
alias :output :to_s
|
107
|
+
|
108
|
+
###########
|
109
|
+
# PRIVATE #
|
110
|
+
###########
|
111
|
+
|
112
|
+
private
|
113
|
+
|
114
|
+
def get_command(path)
|
115
|
+
@command_line = "#{SHELL_EXECUTABLE}#{path}"
|
116
|
+
@command_line
|
117
|
+
end
|
118
|
+
|
119
|
+
end
|
120
|
+
end
|
121
|
+
end
|
data/lib/util/version.rb
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'util/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = 'maestro_shell'
|
8
|
+
spec.version = Maestro::Util::Shell::VERSION
|
9
|
+
spec.authors = ['Doug Henderson']
|
10
|
+
spec.email = ['dhenderson@maestrodev.com']
|
11
|
+
spec.description = %q{A ruby library to help with the creation of Maestro plugins that need Shell functionality}
|
12
|
+
spec.summary = %q{Maestro Shell utility}
|
13
|
+
spec.homepage = 'https://github.com/maestrodev/maestro-shell'
|
14
|
+
spec.license = 'Apache 2.0'
|
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_dependency 'logging', '1.8.0'
|
22
|
+
spec.add_dependency 'rubyzip', '0.9.8'
|
23
|
+
spec.add_dependency 'json', '>= 1.4.6'
|
24
|
+
|
25
|
+
spec.add_development_dependency "mocha", '>=0.10.0'
|
26
|
+
spec.add_development_dependency 'bundler', '~> 1.3'
|
27
|
+
spec.add_development_dependency 'rake'
|
28
|
+
# spec.add_development_dependency 'jruby-openssl'
|
29
|
+
spec.add_development_dependency 'rspec', '~> 2.13.0'
|
30
|
+
|
31
|
+
end
|
data/pom.xml
ADDED
@@ -0,0 +1,55 @@
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
2
|
+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
3
|
+
<modelVersion>4.0.0</modelVersion>
|
4
|
+
|
5
|
+
<groupId>com.maestrodev</groupId>
|
6
|
+
<artifactId>maestro-shell</artifactId>
|
7
|
+
<version>1.0-SNAPSHOT</version>
|
8
|
+
<name>maestro-shell</name>
|
9
|
+
<packaging>pom</packaging>
|
10
|
+
|
11
|
+
<scm>
|
12
|
+
<developerConnection>scm:git:git@github.com:maestrodev/maestro-shell.git</developerConnection>
|
13
|
+
<connection>scm:git:git@github.com:maestrodev/maestro-shell.git</connection>
|
14
|
+
</scm>
|
15
|
+
|
16
|
+
<distributionManagement>
|
17
|
+
<repository>
|
18
|
+
<id>maestro-deploy</id>
|
19
|
+
<url>https://repo.maestrodev.com/archiva/repository/public-releases/</url>
|
20
|
+
</repository>
|
21
|
+
<snapshotRepository>
|
22
|
+
<id>maestro-deploy</id>
|
23
|
+
<url>https://repo.maestrodev.com/archiva/repository/public-snapshots/</url>
|
24
|
+
</snapshotRepository>
|
25
|
+
</distributionManagement>
|
26
|
+
|
27
|
+
<build>
|
28
|
+
<plugins>
|
29
|
+
<plugin>
|
30
|
+
<groupId>org.codehaus.mojo</groupId>
|
31
|
+
<artifactId>build-helper-maven-plugin</artifactId>
|
32
|
+
<version>1.7</version>
|
33
|
+
<executions>
|
34
|
+
<execution>
|
35
|
+
<id>attach-zip</id>
|
36
|
+
<phase>package</phase>
|
37
|
+
<goals>
|
38
|
+
<goal>attach-artifact</goal>
|
39
|
+
</goals>
|
40
|
+
<configuration>
|
41
|
+
<artifacts>
|
42
|
+
<artifact>
|
43
|
+
<file>${project.artifactId}-${project.version}.zip</file>
|
44
|
+
<type>zip</type>
|
45
|
+
<classifier>bin</classifier>
|
46
|
+
</artifact>
|
47
|
+
</artifacts>
|
48
|
+
</configuration>
|
49
|
+
</execution>
|
50
|
+
</executions>
|
51
|
+
</plugin>
|
52
|
+
</plugins>
|
53
|
+
</build>
|
54
|
+
|
55
|
+
</project>
|
data/spec/shell_spec.rb
ADDED
@@ -0,0 +1,136 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Maestro::Util::Shell do
|
4
|
+
|
5
|
+
# it 'should create a script' do
|
6
|
+
# path = subject.create_script "some shell command"
|
7
|
+
#
|
8
|
+
# File.exists?(path).should be_true
|
9
|
+
# end
|
10
|
+
|
11
|
+
# it 'should create a script without random path' do
|
12
|
+
# subject = Maestro::Util::Shell.new("/tmp/maestro-test-script")
|
13
|
+
# path = subject.create_script "some shell command"
|
14
|
+
# subject.shell.should eql("/bin/bash")
|
15
|
+
# File.exists?(path).should be_true
|
16
|
+
# end
|
17
|
+
|
18
|
+
# it 'should create a script with shell parameter' do
|
19
|
+
# subject = Maestro::Util::Shell.new(nil, "/tmp/bash")
|
20
|
+
# path = subject.create_script "some shell command"
|
21
|
+
# File.exists?(path).should be_true
|
22
|
+
# path.should_not eql("/tmp/bash")
|
23
|
+
# end
|
24
|
+
#
|
25
|
+
# it 'should create two scripts with random name' do
|
26
|
+
# path1 = subject.create_script "some shell command"
|
27
|
+
# path2 = subject.create_script "another shell command"
|
28
|
+
#
|
29
|
+
# path1.should_not eql(path2)
|
30
|
+
# File.exists?(path1).should be_true
|
31
|
+
# File.exists?(path2).should be_true
|
32
|
+
# end
|
33
|
+
|
34
|
+
it 'should run script' do
|
35
|
+
path = subject.create_script "echo willy"
|
36
|
+
# File.exists?(path).should be_true
|
37
|
+
|
38
|
+
subject.run_script.success?.should be_true
|
39
|
+
|
40
|
+
subject.to_s.chomp.should eql('willy')
|
41
|
+
end
|
42
|
+
|
43
|
+
it 'should run script with delegate' do
|
44
|
+
path = subject.create_script "echo willy"
|
45
|
+
|
46
|
+
delegate = mock()
|
47
|
+
delegate.expects(:write_output).at_least(1)
|
48
|
+
|
49
|
+
subject.run_script_with_delegate(delegate, "write_output")
|
50
|
+
subject.to_s.chomp.should eql('willy')
|
51
|
+
end
|
52
|
+
|
53
|
+
it 'should parse output' do
|
54
|
+
path = subject.create_script "echo wonka"
|
55
|
+
|
56
|
+
|
57
|
+
subject.run_script
|
58
|
+
subject.to_s.chomp.should eql("wonka")
|
59
|
+
end
|
60
|
+
|
61
|
+
it 'should return error on error' do
|
62
|
+
path = subject.create_script "blah hello"
|
63
|
+
|
64
|
+
subject.run_script.success?.should be_false
|
65
|
+
subject.to_s.should include("blah: command not found")
|
66
|
+
end
|
67
|
+
|
68
|
+
it 'should run with with export inline' do
|
69
|
+
command =<<-CMD
|
70
|
+
#{Maestro::Util::Shell::ENV_EXPORT_COMMAND} BLAH=blah; echo $BLAH
|
71
|
+
CMD
|
72
|
+
|
73
|
+
path = subject.create_script command
|
74
|
+
|
75
|
+
subject.run_script.success?.should be_true
|
76
|
+
subject.to_s.should eql("blah\n")
|
77
|
+
end
|
78
|
+
|
79
|
+
|
80
|
+
it 'should run multiline command' do
|
81
|
+
command =<<-CMD
|
82
|
+
echo hello\r\n
|
83
|
+
echo goodbye
|
84
|
+
CMD
|
85
|
+
|
86
|
+
path = subject.create_script command
|
87
|
+
|
88
|
+
subject.run_script.success?.should be_true
|
89
|
+
subject.to_s.should eql("hello\r\ngoodbye\n")
|
90
|
+
end
|
91
|
+
|
92
|
+
it 'should create run and return result in on call' do
|
93
|
+
exit_code, output = Maestro::Util::Shell.run_command('echo what')
|
94
|
+
output.should eql("what\n")
|
95
|
+
exit_code.success?.should be_true
|
96
|
+
end
|
97
|
+
|
98
|
+
it 'should maintain env' do
|
99
|
+
temp = Tempfile.new('script.sh')
|
100
|
+
temp.write("echo $BLAH")
|
101
|
+
temp.close
|
102
|
+
File.chmod(0777, temp.path)
|
103
|
+
command =<<-CMD
|
104
|
+
#{Maestro::Util::Shell::ENV_EXPORT_COMMAND} BLAH=blah; echo $BLAH
|
105
|
+
#{temp.path}
|
106
|
+
CMD
|
107
|
+
|
108
|
+
path = subject.create_script command
|
109
|
+
|
110
|
+
subject.run_script.success?.should be_true
|
111
|
+
subject.to_s.should eql("blah\nblah\n")
|
112
|
+
|
113
|
+
temp = Tempfile.new('script.sh')
|
114
|
+
temp.write("pwd")
|
115
|
+
temp.close
|
116
|
+
File.chmod(0777, temp.path)
|
117
|
+
command =<<-CMD
|
118
|
+
pwd
|
119
|
+
cd /
|
120
|
+
#{temp.path}
|
121
|
+
CMD
|
122
|
+
|
123
|
+
path = subject.create_script command
|
124
|
+
|
125
|
+
subject.run_script.success?.should be_true
|
126
|
+
subject.to_s.should eql("#{`pwd`}/\n")
|
127
|
+
end
|
128
|
+
|
129
|
+
it "should load all of a large output" do
|
130
|
+
output =`cat #{File.join(File.dirname(__FILE__), '..','maestro_shell.gemspec')}`.chomp
|
131
|
+
subject.create_script "cat #{File.join(File.dirname(__FILE__), '..','maestro_shell.gemspec')}"
|
132
|
+
|
133
|
+
subject.run_script
|
134
|
+
subject.to_s.chomp.should eql(output)
|
135
|
+
end
|
136
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rspec'
|
3
|
+
|
4
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__) + '/../lib') unless $LOAD_PATH.include?(File.dirname(__FILE__) + '/../lib')
|
5
|
+
|
6
|
+
require 'shell'
|
7
|
+
|
8
|
+
RSpec.configure do |config|
|
9
|
+
|
10
|
+
config.mock_with :mocha
|
11
|
+
|
12
|
+
end
|
13
|
+
|
14
|
+
|
15
|
+
|
metadata
ADDED
@@ -0,0 +1,159 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: maestro_shell
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Doug Henderson
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2013-06-27 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: logging
|
15
|
+
version_requirements: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - '='
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 1.8.0
|
20
|
+
requirement: !ruby/object:Gem::Requirement
|
21
|
+
requirements:
|
22
|
+
- - '='
|
23
|
+
- !ruby/object:Gem::Version
|
24
|
+
version: 1.8.0
|
25
|
+
prerelease: false
|
26
|
+
type: :runtime
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rubyzip
|
29
|
+
version_requirements: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - '='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 0.9.8
|
34
|
+
requirement: !ruby/object:Gem::Requirement
|
35
|
+
requirements:
|
36
|
+
- - '='
|
37
|
+
- !ruby/object:Gem::Version
|
38
|
+
version: 0.9.8
|
39
|
+
prerelease: false
|
40
|
+
type: :runtime
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: json
|
43
|
+
version_requirements: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - '>='
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: 1.4.6
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
requirements:
|
50
|
+
- - '>='
|
51
|
+
- !ruby/object:Gem::Version
|
52
|
+
version: 1.4.6
|
53
|
+
prerelease: false
|
54
|
+
type: :runtime
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: mocha
|
57
|
+
version_requirements: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 0.10.0
|
62
|
+
requirement: !ruby/object:Gem::Requirement
|
63
|
+
requirements:
|
64
|
+
- - '>='
|
65
|
+
- !ruby/object:Gem::Version
|
66
|
+
version: 0.10.0
|
67
|
+
prerelease: false
|
68
|
+
type: :development
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: bundler
|
71
|
+
version_requirements: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ~>
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '1.3'
|
76
|
+
requirement: !ruby/object:Gem::Requirement
|
77
|
+
requirements:
|
78
|
+
- - ~>
|
79
|
+
- !ruby/object:Gem::Version
|
80
|
+
version: '1.3'
|
81
|
+
prerelease: false
|
82
|
+
type: :development
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: rake
|
85
|
+
version_requirements: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - '>='
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
requirement: !ruby/object:Gem::Requirement
|
91
|
+
requirements:
|
92
|
+
- - '>='
|
93
|
+
- !ruby/object:Gem::Version
|
94
|
+
version: '0'
|
95
|
+
prerelease: false
|
96
|
+
type: :development
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: rspec
|
99
|
+
version_requirements: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ~>
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: 2.13.0
|
104
|
+
requirement: !ruby/object:Gem::Requirement
|
105
|
+
requirements:
|
106
|
+
- - ~>
|
107
|
+
- !ruby/object:Gem::Version
|
108
|
+
version: 2.13.0
|
109
|
+
prerelease: false
|
110
|
+
type: :development
|
111
|
+
description: A ruby library to help with the creation of Maestro plugins that need Shell functionality
|
112
|
+
email:
|
113
|
+
- dhenderson@maestrodev.com
|
114
|
+
executables: []
|
115
|
+
extensions: []
|
116
|
+
extra_rdoc_files: []
|
117
|
+
files:
|
118
|
+
- .gitignore
|
119
|
+
- .rvmrc
|
120
|
+
- Gemfile
|
121
|
+
- Gemfile.lock
|
122
|
+
- LICENSE.txt
|
123
|
+
- README.md
|
124
|
+
- Rakefile
|
125
|
+
- lib/shell.rb
|
126
|
+
- lib/util/logging.rb
|
127
|
+
- lib/util/shell.rb
|
128
|
+
- lib/util/version.rb
|
129
|
+
- maestro_shell.gemspec
|
130
|
+
- pom.xml
|
131
|
+
- spec/shell_spec.rb
|
132
|
+
- spec/spec_helper.rb
|
133
|
+
homepage: https://github.com/maestrodev/maestro-shell
|
134
|
+
licenses:
|
135
|
+
- Apache 2.0
|
136
|
+
metadata: {}
|
137
|
+
post_install_message:
|
138
|
+
rdoc_options: []
|
139
|
+
require_paths:
|
140
|
+
- lib
|
141
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
142
|
+
requirements:
|
143
|
+
- - '>='
|
144
|
+
- !ruby/object:Gem::Version
|
145
|
+
version: '0'
|
146
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
147
|
+
requirements:
|
148
|
+
- - '>='
|
149
|
+
- !ruby/object:Gem::Version
|
150
|
+
version: '0'
|
151
|
+
requirements: []
|
152
|
+
rubyforge_project:
|
153
|
+
rubygems_version: 2.0.3
|
154
|
+
signing_key:
|
155
|
+
specification_version: 4
|
156
|
+
summary: Maestro Shell utility
|
157
|
+
test_files:
|
158
|
+
- spec/shell_spec.rb
|
159
|
+
- spec/spec_helper.rb
|