procemon 0.7.0 → 0.8.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +8 -8
- data/Gemfile +2 -14
- data/Gemfile.lock +12 -64
- data/VERSION +1 -1
- data/lib/procemon/function/macaddr.rb +1 -0
- data/lib/procemon/mpatch/hash.rb +2 -0
- data/lib/procemon.rb +9 -11
- data/procemon.gemspec +1 -0
- metadata +17 -5
- data/lib/procemon/function/require.rb +0 -108
- data/lib/procemon/function/systemu.rb +0 -360
- /data/lib/procemon/{function → extra}/sender.rb +0 -0
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
NTZjMGIwYmVjZDYxNWVmN2EwYmNlMzMyZDE3M2Y4ZGViZWQ2MDBhOA==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
Nzg1YTNjNDk3ZjBkYjAzNjc1NTI0Njc2ZDkzODg0ZDBkNWNkNTUxNw==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
Njg5N2FlN2Y4OTVjNGU0NjM1YjYyYWZhNzVhMjE1YzU2OGQ1MTgzOGUwOTJi
|
10
|
+
ZDU4ZmQwOTczNzVkMjViMGExOTkyY2FlODVhYmUwMzQyNDEwMDM3NGEwNzlk
|
11
|
+
ZTUxM2Y5N2Q0YjgwZDcyNzBmYjVkMzk1NTViN2M0ZTEzMzU3YmU=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
NTdlODdlMjdhZDQ5YjMwOGNlZmNiZDMzMTBiNTkwMzgzOTRlMzk1MTE2MGVk
|
14
|
+
NTE4MzNmYTVjNDQ1Y2FkNTE3M2QwZWNhNmIxNTVhY2EwNDIzMGQ2NzhhZDJl
|
15
|
+
NGIzNmU0N2E1ZjA3ZTNiOTJjMjcwMDY0NmQ4NzgxMjMxZTMyYjI=
|
data/Gemfile
CHANGED
@@ -1,14 +1,2 @@
|
|
1
|
-
source
|
2
|
-
|
3
|
-
# Example:
|
4
|
-
# gem "activesupport", ">= 2.3.5"
|
5
|
-
gemspec
|
6
|
-
|
7
|
-
# Add dependencies to develop your gem here.
|
8
|
-
# Include everything needed to run rake, tests, features, etc.
|
9
|
-
group :development do
|
10
|
-
gem "shoulda", ">= 0"
|
11
|
-
gem "rdoc", "~> 3.12"
|
12
|
-
gem "bundler", "~> 1.0"
|
13
|
-
gem "jeweler", "~> 1.8.7"
|
14
|
-
end
|
1
|
+
source :rubygems
|
2
|
+
gemspec
|
data/Gemfile.lock
CHANGED
@@ -1,72 +1,20 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
procemon (0.7.0)
|
5
|
+
asynchronous
|
6
|
+
loader
|
7
|
+
sourcerer
|
8
|
+
|
1
9
|
GEM
|
2
10
|
remote: http://rubygems.org/
|
3
11
|
specs:
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
multi_json (~> 1.3)
|
8
|
-
thread_safe (~> 0.1)
|
9
|
-
tzinfo (~> 0.3.37)
|
10
|
-
addressable (2.3.5)
|
11
|
-
atomic (1.1.14)
|
12
|
-
builder (3.2.2)
|
13
|
-
faraday (0.8.8)
|
14
|
-
multipart-post (~> 1.2.0)
|
15
|
-
git (1.2.6)
|
16
|
-
github_api (0.10.1)
|
17
|
-
addressable
|
18
|
-
faraday (~> 0.8.1)
|
19
|
-
hashie (>= 1.2)
|
20
|
-
multi_json (~> 1.4)
|
21
|
-
nokogiri (~> 1.5.2)
|
22
|
-
oauth2
|
23
|
-
hashie (2.0.5)
|
24
|
-
highline (1.6.20)
|
25
|
-
httpauth (0.2.0)
|
26
|
-
i18n (0.6.5)
|
27
|
-
jeweler (1.8.8)
|
28
|
-
builder
|
29
|
-
bundler (~> 1.0)
|
30
|
-
git (>= 1.2.5)
|
31
|
-
github_api (= 0.10.1)
|
32
|
-
highline (>= 1.6.15)
|
33
|
-
nokogiri (= 1.5.10)
|
34
|
-
rake
|
35
|
-
rdoc
|
36
|
-
json (1.8.0)
|
37
|
-
jwt (0.1.8)
|
38
|
-
multi_json (>= 1.5)
|
39
|
-
minitest (4.7.5)
|
40
|
-
multi_json (1.8.2)
|
41
|
-
multi_xml (0.5.5)
|
42
|
-
multipart-post (1.2.0)
|
43
|
-
nokogiri (1.5.10)
|
44
|
-
oauth2 (0.9.2)
|
45
|
-
faraday (~> 0.8)
|
46
|
-
httpauth (~> 0.2)
|
47
|
-
jwt (~> 0.1.4)
|
48
|
-
multi_json (~> 1.0)
|
49
|
-
multi_xml (~> 0.5)
|
50
|
-
rack (~> 1.2)
|
51
|
-
rack (1.5.2)
|
52
|
-
rake (10.1.0)
|
53
|
-
rdoc (3.12.2)
|
54
|
-
json (~> 1.4)
|
55
|
-
shoulda (3.5.0)
|
56
|
-
shoulda-context (~> 1.0, >= 1.0.1)
|
57
|
-
shoulda-matchers (>= 1.4.1, < 3.0)
|
58
|
-
shoulda-context (1.1.5)
|
59
|
-
shoulda-matchers (2.4.0)
|
60
|
-
activesupport (>= 3.0.0)
|
61
|
-
thread_safe (0.1.3)
|
62
|
-
atomic
|
63
|
-
tzinfo (0.3.38)
|
12
|
+
asynchronous (1.0.3)
|
13
|
+
loader (1.0.2)
|
14
|
+
sourcerer (0.5.2)
|
64
15
|
|
65
16
|
PLATFORMS
|
66
17
|
ruby
|
67
18
|
|
68
19
|
DEPENDENCIES
|
69
|
-
|
70
|
-
jeweler (~> 1.8.7)
|
71
|
-
rdoc (~> 3.12)
|
72
|
-
shoulda
|
20
|
+
procemon!
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.8.0
|
data/lib/procemon/mpatch/hash.rb
CHANGED
data/lib/procemon.rb
CHANGED
@@ -3,8 +3,8 @@ module Procemon
|
|
3
3
|
|
4
4
|
require 'asynchronous'
|
5
5
|
require 'sourcerer'
|
6
|
+
require 'loader'
|
6
7
|
|
7
|
-
require File.join(File.dirname(__FILE__),"procemon","function","require")
|
8
8
|
require_relative_directory File.join("procemon","mpatch")
|
9
9
|
require_relative_directory File.join("procemon","function")
|
10
10
|
|
@@ -20,16 +20,14 @@ module Procemon
|
|
20
20
|
tmpdir_init
|
21
21
|
|
22
22
|
# create config singleton
|
23
|
-
metaloader_framework
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
# mount offline modules
|
32
|
-
mount_modules
|
23
|
+
Loader.metaloader_framework root: Loader.caller_root_folder,
|
24
|
+
config_obj: Application.config
|
25
|
+
|
26
|
+
Dir.glob(File.join(Loader.caller_root_folder,"{lib,libs}","*")).each do |path|
|
27
|
+
if !File.directory? path
|
28
|
+
require path
|
29
|
+
end
|
30
|
+
end
|
33
31
|
|
34
32
|
# garbage collect
|
35
33
|
ObjectSpace.garbage_collect
|
data/procemon.gemspec
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: procemon
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.8.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Adam Luzsi
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-02-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: asynchronous
|
@@ -38,6 +38,20 @@ dependencies:
|
|
38
38
|
- - ! '>='
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: loader
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ! '>='
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ! '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
41
55
|
description: ! 'This is a collection of my Ruby Procs in the adventure of becoming
|
42
56
|
the best! In short this provides extra tools in Application configs, argumens processing,daemonise,eval,
|
43
57
|
getting source of a block,method,process and work with it, or even fuse them into
|
@@ -63,6 +77,7 @@ files:
|
|
63
77
|
- examples/simple_async_processing.rb
|
64
78
|
- files.rb
|
65
79
|
- lib/procemon.rb
|
80
|
+
- lib/procemon/extra/sender.rb
|
66
81
|
- lib/procemon/extra/str2duck.rb
|
67
82
|
- lib/procemon/function/application.rb
|
68
83
|
- lib/procemon/function/argv.rb
|
@@ -76,9 +91,6 @@ files:
|
|
76
91
|
- lib/procemon/function/meta/inject_methods.rb
|
77
92
|
- lib/procemon/function/name.rb
|
78
93
|
- lib/procemon/function/port.rb
|
79
|
-
- lib/procemon/function/require.rb
|
80
|
-
- lib/procemon/function/sender.rb
|
81
|
-
- lib/procemon/function/systemu.rb
|
82
94
|
- lib/procemon/function/tmp_dir.rb
|
83
95
|
- lib/procemon/function/validation.rb
|
84
96
|
- lib/procemon/mpatch/array.rb
|
@@ -1,108 +0,0 @@
|
|
1
|
-
module Kernel
|
2
|
-
|
3
|
-
# load meta folders rb files
|
4
|
-
def meta_load(target_folder= File.join(Dir.pwd,"lib","**","meta") )
|
5
|
-
|
6
|
-
# find elements
|
7
|
-
begin
|
8
|
-
Dir.glob( File.join(target_folder,"*.{rb,ru}") ).each do |one_rb_file|
|
9
|
-
require one_rb_file
|
10
|
-
end
|
11
|
-
end
|
12
|
-
|
13
|
-
end
|
14
|
-
|
15
|
-
# mount libs
|
16
|
-
def mount_libs(lib_folder= File.join(Dir.pwd, "lib") )
|
17
|
-
|
18
|
-
# load lib files
|
19
|
-
begin
|
20
|
-
Dir.glob(File.join(lib_folder,"*.{rb,ru}")).uniq.each do |one_rb_file|
|
21
|
-
require one_rb_file
|
22
|
-
end
|
23
|
-
end
|
24
|
-
|
25
|
-
end
|
26
|
-
alias :require_folder :mount_libs
|
27
|
-
|
28
|
-
# Offline repo activate
|
29
|
-
def mount_modules(target_folder= File.join(Dir.pwd,"{module,modules}","{gem,gems}") )
|
30
|
-
Dir.glob(File.join(target_folder,"**","lib")).select{|f| File.directory?(f)}.each do |one_path|
|
31
|
-
$LOAD_PATH.unshift one_path
|
32
|
-
end
|
33
|
-
end
|
34
|
-
|
35
|
-
# #Return File_name:File_path
|
36
|
-
def get_files(folder)
|
37
|
-
|
38
|
-
# Pre def. variables
|
39
|
-
begin
|
40
|
-
files = Hash.new
|
41
|
-
end
|
42
|
-
|
43
|
-
# Validation
|
44
|
-
begin
|
45
|
-
# Check that does the folder is absolute or not
|
46
|
-
if folder != File.expand_path(folder)
|
47
|
-
folder = File.expand_path(folder)
|
48
|
-
end
|
49
|
-
end
|
50
|
-
|
51
|
-
# Get Files list
|
52
|
-
begin
|
53
|
-
Dir[File.join(folder,'**','*')].uniq.each do |file_path|
|
54
|
-
if !File.directory? file_path
|
55
|
-
files[file_path.split(File::SEPARATOR).last.to_sym]= file_path
|
56
|
-
end
|
57
|
-
end
|
58
|
-
end
|
59
|
-
|
60
|
-
# Return file_name:folder
|
61
|
-
return files
|
62
|
-
end
|
63
|
-
|
64
|
-
# require by absolute path directory's files
|
65
|
-
def require_directory(folder)
|
66
|
-
Dir.glob(File.join(folder,"**","*.{rb,ru}")).each do |file_path|
|
67
|
-
require file_path
|
68
|
-
end
|
69
|
-
end
|
70
|
-
|
71
|
-
# require sender relative directory's files
|
72
|
-
# return the directory and the sub directories file names (rb/ru)
|
73
|
-
def require_relative_directory(folder)
|
74
|
-
|
75
|
-
# pre format
|
76
|
-
begin
|
77
|
-
|
78
|
-
# path create from caller
|
79
|
-
begin
|
80
|
-
path= caller[0].split(".{rb,ru}:").first.split(File::SEPARATOR)
|
81
|
-
path= path[0..(path.count-2)]
|
82
|
-
end
|
83
|
-
|
84
|
-
# after formatting
|
85
|
-
begin
|
86
|
-
|
87
|
-
if !File.directory?(path.join(File::SEPARATOR))
|
88
|
-
path.pop
|
89
|
-
end
|
90
|
-
path= File.join(path.join(File::SEPARATOR))
|
91
|
-
if path != File.expand_path(path)
|
92
|
-
path= File.expand_path(path)
|
93
|
-
end
|
94
|
-
|
95
|
-
end
|
96
|
-
|
97
|
-
end
|
98
|
-
|
99
|
-
# find elements
|
100
|
-
begin
|
101
|
-
return Dir.glob(File.join(path,folder,"**","*.{rb,ru}")).each do |one_path|
|
102
|
-
require one_path
|
103
|
-
end
|
104
|
-
end
|
105
|
-
|
106
|
-
end
|
107
|
-
|
108
|
-
end
|
@@ -1,360 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
|
-
require 'tmpdir'
|
4
|
-
require 'socket'
|
5
|
-
require 'fileutils'
|
6
|
-
require 'rbconfig'
|
7
|
-
require 'thread'
|
8
|
-
|
9
|
-
class Object
|
10
|
-
def systemu(*a, &b) SystemUniversal.new(*a, &b).systemu end
|
11
|
-
end
|
12
|
-
|
13
|
-
class SystemUniversal
|
14
|
-
#
|
15
|
-
# constants
|
16
|
-
#
|
17
|
-
SystemUniversal::VERSION = '2.5.2' unless SystemUniversal.send(:const_defined?, :VERSION)
|
18
|
-
def SystemUniversal.version() SystemUniversal::VERSION end
|
19
|
-
def version() SystemUniversal::VERSION end
|
20
|
-
#
|
21
|
-
# class methods
|
22
|
-
#
|
23
|
-
|
24
|
-
@host = Socket.gethostname
|
25
|
-
@ppid = Process.ppid
|
26
|
-
@pid = Process.pid
|
27
|
-
@turd = ENV['SYSTEMU_TURD']
|
28
|
-
|
29
|
-
c = begin; ::RbConfig::CONFIG; rescue NameError; ::Config::CONFIG; end
|
30
|
-
ruby = File.join(c['bindir'], c['ruby_install_name']) << c['EXEEXT']
|
31
|
-
@ruby = if system('%s -e 42' % ruby)
|
32
|
-
ruby
|
33
|
-
else
|
34
|
-
system('%s -e 42' % 'ruby') ? 'ruby' : warn('no ruby in PATH/CONFIG')
|
35
|
-
end
|
36
|
-
|
37
|
-
class << SystemUniversal
|
38
|
-
%w( host ppid pid ruby turd ).each{|a| attr_accessor a}
|
39
|
-
|
40
|
-
def quote(*words)
|
41
|
-
words.map{|word| word.inspect}.join(' ')
|
42
|
-
end
|
43
|
-
end
|
44
|
-
|
45
|
-
#
|
46
|
-
# instance methods
|
47
|
-
#
|
48
|
-
|
49
|
-
def initialize argv, opts = {}, &block
|
50
|
-
getopt = getopts opts
|
51
|
-
|
52
|
-
@argv = argv
|
53
|
-
@block = block
|
54
|
-
|
55
|
-
@stdin = getopt[ ['stdin', 'in', '0', 0] ]
|
56
|
-
@stdout = getopt[ ['stdout', 'out', '1', 1] ]
|
57
|
-
@stderr = getopt[ ['stderr', 'err', '2', 2] ]
|
58
|
-
@env = getopt[ 'env' ]
|
59
|
-
@cwd = getopt[ 'cwd' ]
|
60
|
-
|
61
|
-
@host = getopt[ 'host', self.class.host ]
|
62
|
-
@ppid = getopt[ 'ppid', self.class.ppid ]
|
63
|
-
@pid = getopt[ 'pid', self.class.pid ]
|
64
|
-
@ruby = getopt[ 'ruby', self.class.ruby ]
|
65
|
-
end
|
66
|
-
|
67
|
-
def systemu
|
68
|
-
tmpdir do |tmp|
|
69
|
-
c = child_setup tmp
|
70
|
-
status = nil
|
71
|
-
|
72
|
-
begin
|
73
|
-
thread = nil
|
74
|
-
|
75
|
-
quietly{
|
76
|
-
IO.popen "#{ quote(@ruby) } #{ quote(c['program']) }", 'r+' do |pipe|
|
77
|
-
line = pipe.gets
|
78
|
-
case line
|
79
|
-
when %r/^pid: \d+$/
|
80
|
-
cid = Integer line[%r/\d+/]
|
81
|
-
else
|
82
|
-
begin
|
83
|
-
buf = pipe.read
|
84
|
-
buf = "#{ line }#{ buf }"
|
85
|
-
e = Marshal.load buf
|
86
|
-
raise unless Exception === e
|
87
|
-
raise e
|
88
|
-
rescue
|
89
|
-
raise "systemu: Error - process interrupted!\n#{ buf }\n"
|
90
|
-
end
|
91
|
-
end
|
92
|
-
thread = new_thread cid, @block if @block
|
93
|
-
pipe.read rescue nil
|
94
|
-
end
|
95
|
-
}
|
96
|
-
status = $?
|
97
|
-
ensure
|
98
|
-
if thread
|
99
|
-
begin
|
100
|
-
class << status
|
101
|
-
attr 'thread'
|
102
|
-
end
|
103
|
-
status.instance_eval{ @thread = thread }
|
104
|
-
rescue
|
105
|
-
42
|
106
|
-
end
|
107
|
-
end
|
108
|
-
end
|
109
|
-
|
110
|
-
if @stdout or @stderr
|
111
|
-
open(c['stdout']){|f| relay f => @stdout} if @stdout
|
112
|
-
open(c['stderr']){|f| relay f => @stderr} if @stderr
|
113
|
-
status
|
114
|
-
else
|
115
|
-
[status, IO.read(c['stdout']), IO.read(c['stderr'])]
|
116
|
-
end
|
117
|
-
end
|
118
|
-
end
|
119
|
-
|
120
|
-
def quote *args, &block
|
121
|
-
SystemUniversal.quote(*args, &block)
|
122
|
-
end
|
123
|
-
|
124
|
-
def new_thread cid, block
|
125
|
-
q = Queue.new
|
126
|
-
Thread.new(cid) do |cid|
|
127
|
-
current = Thread.current
|
128
|
-
current.abort_on_exception = true
|
129
|
-
q.push current
|
130
|
-
block.call cid
|
131
|
-
end
|
132
|
-
q.pop
|
133
|
-
end
|
134
|
-
|
135
|
-
def child_setup tmp
|
136
|
-
stdin = File.expand_path(File.join(tmp, 'stdin'))
|
137
|
-
stdout = File.expand_path(File.join(tmp, 'stdout'))
|
138
|
-
stderr = File.expand_path(File.join(tmp, 'stderr'))
|
139
|
-
program = File.expand_path(File.join(tmp, 'program'))
|
140
|
-
config = File.expand_path(File.join(tmp, 'config'))
|
141
|
-
|
142
|
-
if @stdin
|
143
|
-
open(stdin, 'w'){|f| relay @stdin => f}
|
144
|
-
else
|
145
|
-
FileUtils.touch stdin
|
146
|
-
end
|
147
|
-
FileUtils.touch stdout
|
148
|
-
FileUtils.touch stderr
|
149
|
-
|
150
|
-
c = {}
|
151
|
-
c['argv'] = @argv
|
152
|
-
c['env'] = @env
|
153
|
-
c['cwd'] = @cwd
|
154
|
-
c['stdin'] = stdin
|
155
|
-
c['stdout'] = stdout
|
156
|
-
c['stderr'] = stderr
|
157
|
-
c['program'] = program
|
158
|
-
open(config, 'w'){|f| Marshal.dump(c, f)}
|
159
|
-
|
160
|
-
open(program, 'w'){|f| f.write child_program(config)}
|
161
|
-
|
162
|
-
c
|
163
|
-
end
|
164
|
-
|
165
|
-
def quietly
|
166
|
-
v = $VERBOSE
|
167
|
-
$VERBOSE = nil
|
168
|
-
yield
|
169
|
-
ensure
|
170
|
-
$VERBOSE = v
|
171
|
-
end
|
172
|
-
|
173
|
-
def child_program config
|
174
|
-
<<-program
|
175
|
-
# encoding: utf-8
|
176
|
-
|
177
|
-
PIPE = STDOUT.dup
|
178
|
-
begin
|
179
|
-
config = Marshal.load(IO.read('#{ config }'))
|
180
|
-
|
181
|
-
argv = config['argv']
|
182
|
-
env = config['env']
|
183
|
-
cwd = config['cwd']
|
184
|
-
stdin = config['stdin']
|
185
|
-
stdout = config['stdout']
|
186
|
-
stderr = config['stderr']
|
187
|
-
|
188
|
-
Dir.chdir cwd if cwd
|
189
|
-
env.each{|k,v| ENV[k.to_s] = v.to_s} if env
|
190
|
-
|
191
|
-
STDIN.reopen stdin
|
192
|
-
STDOUT.reopen stdout
|
193
|
-
STDERR.reopen stderr
|
194
|
-
|
195
|
-
PIPE.puts "pid: \#{ Process.pid }"
|
196
|
-
PIPE.flush # the process is ready yo!
|
197
|
-
PIPE.close
|
198
|
-
|
199
|
-
exec *argv
|
200
|
-
rescue Exception => e
|
201
|
-
PIPE.write Marshal.dump(e) rescue nil
|
202
|
-
exit 42
|
203
|
-
end
|
204
|
-
program
|
205
|
-
end
|
206
|
-
|
207
|
-
def relay srcdst
|
208
|
-
src, dst, ignored = srcdst.to_a.first
|
209
|
-
if src.respond_to? 'read'
|
210
|
-
while((buf = src.read(8192))); dst << buf; end
|
211
|
-
else
|
212
|
-
if src.respond_to?(:each_line)
|
213
|
-
src.each_line{|buf| dst << buf}
|
214
|
-
else
|
215
|
-
src.each{|buf| dst << buf}
|
216
|
-
end
|
217
|
-
end
|
218
|
-
end
|
219
|
-
|
220
|
-
def tmpdir d = Dir.tmpdir, max = 42, &b
|
221
|
-
i = -1 and loop{
|
222
|
-
i += 1
|
223
|
-
|
224
|
-
tmp = File.join d, "systemu_#{ @host }_#{ @ppid }_#{ @pid }_#{ rand }_#{ i += 1 }"
|
225
|
-
|
226
|
-
begin
|
227
|
-
Dir.mkdir tmp
|
228
|
-
rescue Errno::EEXIST
|
229
|
-
raise if i >= max
|
230
|
-
next
|
231
|
-
end
|
232
|
-
|
233
|
-
break(
|
234
|
-
if b
|
235
|
-
begin
|
236
|
-
b.call tmp
|
237
|
-
ensure
|
238
|
-
FileUtils.rm_rf tmp unless SystemU.turd
|
239
|
-
end
|
240
|
-
else
|
241
|
-
tmp
|
242
|
-
end
|
243
|
-
)
|
244
|
-
}
|
245
|
-
end
|
246
|
-
|
247
|
-
def getopts opts = {}
|
248
|
-
lambda do |*args|
|
249
|
-
keys, default, ignored = args
|
250
|
-
catch(:opt) do
|
251
|
-
[keys].flatten.each do |key|
|
252
|
-
[key, key.to_s, key.to_s.intern].each do |key|
|
253
|
-
throw :opt, opts[key] if opts.has_key?(key)
|
254
|
-
end
|
255
|
-
end
|
256
|
-
default
|
257
|
-
end
|
258
|
-
end
|
259
|
-
end
|
260
|
-
end
|
261
|
-
|
262
|
-
# some monkeypatching for JRuby
|
263
|
-
if defined? JRUBY_VERSION
|
264
|
-
require 'jruby'
|
265
|
-
java_import org.jruby.RubyProcess
|
266
|
-
|
267
|
-
class SystemUniversal
|
268
|
-
def systemu
|
269
|
-
split_argv = JRuby::PathHelper.smart_split_command @argv
|
270
|
-
process = java.lang.Runtime.runtime.exec split_argv.to_java(:string)
|
271
|
-
|
272
|
-
stdout, stderr = [process.input_stream, process.error_stream].map do |stream|
|
273
|
-
StreamReader.new(stream)
|
274
|
-
end
|
275
|
-
|
276
|
-
exit_code = process.wait_for
|
277
|
-
field = process.get_class.get_declared_field("pid")
|
278
|
-
field.set_accessible(true)
|
279
|
-
pid = field.get(process)
|
280
|
-
[
|
281
|
-
RubyProcess::RubyStatus.new_process_status(JRuby.runtime, exit_code, pid),
|
282
|
-
stdout.join,
|
283
|
-
stderr.join
|
284
|
-
]
|
285
|
-
end
|
286
|
-
|
287
|
-
class StreamReader
|
288
|
-
def initialize(stream)
|
289
|
-
@data = ""
|
290
|
-
@thread = Thread.new do
|
291
|
-
reader = java.io.BufferedReader.new java.io.InputStreamReader.new(stream)
|
292
|
-
|
293
|
-
while line = reader.read_line
|
294
|
-
@data << line << "\n"
|
295
|
-
end
|
296
|
-
end
|
297
|
-
end
|
298
|
-
|
299
|
-
def join
|
300
|
-
@thread.join
|
301
|
-
@data
|
302
|
-
end
|
303
|
-
end
|
304
|
-
end
|
305
|
-
end
|
306
|
-
|
307
|
-
|
308
|
-
|
309
|
-
SystemU = SystemUniversal unless defined? SystemU
|
310
|
-
Systemu = SystemUniversal unless defined? Systemu
|
311
|
-
|
312
|
-
|
313
|
-
|
314
|
-
|
315
|
-
|
316
|
-
|
317
|
-
|
318
|
-
|
319
|
-
|
320
|
-
|
321
|
-
|
322
|
-
|
323
|
-
|
324
|
-
if $0 == __FILE__
|
325
|
-
#
|
326
|
-
# date
|
327
|
-
#
|
328
|
-
date = %q( ruby -e" t = Time.now; STDOUT.puts t; STDERR.puts t " )
|
329
|
-
|
330
|
-
status, stdout, stderr = systemu date
|
331
|
-
p [status, stdout, stderr]
|
332
|
-
|
333
|
-
status = systemu date, 1=>(stdout = '')
|
334
|
-
p [status, stdout]
|
335
|
-
|
336
|
-
status = systemu date, 2=>(stderr = '')
|
337
|
-
p [status, stderr]
|
338
|
-
#
|
339
|
-
# sleep
|
340
|
-
#
|
341
|
-
sleep = %q( ruby -e" p(sleep(1)) " )
|
342
|
-
status, stdout, stderr = systemu sleep
|
343
|
-
p [status, stdout, stderr]
|
344
|
-
|
345
|
-
sleep = %q( ruby -e" p(sleep(42)) " )
|
346
|
-
status, stdout, stderr = systemu(sleep){|cid| Process.kill 9, cid}
|
347
|
-
p [status, stdout, stderr]
|
348
|
-
#
|
349
|
-
# env
|
350
|
-
#
|
351
|
-
env = %q( ruby -e" p ENV['A'] " )
|
352
|
-
status, stdout, stderr = systemu env, :env => {'A' => 42}
|
353
|
-
p [status, stdout, stderr]
|
354
|
-
#
|
355
|
-
# cwd
|
356
|
-
#
|
357
|
-
env = %q( ruby -e" p Dir.pwd " )
|
358
|
-
status, stdout, stderr = systemu env, :cwd => Dir.tmpdir
|
359
|
-
p [status, stdout, stderr]
|
360
|
-
end
|
File without changes
|