joumae 0.2.2 → 0.2.3

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: 216773d4a6a9177310fb757fed1d3b80aebd7e8a
4
- data.tar.gz: bde3734f5b5513f6a4c18c561655562004001f1e
3
+ metadata.gz: 0ef042d05aeab5b8c0b04b20bc7d941cb12662f2
4
+ data.tar.gz: 9db5f0ee408e17c7f6a25d1e1131f908af75ad9d
5
5
  SHA512:
6
- metadata.gz: 8502d2b2a88ef5ae0d40aec45e9f6ea8bdd9a50d16a5d1ec3d5013fa17ce8f4c697f92af6200f0ab98699f66bded8b45159975c44fae3a634da571cd5649bd89
7
- data.tar.gz: 5abc27547003d6807dc566443ff61826edd98b7235001787f9b45cdb069cdc22fc1b271ab2dd89961d42f1bdd4ee3ddef24ebee80c52f35da079b83fe31124cb
6
+ metadata.gz: ee52c72f005d0debe8829fe4ddbf659fdbc11f4850c4ac08811c84b8c52fdb6684ea73fb09ead5283ca90d1a29d7b031006a9c160815a0904ae42f2948ce0ba7
7
+ data.tar.gz: e636aec70a610a459cce4c397e5a6d5c73240aef3cd6d05877d47b9e2785a4b8802d9acd1380538c44a513c14ac7a3f9d187c79ae2fb0c274c10e308799af94f
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- joumae (0.2.1)
4
+ joumae (0.2.2)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
@@ -5,6 +5,8 @@ require 'open3'
5
5
 
6
6
  module Joumae
7
7
  class Command
8
+ EXIT_STATUS_INTERRUPT = 130
9
+
8
10
  attr_reader :cmd
9
11
 
10
12
  def initialize(cmd, resource_name:, client:)
@@ -26,19 +28,13 @@ module Joumae
26
28
 
27
29
  def run!
28
30
  status = Joumae::Transaction.run!(resource_name: @resource_name, client: @client) do
29
- Open3.popen3("bash") do |i, o, e, w|
30
- i.write cmd
31
- i.close
32
-
33
- o.each do |line|
34
- STDOUT.puts line
35
- STDOUT.flush
31
+ Open3.popen3(cmd) do |i, o, e, w|
32
+ unless STDIN.tty?
33
+ redirect(STDIN => i)
36
34
  end
35
+ i.close
37
36
 
38
- e.each do |line|
39
- STDERR.puts line
40
- STDERR.flush
41
- end
37
+ redirect(o => STDOUT, e => STDERR)
42
38
 
43
39
  debug w.value
44
40
 
@@ -50,6 +46,37 @@ module Joumae
50
46
 
51
47
  private
52
48
 
49
+ def redirect(mapping)
50
+ files = mapping.keys
51
+
52
+ until files.all?(&:eof) do
53
+ ready = IO.select(files)
54
+
55
+ continue unless ready
56
+
57
+ readable = ready[0]
58
+
59
+ readable.each do |f|
60
+ begin
61
+ data = f.read_nonblock(1024)
62
+
63
+ mapping[f].write(data)
64
+ rescue EOFError => e
65
+ debug e.to_s;
66
+ end
67
+ end
68
+ end
69
+ end
70
+
71
+ def all_eof?(files)
72
+ begin
73
+ files.all?(&:eof)
74
+ rescue Interrupt => e
75
+ warn "You've interrupted while joumae is running a command."
76
+ EXIT_STATUS_INTERRUPT
77
+ end
78
+ end
79
+
53
80
  def info(msg)
54
81
  logger.info msg
55
82
  end
@@ -1,3 +1,3 @@
1
1
  module Joumae
2
- VERSION = "0.2.2"
2
+ VERSION = "0.2.3"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: joumae
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.2
4
+ version: 0.2.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yusuke KUOKA
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2015-11-13 00:00:00.000000000 Z
11
+ date: 2015-11-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler