pasv_lib 0.1.1 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.gitignore +2 -0
- data/lib/pasv_lib/version.rb +1 -1
- data/lib/pasv_lib.rb +2 -2
- data/pasv_lib.gemspec +0 -2
- data/vendor/systemu.rb +416 -0
- metadata +4 -24
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 50e4d7a31367670be250e437270f02fd37b8638fbd7a541fa91ab0ec7e35dccb
|
4
|
+
data.tar.gz: 304eab6bd2becd3995b14c92bfdd1a39adda5d73687598eea0c64faeffd03651
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2f550d96c0a73954f1a39ddce847580197ec75bcdf0e69733926ba5d794e986c4d13f76d47a9d4872d20156b095381b052b983ded6dd364d56e414aea21b08de
|
7
|
+
data.tar.gz: d72ecf0b88674b51d0622878659d12f29d22b3bf815ec64b75eb6e120b00dc4f571744ebeb48f1c334bc91e94569ed2673b2c9e78a7bf82ad8fdd0ba04a01d5f
|
data/.gitignore
CHANGED
data/lib/pasv_lib/version.rb
CHANGED
data/lib/pasv_lib.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
require "pasv_lib/version"
|
2
|
-
require "systemu"
|
2
|
+
require File.join __dir__, "..", "vendor", "systemu"
|
3
3
|
|
4
4
|
module PasvLib
|
5
5
|
module CoreExtensions
|
@@ -35,7 +35,7 @@ module PasvLib
|
|
35
35
|
include CoreExtensions::Time
|
36
36
|
|
37
37
|
def run_it *a, &b
|
38
|
-
exit_status, stdout, stderr = systemu *a, &b
|
38
|
+
exit_status, stdout, stderr = SystemUniversal::Run.systemu *a, &b
|
39
39
|
|
40
40
|
|
41
41
|
puts stdout unless stdout.empty?
|
data/pasv_lib.gemspec
CHANGED
@@ -23,6 +23,4 @@ Gem::Specification.new do |spec|
|
|
23
23
|
spec.add_development_dependency "bundler", "~> 1.15"
|
24
24
|
spec.add_development_dependency "rake", "~> 10.0"
|
25
25
|
spec.add_development_dependency "rspec", "~> 3.0"
|
26
|
-
|
27
|
-
spec.add_runtime_dependency "systemu", "~> 2.6", ">= 2.6.5"
|
28
26
|
end
|
data/vendor/systemu.rb
ADDED
@@ -0,0 +1,416 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
# Copyright (c) 2010, Ara T. Howard
|
4
|
+
# All rights reserved.
|
5
|
+
#
|
6
|
+
# Redistribution and use in source and binary forms, with or without
|
7
|
+
# modification, are permitted provided that the following conditions are met:
|
8
|
+
#
|
9
|
+
# * Redistributions of source code must retain the above copyright notice, this
|
10
|
+
# list of conditions and the following disclaimer.
|
11
|
+
#
|
12
|
+
# * Redistributions in binary form must reproduce the above copyright notice,
|
13
|
+
# this list of conditions and the following disclaimer in the documentation
|
14
|
+
# and/or other materials provided with the distribution.
|
15
|
+
#
|
16
|
+
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
17
|
+
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
18
|
+
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
19
|
+
# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
20
|
+
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
21
|
+
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
22
|
+
# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
23
|
+
# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
24
|
+
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
25
|
+
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
26
|
+
#
|
27
|
+
|
28
|
+
# This is a modified version of systemu by me (Ryan Moore).
|
29
|
+
|
30
|
+
require 'tmpdir'
|
31
|
+
require 'socket'
|
32
|
+
require 'fileutils'
|
33
|
+
require 'rbconfig'
|
34
|
+
require 'thread'
|
35
|
+
|
36
|
+
# Change to this to not pollute Object.
|
37
|
+
|
38
|
+
class SystemUniversal
|
39
|
+
class Run
|
40
|
+
def self.systemu(*a, &b)
|
41
|
+
Object::SystemUniversal.new(*a, &b).systemu
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
#
|
46
|
+
# error class
|
47
|
+
#
|
48
|
+
class Error < RuntimeError
|
49
|
+
end
|
50
|
+
|
51
|
+
#
|
52
|
+
# constants
|
53
|
+
#
|
54
|
+
SystemUniversal::VERSION = '2.6.5' unless SystemUniversal.send(:const_defined?, :VERSION)
|
55
|
+
def SystemUniversal.version() SystemUniversal::VERSION end
|
56
|
+
def version() SystemUniversal::VERSION end
|
57
|
+
def SystemUniversal.description
|
58
|
+
"universal capture of stdout and stderr and handling of child process pid for windows, *nix, etc."
|
59
|
+
end
|
60
|
+
#
|
61
|
+
# class methods
|
62
|
+
#
|
63
|
+
|
64
|
+
@host = Socket.gethostname
|
65
|
+
@ppid = Process.ppid
|
66
|
+
@pid = Process.pid
|
67
|
+
@turd = ENV['SYSTEMU_TURD']
|
68
|
+
@ruby = nil
|
69
|
+
|
70
|
+
def self.ruby
|
71
|
+
return @ruby if @ruby
|
72
|
+
|
73
|
+
c = begin; ::RbConfig::CONFIG; rescue NameError; ::Config::CONFIG; end
|
74
|
+
ruby = File.join(c['bindir'], c['ruby_install_name']) << c['EXEEXT']
|
75
|
+
@ruby = if system(ruby, '-e', '42')
|
76
|
+
ruby
|
77
|
+
else
|
78
|
+
system('ruby', '-e', '42') ? 'ruby' : warn('no ruby in PATH/CONFIG')
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
class << SystemUniversal
|
83
|
+
%w( host ppid pid turd ).each{|a| attr_accessor a}
|
84
|
+
|
85
|
+
def quote(*words)
|
86
|
+
words.map{|word| word.inspect}.join(' ')
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
#
|
91
|
+
# instance methods
|
92
|
+
#
|
93
|
+
|
94
|
+
def initialize argv, opts = {}, &block
|
95
|
+
getopt = getopts opts
|
96
|
+
|
97
|
+
@argv = argv
|
98
|
+
@block = block
|
99
|
+
|
100
|
+
@stdin = getopt[ ['stdin', 'in', '0', 0] ]
|
101
|
+
@stdout = getopt[ ['stdout', 'out', '1', 1] ]
|
102
|
+
@stderr = getopt[ ['stderr', 'err', '2', 2] ]
|
103
|
+
@env = getopt[ 'env' ]
|
104
|
+
@cwd = getopt[ 'cwd' ]
|
105
|
+
|
106
|
+
@host = getopt[ 'host', self.class.host ]
|
107
|
+
@ppid = getopt[ 'ppid', self.class.ppid ]
|
108
|
+
@pid = getopt[ 'pid', self.class.pid ]
|
109
|
+
@ruby = getopt[ 'ruby', self.class.ruby ]
|
110
|
+
end
|
111
|
+
|
112
|
+
def systemu
|
113
|
+
tmpdir do |tmp|
|
114
|
+
c = child_setup tmp
|
115
|
+
status = nil
|
116
|
+
|
117
|
+
begin
|
118
|
+
thread = nil
|
119
|
+
|
120
|
+
quietly{
|
121
|
+
IO.popen "#{ quote(@ruby) } #{ quote(c['program']) }", 'rb+' do |pipe|
|
122
|
+
line = pipe.gets
|
123
|
+
case line
|
124
|
+
when %r/^pid: \d+$/
|
125
|
+
cid = Integer line[%r/\d+/]
|
126
|
+
else
|
127
|
+
begin
|
128
|
+
buf = pipe.read
|
129
|
+
buf = "#{ line }#{ buf }"
|
130
|
+
e = Marshal.load buf
|
131
|
+
raise unless Exception === e
|
132
|
+
raise e
|
133
|
+
rescue
|
134
|
+
raise Error "systemu: Error - process interrupted!\n#{ buf }\n"
|
135
|
+
end
|
136
|
+
end
|
137
|
+
thread = new_thread cid, @block if @block
|
138
|
+
pipe.read rescue nil
|
139
|
+
end
|
140
|
+
}
|
141
|
+
status = $?
|
142
|
+
ensure
|
143
|
+
if thread
|
144
|
+
begin
|
145
|
+
class << status
|
146
|
+
attr 'thread'
|
147
|
+
end
|
148
|
+
status.instance_eval{ @thread = thread }
|
149
|
+
rescue
|
150
|
+
42
|
151
|
+
end
|
152
|
+
end
|
153
|
+
end
|
154
|
+
|
155
|
+
if @stdout or @stderr
|
156
|
+
open(c['stdout'], 'rb'){|f| relay f => @stdout} if @stdout
|
157
|
+
open(c['stderr'], 'rb'){|f| relay f => @stderr} if @stderr
|
158
|
+
status
|
159
|
+
else
|
160
|
+
[status, open(c['stdout'], 'rb'){|f| f.read}, open(c['stderr'], 'rb'){|f| f.read}]
|
161
|
+
end
|
162
|
+
end
|
163
|
+
end
|
164
|
+
|
165
|
+
def quote *args, &block
|
166
|
+
SystemUniversal.quote(*args, &block)
|
167
|
+
end
|
168
|
+
|
169
|
+
def new_thread child_pid, block
|
170
|
+
q = Queue.new
|
171
|
+
Thread.new(child_pid) do |cid|
|
172
|
+
current = Thread.current
|
173
|
+
current.abort_on_exception = true
|
174
|
+
q.push current
|
175
|
+
block.call cid
|
176
|
+
end
|
177
|
+
q.pop
|
178
|
+
end
|
179
|
+
|
180
|
+
def child_setup tmp
|
181
|
+
stdin = File.expand_path(File.join(tmp, 'stdin'))
|
182
|
+
stdout = File.expand_path(File.join(tmp, 'stdout'))
|
183
|
+
stderr = File.expand_path(File.join(tmp, 'stderr'))
|
184
|
+
program = File.expand_path(File.join(tmp, 'program'))
|
185
|
+
config = File.expand_path(File.join(tmp, 'config'))
|
186
|
+
|
187
|
+
if @stdin
|
188
|
+
open(stdin, 'wb'){|f| relay @stdin => f}
|
189
|
+
else
|
190
|
+
FileUtils.touch stdin
|
191
|
+
end
|
192
|
+
FileUtils.touch stdout
|
193
|
+
FileUtils.touch stderr
|
194
|
+
|
195
|
+
c = {}
|
196
|
+
c['argv'] = @argv
|
197
|
+
c['env'] = @env
|
198
|
+
c['cwd'] = @cwd
|
199
|
+
c['stdin'] = stdin
|
200
|
+
c['stdout'] = stdout
|
201
|
+
c['stderr'] = stderr
|
202
|
+
c['program'] = program
|
203
|
+
open(config, 'wb'){|f| Marshal.dump(c, f)}
|
204
|
+
|
205
|
+
open(program, 'wb'){|f| f.write child_program(config)}
|
206
|
+
|
207
|
+
c
|
208
|
+
end
|
209
|
+
|
210
|
+
def quietly
|
211
|
+
v = $VERBOSE
|
212
|
+
$VERBOSE = nil
|
213
|
+
yield
|
214
|
+
ensure
|
215
|
+
$VERBOSE = v
|
216
|
+
end
|
217
|
+
|
218
|
+
def child_program config
|
219
|
+
<<-program
|
220
|
+
# encoding: utf-8
|
221
|
+
|
222
|
+
PIPE = STDOUT.dup
|
223
|
+
begin
|
224
|
+
config = Marshal.load(IO.read('#{ config }',:mode=>"rb"))
|
225
|
+
|
226
|
+
argv = config['argv']
|
227
|
+
env = config['env']
|
228
|
+
cwd = config['cwd']
|
229
|
+
stdin = config['stdin']
|
230
|
+
stdout = config['stdout']
|
231
|
+
stderr = config['stderr']
|
232
|
+
|
233
|
+
Dir.chdir cwd if cwd
|
234
|
+
env.each{|k,v| ENV[k.to_s] = v.to_s} if env
|
235
|
+
|
236
|
+
STDIN.reopen stdin
|
237
|
+
STDOUT.reopen stdout
|
238
|
+
STDERR.reopen stderr
|
239
|
+
|
240
|
+
PIPE.puts "pid: \#{ Process.pid }"
|
241
|
+
PIPE.flush ### the process is ready yo!
|
242
|
+
PIPE.close
|
243
|
+
|
244
|
+
exec *argv
|
245
|
+
rescue Exception => e
|
246
|
+
PIPE.write Marshal.dump(e) rescue nil
|
247
|
+
exit 42
|
248
|
+
end
|
249
|
+
program
|
250
|
+
end
|
251
|
+
|
252
|
+
def relay srcdst
|
253
|
+
src, dst, _ = srcdst.to_a.first
|
254
|
+
if src.respond_to? 'read'
|
255
|
+
while((buffer = src.read(8192))); dst << buffer; end
|
256
|
+
else
|
257
|
+
if src.respond_to?(:each_line)
|
258
|
+
src.each_line{|buf| dst << buf}
|
259
|
+
else
|
260
|
+
src.each{|buf| dst << buf}
|
261
|
+
end
|
262
|
+
end
|
263
|
+
end
|
264
|
+
|
265
|
+
def slug_for(*args)
|
266
|
+
options = args.last.is_a?(Hash) ? args.pop : {}
|
267
|
+
join = (options[:join] || options['join'] || '_').to_s
|
268
|
+
string = args.flatten.compact.join(join)
|
269
|
+
words = string.to_s.scan(%r|[/\w]+|)
|
270
|
+
words.map!{|word| word.gsub %r|[^/0-9a-zA-Z_-]|, ''}
|
271
|
+
words.delete_if{|word| word.nil? or word.strip.empty?}
|
272
|
+
words.join(join).downcase.gsub('/', (join * 2))
|
273
|
+
end
|
274
|
+
|
275
|
+
def tmpdir d = Dir.tmpdir, max = 42, &b
|
276
|
+
i = -1 and loop{
|
277
|
+
i += 1
|
278
|
+
|
279
|
+
tmp = File.join(d, slug_for("systemu_#{ @host }_#{ @ppid }_#{ @pid }_#{ rand }_#{ i += 1 }"))
|
280
|
+
|
281
|
+
begin
|
282
|
+
Dir.mkdir tmp
|
283
|
+
rescue Errno::EEXIST
|
284
|
+
raise Error if i >= max
|
285
|
+
next
|
286
|
+
end
|
287
|
+
|
288
|
+
break(
|
289
|
+
if b
|
290
|
+
begin
|
291
|
+
b.call tmp
|
292
|
+
ensure
|
293
|
+
FileUtils.rm_rf tmp unless SystemU.turd
|
294
|
+
end
|
295
|
+
else
|
296
|
+
tmp
|
297
|
+
end
|
298
|
+
)
|
299
|
+
}
|
300
|
+
end
|
301
|
+
|
302
|
+
def getopts opts = {}
|
303
|
+
lambda do |*args|
|
304
|
+
keys, default, _ = args
|
305
|
+
catch(:opt) do
|
306
|
+
[keys].flatten.each do |key|
|
307
|
+
[key, key.to_s, key.to_s.intern].each do |k|
|
308
|
+
throw :opt, opts[k] if opts.has_key?(k)
|
309
|
+
end
|
310
|
+
end
|
311
|
+
default
|
312
|
+
end
|
313
|
+
end
|
314
|
+
end
|
315
|
+
end
|
316
|
+
|
317
|
+
# some monkeypatching for JRuby
|
318
|
+
if defined? JRUBY_VERSION
|
319
|
+
require 'jruby'
|
320
|
+
java_import org.jruby.RubyProcess
|
321
|
+
|
322
|
+
class SystemUniversal
|
323
|
+
def systemu
|
324
|
+
split_argv = JRuby::PathHelper.smart_split_command @argv
|
325
|
+
process = java.lang.Runtime.runtime.exec split_argv.to_java(:string)
|
326
|
+
|
327
|
+
stdout, stderr = [process.input_stream, process.error_stream].map do |stream|
|
328
|
+
StreamReader.new(stream)
|
329
|
+
end
|
330
|
+
|
331
|
+
field = process.get_class.get_declared_field("pid")
|
332
|
+
field.set_accessible(true)
|
333
|
+
pid = field.get(process)
|
334
|
+
_thread = new_thread pid, @block if @block
|
335
|
+
exit_code = process.wait_for
|
336
|
+
[
|
337
|
+
RubyProcess::RubyStatus.new_process_status(JRuby.runtime, exit_code, pid),
|
338
|
+
stdout.join,
|
339
|
+
stderr.join
|
340
|
+
]
|
341
|
+
end
|
342
|
+
|
343
|
+
class StreamReader
|
344
|
+
def initialize(stream)
|
345
|
+
@data = ""
|
346
|
+
@thread = Thread.new do
|
347
|
+
reader = java.io.BufferedReader.new java.io.InputStreamReader.new(stream)
|
348
|
+
|
349
|
+
while line = reader.read_line
|
350
|
+
@data << line << "\n"
|
351
|
+
end
|
352
|
+
end
|
353
|
+
end
|
354
|
+
|
355
|
+
def join
|
356
|
+
@thread.join
|
357
|
+
@data
|
358
|
+
end
|
359
|
+
end
|
360
|
+
end
|
361
|
+
end
|
362
|
+
|
363
|
+
|
364
|
+
|
365
|
+
SystemU = SystemUniversal unless defined? SystemU
|
366
|
+
Systemu = SystemUniversal unless defined? Systemu
|
367
|
+
|
368
|
+
|
369
|
+
|
370
|
+
|
371
|
+
|
372
|
+
|
373
|
+
|
374
|
+
|
375
|
+
|
376
|
+
|
377
|
+
|
378
|
+
|
379
|
+
|
380
|
+
if $0 == __FILE__
|
381
|
+
#
|
382
|
+
# date
|
383
|
+
#
|
384
|
+
date = %q( ruby -e" t = Time.now; STDOUT.puts t; STDERR.puts t " )
|
385
|
+
|
386
|
+
status, stdout, stderr = systemu date
|
387
|
+
p [status, stdout, stderr]
|
388
|
+
|
389
|
+
status = systemu date, 1=>(stdout = '')
|
390
|
+
p [status, stdout]
|
391
|
+
|
392
|
+
status = systemu date, 2=>(stderr = '')
|
393
|
+
p [status, stderr]
|
394
|
+
#
|
395
|
+
# sleep
|
396
|
+
#
|
397
|
+
sleep = %q( ruby -e" p(sleep(1)) " )
|
398
|
+
status, stdout, stderr = systemu sleep
|
399
|
+
p [status, stdout, stderr]
|
400
|
+
|
401
|
+
sleep = %q( ruby -e" p(sleep(42)) " )
|
402
|
+
status, stdout, stderr = systemu(sleep){|cid| Process.kill 9, cid}
|
403
|
+
p [status, stdout, stderr]
|
404
|
+
#
|
405
|
+
# env
|
406
|
+
#
|
407
|
+
env = %q( ruby -e" p ENV['A'] " )
|
408
|
+
status, stdout, stderr = systemu env, :env => {'A' => 42}
|
409
|
+
p [status, stdout, stderr]
|
410
|
+
#
|
411
|
+
# cwd
|
412
|
+
#
|
413
|
+
env = %q( ruby -e" p Dir.pwd " )
|
414
|
+
status, stdout, stderr = systemu env, :cwd => Dir.tmpdir
|
415
|
+
p [status, stdout, stderr]
|
416
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pasv_lib
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ryan Moore
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2019-02-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -52,26 +52,6 @@ dependencies:
|
|
52
52
|
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '3.0'
|
55
|
-
- !ruby/object:Gem::Dependency
|
56
|
-
name: systemu
|
57
|
-
requirement: !ruby/object:Gem::Requirement
|
58
|
-
requirements:
|
59
|
-
- - "~>"
|
60
|
-
- !ruby/object:Gem::Version
|
61
|
-
version: '2.6'
|
62
|
-
- - ">="
|
63
|
-
- !ruby/object:Gem::Version
|
64
|
-
version: 2.6.5
|
65
|
-
type: :runtime
|
66
|
-
prerelease: false
|
67
|
-
version_requirements: !ruby/object:Gem::Requirement
|
68
|
-
requirements:
|
69
|
-
- - "~>"
|
70
|
-
- !ruby/object:Gem::Version
|
71
|
-
version: '2.6'
|
72
|
-
- - ">="
|
73
|
-
- !ruby/object:Gem::Version
|
74
|
-
version: 2.6.5
|
75
55
|
description:
|
76
56
|
email:
|
77
57
|
- moorer@udel.edu
|
@@ -91,6 +71,7 @@ files:
|
|
91
71
|
- lib/pasv_lib.rb
|
92
72
|
- lib/pasv_lib/version.rb
|
93
73
|
- pasv_lib.gemspec
|
74
|
+
- vendor/systemu.rb
|
94
75
|
homepage: http://www.github.com/mooreryan/pasv_lib
|
95
76
|
licenses: []
|
96
77
|
metadata: {}
|
@@ -109,8 +90,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
109
90
|
- !ruby/object:Gem::Version
|
110
91
|
version: '0'
|
111
92
|
requirements: []
|
112
|
-
|
113
|
-
rubygems_version: 2.6.14
|
93
|
+
rubygems_version: 3.0.1
|
114
94
|
signing_key:
|
115
95
|
specification_version: 4
|
116
96
|
summary: Library code for PASV
|