console-mux 2.0.7 → 2.0.8

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 52f90b608b800c986fb3eba38f8977584a590f9a
4
+ data.tar.gz: 35f9a160bb52d9407535e5e53978fd5c31ebad0e
5
+ SHA512:
6
+ metadata.gz: e06a46cf0cf7e3c62cee109a95167f7c63c4e0b6068e755ad11ab396d6a6d721c62ae0084f242770618741aeddbe35eecbaaa95ae0ead7221c44118f5a800daa
7
+ data.tar.gz: 5737dfaa9893cac325ed3e67f6acb22c05c89600deaa705130473e4b8d14b2c1f9773f656725b1c1bc1fc06b50d6024f4448aef90ecae3db8c0928f7dbfae443
data/VERSION CHANGED
@@ -1 +1 @@
1
- 2.0.7
1
+ 2.0.8
@@ -39,7 +39,7 @@ module Console
39
39
  :init_file => nil
40
40
  }
41
41
 
42
- OptionParser.new do |opts|
42
+ oparser = OptionParser.new do |opts|
43
43
  opts.banner = "Usage: console-mux <init_file>"
44
44
  opts.on_tail('-h', '--help', 'Show this message') do
45
45
  puts opts
@@ -52,7 +52,14 @@ module Console
52
52
  puts VERSION
53
53
  exit
54
54
  end
55
- end.parse!(args)
55
+ end
56
+ oparser.parse!(args)
57
+
58
+ options[:init_file] ||= args.shift
59
+ unless options[:init_file]
60
+ $stderr.puts oparser
61
+ exit 1
62
+ end
56
63
 
57
64
  begin
58
65
  run(options)
@@ -31,16 +31,15 @@ module Console
31
31
  # waits for an +:exit+ event from each.
32
32
  #
33
33
  # @param [Array<Process>] processes
34
- def join(processes)
35
- pending_exit = processes.size
34
+ def join(processes, &block)
35
+ q = EventMachine::Queue.new
36
+
36
37
  processes.each do |proc|
37
- proc.on(:exit) do
38
- pending_exit -= 1
39
- if pending_exit == 0 && block_given?
40
- yield
41
- end
42
- end
38
+ proc.on(:exit) { q.push :exit }
43
39
  end
40
+
41
+ (processes.size - 1).times { q.pop {} }
42
+ q.pop { block.call } # all have exited
44
43
  end
45
44
  end
46
45
 
@@ -92,33 +92,6 @@ module Console
92
92
  end
93
93
  end
94
94
 
95
- def run_commands()
96
- next_command = commands.command_q.shift
97
- if (!next_command.nil?)
98
- commands.startCommand( next_command )
99
-
100
- # if next_command.opts[:blocking]
101
- # EventMachine.next_tick do
102
- # check_command(next_command)
103
- # end
104
- # else
105
- # end
106
-
107
- if (!(commands.command_q.empty?))
108
- EventMachine.next_tick do
109
- run_commands()
110
- end
111
- end
112
- end
113
-
114
- # EM::Iterator requires the beta version of eventmachine
115
- # EM::Iterator.new(commands.command_q).each do |command,iter|
116
- # commands.start( commands.command_q.shift )
117
- # iter.next
118
- # end
119
- end
120
-
121
-
122
95
  # Using set_ rather than '=' style accessor so config file needn't
123
96
  # use self.default_options =.
124
97
  def set_default_options(opts)
@@ -250,19 +223,22 @@ module Console
250
223
  end
251
224
 
252
225
  def shutdown
253
- if commands.stopped?
226
+ timer = EventMachine.add_timer(30) do
227
+ logger.error { "could not halt all processes; giving up :(" }
254
228
  EventMachine.stop_event_loop
255
- else
256
- timer = EventMachine.add_timer(30) do
257
- logger.error { "could not halt all processes; giving up :(" }
258
- EventMachine.stop_event_loop
259
- end
229
+ end
230
+
231
+ commands.on(:stopped) do
232
+ EventMachine.cancel_timer(timer)
260
233
 
261
- commands.on(:stopped) do
262
- EventMachine.cancel_timer(timer)
263
- EventMachine.stop_event_loop
264
- end
234
+ # If not wrapped in next_tick, EventMachine doesn't exit
235
+ # immediately (bug?)
236
+ EventMachine.next_tick { EventMachine.stop_event_loop }
237
+ end
265
238
 
239
+ if commands.stopped?
240
+ EventMachine.stop_event_loop
241
+ else
266
242
  commands.stop_all
267
243
  end
268
244
  end
@@ -64,9 +64,6 @@ module Console
64
64
 
65
65
  # Called by the child handler
66
66
  def unbind
67
- @stdin.close rescue nil
68
- @stdout.close rescue nil
69
-
70
67
  pid2, status = ::Process.waitpid2(pid, ::Process::WNOHANG)
71
68
  if pid2
72
69
  on_exit(status)
@@ -135,22 +132,18 @@ module Console
135
132
 
136
133
  @started_at = Time.now
137
134
 
138
- stdin, stdout, pid = Dir.chdir command.dir do
135
+ @stdin, @stdout, @pid = Dir.chdir(command.dir) do
139
136
  with_clean_env(command.env) do
140
137
  PTY.spawn(command.commandline)
141
138
  end
142
139
  end
143
-
144
- @stdin = stdin
145
- @stdout = stdout
146
- @pid = pid
147
140
 
148
141
  logger.info { "in #{File.expand_path(command.dir)}" }
149
142
  logger.info { "with #{command.env.to_a.map{|k,v| "#{k}=#{v}"}.join(' ')}" }
150
143
  logger.info { command }
151
144
  logger.info { "started process #{pid}" }
152
145
 
153
- @handler = EventMachine.attach(stdout, PTYHandler, self)
146
+ @handler = EventMachine.attach(@stdout, PTYHandler, self)
154
147
  end
155
148
 
156
149
  def try_kill(signals)
@@ -197,10 +190,13 @@ module Console
197
190
  logger.warn { "process #{pid} exited #{status.inspect}" }
198
191
  end
199
192
  ensure
193
+ @stdin.close rescue nil
194
+ @stdout.close rescue nil
195
+
200
196
  @handler = nil
201
197
  fire(:exit)
202
198
  end
203
199
  end
204
200
  end
205
201
  end
206
- end
202
+ end
metadata CHANGED
@@ -1,52 +1,46 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: console-mux
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.7
5
- prerelease:
4
+ version: 2.0.8
6
5
  platform: ruby
7
6
  authors:
8
- - CG Labs
7
+ - Patrick Mahoney
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2013-03-12 00:00:00.000000000 Z
11
+ date: 2013-07-28 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
14
  name: eventmachine
16
15
  requirement: !ruby/object:Gem::Requirement
17
- none: false
18
16
  requirements:
19
- - - ! '>='
17
+ - - '>='
20
18
  - !ruby/object:Gem::Version
21
19
  version: '0'
22
20
  type: :runtime
23
21
  prerelease: false
24
22
  version_requirements: !ruby/object:Gem::Requirement
25
- none: false
26
23
  requirements:
27
- - - ! '>='
24
+ - - '>='
28
25
  - !ruby/object:Gem::Version
29
26
  version: '0'
30
27
  - !ruby/object:Gem::Dependency
31
28
  name: log4r
32
29
  requirement: !ruby/object:Gem::Requirement
33
- none: false
34
30
  requirements:
35
- - - ! '>='
31
+ - - '>='
36
32
  - !ruby/object:Gem::Version
37
33
  version: '0'
38
34
  type: :runtime
39
35
  prerelease: false
40
36
  version_requirements: !ruby/object:Gem::Requirement
41
- none: false
42
37
  requirements:
43
- - - ! '>='
38
+ - - '>='
44
39
  - !ruby/object:Gem::Version
45
40
  version: '0'
46
41
  - !ruby/object:Gem::Dependency
47
42
  name: ripl-readline-em
48
43
  requirement: !ruby/object:Gem::Requirement
49
- none: false
50
44
  requirements:
51
45
  - - ~>
52
46
  - !ruby/object:Gem::Version
@@ -54,7 +48,6 @@ dependencies:
54
48
  type: :runtime
55
49
  prerelease: false
56
50
  version_requirements: !ruby/object:Gem::Requirement
57
- none: false
58
51
  requirements:
59
52
  - - ~>
60
53
  - !ruby/object:Gem::Version
@@ -62,23 +55,20 @@ dependencies:
62
55
  - !ruby/object:Gem::Dependency
63
56
  name: rake
64
57
  requirement: !ruby/object:Gem::Requirement
65
- none: false
66
58
  requirements:
67
- - - ! '>='
59
+ - - '>='
68
60
  - !ruby/object:Gem::Version
69
61
  version: '0'
70
62
  type: :development
71
63
  prerelease: false
72
64
  version_requirements: !ruby/object:Gem::Requirement
73
- none: false
74
65
  requirements:
75
- - - ! '>='
66
+ - - '>='
76
67
  - !ruby/object:Gem::Version
77
68
  version: '0'
78
69
  - !ruby/object:Gem::Dependency
79
70
  name: version
80
71
  requirement: !ruby/object:Gem::Requirement
81
- none: false
82
72
  requirements:
83
73
  - - ~>
84
74
  - !ruby/object:Gem::Version
@@ -86,14 +76,13 @@ dependencies:
86
76
  type: :development
87
77
  prerelease: false
88
78
  version_requirements: !ruby/object:Gem::Requirement
89
- none: false
90
79
  requirements:
91
80
  - - ~>
92
81
  - !ruby/object:Gem::Version
93
82
  version: '1'
94
83
  description: Multiplex several commands on one console
95
84
  email:
96
- - eng@commongroundpublishing.com
85
+ - pat@polycrystal.org
97
86
  executables:
98
87
  - console-mux
99
88
  extensions: []
@@ -120,32 +109,25 @@ files:
120
109
  - bin/console-mux
121
110
  homepage:
122
111
  licenses: []
112
+ metadata: {}
123
113
  post_install_message:
124
114
  rdoc_options: []
125
115
  require_paths:
126
116
  - lib
127
117
  required_ruby_version: !ruby/object:Gem::Requirement
128
- none: false
129
118
  requirements:
130
- - - ! '>='
119
+ - - '>='
131
120
  - !ruby/object:Gem::Version
132
121
  version: '0'
133
- segments:
134
- - 0
135
- hash: -1031871365713465132
136
122
  required_rubygems_version: !ruby/object:Gem::Requirement
137
- none: false
138
123
  requirements:
139
- - - ! '>='
124
+ - - '>='
140
125
  - !ruby/object:Gem::Version
141
126
  version: '0'
142
- segments:
143
- - 0
144
- hash: -1031871365713465132
145
127
  requirements: []
146
128
  rubyforge_project:
147
- rubygems_version: 1.8.23
129
+ rubygems_version: 2.0.3
148
130
  signing_key:
149
- specification_version: 3
131
+ specification_version: 4
150
132
  summary: Multiplex several commands on one console
151
133
  test_files: []