maestro_shell 0.0.6 → 0.0.7

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e64d5765872e7cd5ee7577d58f79435f56c76c56
4
- data.tar.gz: b00917d18728c744468b1f0f38d2a8ecd8b90b3b
3
+ metadata.gz: dc3c43c91ae1ad728a326390268aa61924c77521
4
+ data.tar.gz: bcc3c16f0f7d1309e0b51dabeccf1698bd9f9d92
5
5
  SHA512:
6
- metadata.gz: 23eb28703979cb266c516d74ca891e9974cceb2f9c0d046c5ca3bf4696ebc7a98e80c338aafb15d35c98b4b30640cb0ee01aaf337dd88a0d3ff2a19d8925a3cb
7
- data.tar.gz: aeb367603f3b4cf1340df35da8505fa553ab6376915192bae4dcecc81c5f02b6a45c2616be5e977bd1e007f54efabdfb236c13648a9583a21935d4f5abf93f5a
6
+ metadata.gz: 15b0438163743d7540034ffc2375da502e7e0f31d573ae3e89896a2d5ff5efea96726c16bfd0a7de4779082db4b3b7e78520cb1ba9ba674163250c1e8f673013
7
+ data.tar.gz: 5ff0317c41ceca677029b8dbcd70669efa64e8394b64419244c2514fabf1998ef43307d882285500180b46fd7a13de482b520f969525463bd2d91d2dfa003987
data/lib/util/shell.rb CHANGED
@@ -1,5 +1,6 @@
1
1
  # Copyright 2011 (c) MaestroDev. All rights reserved.
2
2
 
3
+ require 'pty'
3
4
  require 'tempfile'
4
5
  require 'rbconfig'
5
6
 
@@ -32,7 +33,6 @@ module Maestro
32
33
  COMMAND_SEPARATOR = '&&' # IS_WINDOWS ? '&&' : '&&'
33
34
  SCRIPT_EXTENSION = IS_WINDOWS ? '.bat' : '.shell'
34
35
  SHELL_EXECUTABLE = IS_WINDOWS ? '' : 'bash '
35
- COMMAND_SUFFIX = IS_WINDOWS ? '' : ' 2>&1'
36
36
 
37
37
  def Shell.unset_env_variable(var)
38
38
  IS_WINDOWS ? "set #{var}=" : "unset #{var}"
@@ -76,31 +76,26 @@ module Maestro
76
76
  # +err+ Boolean True if line is from stderr
77
77
  def run_script_with_delegate(delegate, on_output)
78
78
  File.open(@output_file.path, 'a') do |out_file|
79
- status = IO.popen4(@command_line) do |pid, stdin, stdout, stderr|
80
- # Keep reading input until all (stdin/stderr) streams report eof
81
- readers = [stdout, stderr]
82
- while readers.any?
83
- ready = IO.select(readers, [], readers)
84
- # no writers
85
- # ready[1].each { ... }
86
- ready[0].each do |fd|
87
- if fd.eof?
88
- readers.delete fd
89
- else
90
-
91
- text = fd.readpartial(1024)
92
- out_file.write(text)
93
-
94
- if delegate && on_output
95
- delegate.send(on_output, text)
96
- end
79
+ sleep 0.1
80
+ status = PTY.spawn(@command_line) do |master, slave, pid|
81
+ begin
82
+ while !slave.eof?
83
+ text = slave.readpartial(1024).gsub(/\r/, '')
84
+ out_file.write(text)
85
+
86
+ if delegate && on_output
87
+ delegate.send(on_output, text)
97
88
  end
98
89
  end
90
+ rescue Exception => e
91
+ Maestro.log.warn "Got Exception in spawn #{e} #{e.class}"
99
92
  end
93
+
94
+ Process.wait(pid)
100
95
  end
101
- end
102
96
 
103
- @exit_code = ExitCode.new($?)
97
+ @exit_code = ExitCode.new($?)
98
+ end
104
99
 
105
100
  return @exit_code
106
101
  end
@@ -117,7 +112,7 @@ module Maestro
117
112
  private
118
113
 
119
114
  def get_command(path)
120
- @command_line = "#{SHELL_EXECUTABLE}#{path}#{COMMAND_SUFFIX}"
115
+ @command_line = "#{SHELL_EXECUTABLE}#{path}"
121
116
  @command_line
122
117
  end
123
118
 
data/lib/util/version.rb CHANGED
@@ -1,7 +1,7 @@
1
1
  module Maestro
2
2
  module Util
3
3
  class Shell
4
- VERSION = '0.0.6'
4
+ VERSION = '0.0.7'
5
5
  end
6
6
  end
7
7
  end
data/spec/shell_spec.rb CHANGED
@@ -62,7 +62,13 @@ describe Maestro::Util::Shell do
62
62
  path = subject.create_script "blah hello"
63
63
 
64
64
  subject.run_script.success?.should be_false
65
- subject.to_s.should include("blah: command not found")
65
+ subject.output.should include("blah: command not found")
66
+ end
67
+
68
+ it 'should emit stdout and stderr in order' do
69
+ subject.create_script("echo stdout1\nsleep 1\necho stderr1 >&2\nsleep 1\necho stdout2\nsleep 1\necho stderr2 >&2\nsleep 1\necho stdout3")
70
+ subject.run_script.success?.should be_true
71
+ subject.to_s.should eql("stdout1\nstderr1\nstdout2\nstderr2\nstdout3\n")
66
72
  end
67
73
 
68
74
  it 'should run with with export inline' do
@@ -86,7 +92,8 @@ CMD
86
92
  path = subject.create_script command
87
93
 
88
94
  subject.run_script.success?.should be_true
89
- subject.to_s.should eql("hello\r\ngoodbye\n")
95
+ # Strips \r
96
+ subject.to_s.should eql("hello\ngoodbye\n")
90
97
  end
91
98
 
92
99
  it 'should create run and return result in on call' do
@@ -102,7 +109,7 @@ CMD
102
109
  File.chmod(0777, temp.path)
103
110
  command =<<-CMD
104
111
  #{Maestro::Util::Shell::ENV_EXPORT_COMMAND} BLAH=blah; echo $BLAH
105
- #{temp.path}
112
+ #{Maestro::Util::Shell::SHELL_EXECUTABLE} #{temp.path}
106
113
  CMD
107
114
 
108
115
  path = subject.create_script command
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: maestro_shell
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.6
4
+ version: 0.0.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Doug Henderson
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-07-16 00:00:00.000000000 Z
11
+ date: 2013-07-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: logging