systemu 1.2.0 → 2.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/LICENSE +3 -0
- data/README +16 -7
- data/{README.tmpl → README.erb} +10 -3
- data/Rakefile +364 -0
- data/lib/systemu.rb +64 -6
- data/systemu.gemspec +27 -0
- metadata +57 -39
- data/a.rb +0 -6
- data/gemspec.rb +0 -23
- data/gen_readme.rb +0 -32
- data/install.rb +0 -206
data/LICENSE
ADDED
data/README
CHANGED
@@ -8,15 +8,22 @@ SYNOPSIS
|
|
8
8
|
|
9
9
|
URIS
|
10
10
|
|
11
|
+
http://github.com/ahoward/systemu
|
11
12
|
http://rubyforge.org/projects/codeforpeople/
|
12
|
-
http://codeforpeople.com/lib/ruby/
|
13
|
-
http://codeforpeople.rubyforge.org/svn/
|
14
13
|
|
15
14
|
INSTALL
|
16
15
|
|
17
16
|
gem install systemu
|
18
17
|
|
19
18
|
HISTORY
|
19
|
+
2.0.0
|
20
|
+
- versioning issue. new gem release.
|
21
|
+
|
22
|
+
1.3.1
|
23
|
+
- updates for ruby 1.9.1
|
24
|
+
|
25
|
+
1.3.0
|
26
|
+
- move to github
|
20
27
|
|
21
28
|
1.2.0
|
22
29
|
|
@@ -27,6 +34,7 @@ HISTORY
|
|
27
34
|
|
28
35
|
SAMPLES
|
29
36
|
|
37
|
+
|
30
38
|
<========< samples/a.rb >========>
|
31
39
|
|
32
40
|
~ > cat samples/a.rb
|
@@ -45,7 +53,7 @@ SAMPLES
|
|
45
53
|
|
46
54
|
~ > ruby samples/a.rb
|
47
55
|
|
48
|
-
[#<Process::Status: pid=
|
56
|
+
[#<Process::Status: pid=44129,exited(0)>, "Tue Apr 12 21:43:07 -0600 2011\n", "Tue Apr 12 21:43:07 -0600 2011\n"]
|
49
57
|
|
50
58
|
|
51
59
|
<========< samples/b.rb >========>
|
@@ -67,7 +75,7 @@ SAMPLES
|
|
67
75
|
|
68
76
|
~ > ruby samples/b.rb
|
69
77
|
|
70
|
-
[#<Process::Status: pid=
|
78
|
+
[#<Process::Status: pid=44134,exited(0)>, "Tue Apr 12 21:43:07 -0600 2011\n", "Tue Apr 12 21:43:07 -0600 2011\n"]
|
71
79
|
|
72
80
|
|
73
81
|
<========< samples/c.rb >========>
|
@@ -108,7 +116,7 @@ SAMPLES
|
|
108
116
|
|
109
117
|
~ > ruby samples/d.rb
|
110
118
|
|
111
|
-
/private/
|
119
|
+
/private/var/folders/nO/nOjBCb30ELegrm98Bhyvbk+++TM/-Tmp-
|
112
120
|
|
113
121
|
|
114
122
|
<========< samples/e.rb >========>
|
@@ -155,6 +163,7 @@ SAMPLES
|
|
155
163
|
|
156
164
|
~ > ruby samples/f.rb
|
157
165
|
|
158
|
-
#<Process::Status: pid=
|
159
|
-
"
|
166
|
+
#<Process::Status: pid=44154,signaled(SIGKILL=9)>
|
167
|
+
"1302666187\n1302666188\n1302666189\n"
|
168
|
+
|
160
169
|
|
data/{README.tmpl → README.erb}
RENAMED
@@ -8,15 +8,22 @@ SYNOPSIS
|
|
8
8
|
|
9
9
|
URIS
|
10
10
|
|
11
|
+
http://github.com/ahoward/systemu
|
11
12
|
http://rubyforge.org/projects/codeforpeople/
|
12
|
-
http://codeforpeople.com/lib/ruby/
|
13
|
-
http://codeforpeople.rubyforge.org/svn/
|
14
13
|
|
15
14
|
INSTALL
|
16
15
|
|
17
16
|
gem install systemu
|
18
17
|
|
19
18
|
HISTORY
|
19
|
+
2.0.0
|
20
|
+
- versioning issue. new gem release.
|
21
|
+
|
22
|
+
1.3.1
|
23
|
+
- updates for ruby 1.9.1
|
24
|
+
|
25
|
+
1.3.0
|
26
|
+
- move to github
|
20
27
|
|
21
28
|
1.2.0
|
22
29
|
|
@@ -27,4 +34,4 @@ HISTORY
|
|
27
34
|
|
28
35
|
SAMPLES
|
29
36
|
|
30
|
-
|
37
|
+
<%= samples %>
|
data/Rakefile
ADDED
@@ -0,0 +1,364 @@
|
|
1
|
+
This.rubyforge_project = 'codeforpeople'
|
2
|
+
This.author = "Ara T. Howard"
|
3
|
+
This.email = "ara.t.howard@gmail.com"
|
4
|
+
This.homepage = "http://github.com/ahoward/#{ This.lib }"
|
5
|
+
|
6
|
+
|
7
|
+
task :default do
|
8
|
+
puts((Rake::Task.tasks.map{|task| task.name.gsub(/::/,':')} - ['default']).sort)
|
9
|
+
end
|
10
|
+
|
11
|
+
task :test do
|
12
|
+
run_tests!
|
13
|
+
end
|
14
|
+
|
15
|
+
namespace :test do
|
16
|
+
task(:unit){ run_tests!(:unit) }
|
17
|
+
task(:functional){ run_tests!(:functional) }
|
18
|
+
task(:integration){ run_tests!(:integration) }
|
19
|
+
end
|
20
|
+
|
21
|
+
def run_tests!(which = nil)
|
22
|
+
which ||= '**'
|
23
|
+
test_dir = File.join(This.dir, "test")
|
24
|
+
test_glob ||= File.join(test_dir, "#{ which }/**_test.rb")
|
25
|
+
test_rbs = Dir.glob(test_glob).sort
|
26
|
+
|
27
|
+
div = ('=' * 119)
|
28
|
+
line = ('-' * 119)
|
29
|
+
helper = "-r ./test/helper.rb" if test(?e, "./test/helper.rb")
|
30
|
+
|
31
|
+
test_rbs.each_with_index do |test_rb, index|
|
32
|
+
testno = index + 1
|
33
|
+
command = "#{ This.ruby } -I ./lib -I ./test/lib #{ helper } #{ test_rb }"
|
34
|
+
|
35
|
+
puts
|
36
|
+
say(div, :color => :cyan, :bold => true)
|
37
|
+
say("@#{ testno } => ", :bold => true, :method => :print)
|
38
|
+
say(command, :color => :cyan, :bold => true)
|
39
|
+
say(line, :color => :cyan, :bold => true)
|
40
|
+
|
41
|
+
system(command)
|
42
|
+
|
43
|
+
say(line, :color => :cyan, :bold => true)
|
44
|
+
|
45
|
+
status = $?.exitstatus
|
46
|
+
|
47
|
+
if status.zero?
|
48
|
+
say("@#{ testno } <= ", :bold => true, :color => :white, :method => :print)
|
49
|
+
say("SUCCESS", :color => :green, :bold => true)
|
50
|
+
else
|
51
|
+
say("@#{ testno } <= ", :bold => true, :color => :white, :method => :print)
|
52
|
+
say("FAILURE", :color => :red, :bold => true)
|
53
|
+
end
|
54
|
+
say(line, :color => :cyan, :bold => true)
|
55
|
+
|
56
|
+
exit(status) unless status.zero?
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
|
61
|
+
task :gemspec do
|
62
|
+
ignore_extensions = 'git', 'svn', 'tmp', /sw./, 'bak', 'gem'
|
63
|
+
ignore_directories = %w[ pkg ]
|
64
|
+
ignore_files = %w[ test/log ]
|
65
|
+
|
66
|
+
shiteless =
|
67
|
+
lambda do |list|
|
68
|
+
list.delete_if do |entry|
|
69
|
+
next unless test(?e, entry)
|
70
|
+
extension = File.basename(entry).split(%r/[.]/).last
|
71
|
+
ignore_extensions.any?{|ext| ext === extension}
|
72
|
+
end
|
73
|
+
list.delete_if do |entry|
|
74
|
+
next unless test(?d, entry)
|
75
|
+
dirname = File.expand_path(entry)
|
76
|
+
ignore_directories.any?{|dir| File.expand_path(dir) == dirname}
|
77
|
+
end
|
78
|
+
list.delete_if do |entry|
|
79
|
+
next unless test(?f, entry)
|
80
|
+
filename = File.expand_path(entry)
|
81
|
+
ignore_files.any?{|file| File.expand_path(file) == filename}
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
lib = This.lib
|
86
|
+
object = This.object
|
87
|
+
version = This.version
|
88
|
+
files = shiteless[Dir::glob("**/**")]
|
89
|
+
executables = shiteless[Dir::glob("bin/*")].map{|exe| File.basename(exe)}
|
90
|
+
has_rdoc = true #File.exist?('doc')
|
91
|
+
test_files = "test/#{ lib }.rb" if File.file?("test/#{ lib }.rb")
|
92
|
+
summary = object.respond_to?(:summary) ? object.summary : "summary: #{ lib } kicks the ass"
|
93
|
+
description = object.respond_to?(:description) ? object.description : "description: #{ lib } kicks the ass"
|
94
|
+
|
95
|
+
if This.extensions.nil?
|
96
|
+
This.extensions = []
|
97
|
+
extensions = This.extensions
|
98
|
+
%w( Makefile configure extconf.rb ).each do |ext|
|
99
|
+
extensions << ext if File.exists?(ext)
|
100
|
+
end
|
101
|
+
end
|
102
|
+
extensions = [extensions].flatten.compact
|
103
|
+
|
104
|
+
template =
|
105
|
+
if test(?e, 'gemspec.erb')
|
106
|
+
Template{ IO.read('gemspec.erb') }
|
107
|
+
else
|
108
|
+
Template {
|
109
|
+
<<-__
|
110
|
+
## #{ lib }.gemspec
|
111
|
+
#
|
112
|
+
|
113
|
+
Gem::Specification::new do |spec|
|
114
|
+
spec.name = #{ lib.inspect }
|
115
|
+
spec.version = #{ version.inspect }
|
116
|
+
spec.platform = Gem::Platform::RUBY
|
117
|
+
spec.summary = #{ lib.inspect }
|
118
|
+
spec.description = #{ description.inspect }
|
119
|
+
|
120
|
+
spec.files = #{ files.inspect }
|
121
|
+
spec.executables = #{ executables.inspect }
|
122
|
+
|
123
|
+
spec.require_path = "lib"
|
124
|
+
|
125
|
+
spec.has_rdoc = #{ has_rdoc.inspect }
|
126
|
+
spec.test_files = #{ test_files.inspect }
|
127
|
+
|
128
|
+
# spec.add_dependency 'lib', '>= version'
|
129
|
+
|
130
|
+
spec.extensions.push(*#{ extensions.inspect })
|
131
|
+
|
132
|
+
spec.rubyforge_project = #{ This.rubyforge_project.inspect }
|
133
|
+
spec.author = #{ This.author.inspect }
|
134
|
+
spec.email = #{ This.email.inspect }
|
135
|
+
spec.homepage = #{ This.homepage.inspect }
|
136
|
+
end
|
137
|
+
__
|
138
|
+
}
|
139
|
+
end
|
140
|
+
|
141
|
+
Fu.mkdir_p(This.pkgdir)
|
142
|
+
This.gemspec = File.join(This.dir, "#{ This.lib }.gemspec") #File.join(This.pkgdir, "gemspec.rb")
|
143
|
+
open("#{ This.gemspec }", "w"){|fd| fd.puts(template)}
|
144
|
+
end
|
145
|
+
|
146
|
+
task :gem => [:clean, :gemspec] do
|
147
|
+
Fu.mkdir_p(This.pkgdir)
|
148
|
+
before = Dir['*.gem']
|
149
|
+
cmd = "gem build #{ This.gemspec }"
|
150
|
+
`#{ cmd }`
|
151
|
+
after = Dir['*.gem']
|
152
|
+
gem = ((after - before).first || after.first) or abort('no gem!')
|
153
|
+
Fu.mv gem, This.pkgdir
|
154
|
+
This.gem = File.basename(gem)
|
155
|
+
end
|
156
|
+
|
157
|
+
task :readme do
|
158
|
+
samples = ''
|
159
|
+
prompt = '~ > '
|
160
|
+
lib = This.lib
|
161
|
+
version = This.version
|
162
|
+
|
163
|
+
Dir['sample*/*'].sort.each do |sample|
|
164
|
+
samples << "\n" << " <========< #{ sample } >========>" << "\n\n"
|
165
|
+
|
166
|
+
cmd = "cat #{ sample }"
|
167
|
+
samples << Util.indent(prompt + cmd, 2) << "\n\n"
|
168
|
+
samples << Util.indent(`#{ cmd }`, 4) << "\n"
|
169
|
+
|
170
|
+
cmd = "ruby #{ sample }"
|
171
|
+
samples << Util.indent(prompt + cmd, 2) << "\n\n"
|
172
|
+
|
173
|
+
cmd = "ruby -e'STDOUT.sync=true; exec %(ruby -I ./lib #{ sample })'"
|
174
|
+
samples << Util.indent(`#{ cmd } 2>&1`, 4) << "\n"
|
175
|
+
end
|
176
|
+
|
177
|
+
template =
|
178
|
+
if test(?e, 'readme.erb')
|
179
|
+
Template{ IO.read('readme.erb') }
|
180
|
+
else
|
181
|
+
Template {
|
182
|
+
<<-__
|
183
|
+
NAME
|
184
|
+
#{ lib }
|
185
|
+
|
186
|
+
DESCRIPTION
|
187
|
+
|
188
|
+
INSTALL
|
189
|
+
gem install #{ lib }
|
190
|
+
|
191
|
+
SAMPLES
|
192
|
+
#{ samples }
|
193
|
+
__
|
194
|
+
}
|
195
|
+
end
|
196
|
+
|
197
|
+
open("README", "w"){|fd| fd.puts template}
|
198
|
+
end
|
199
|
+
|
200
|
+
|
201
|
+
task :clean do
|
202
|
+
Dir[File.join(This.pkgdir, '**/**')].each{|entry| Fu.rm_rf(entry)}
|
203
|
+
end
|
204
|
+
|
205
|
+
|
206
|
+
task :release => [:clean, :gemspec, :gem] do
|
207
|
+
gems = Dir[File.join(This.pkgdir, '*.gem')].flatten
|
208
|
+
raise "which one? : #{ gems.inspect }" if gems.size > 1
|
209
|
+
raise "no gems?" if gems.size < 1
|
210
|
+
cmd = "rubyforge login && rubyforge add_release #{ This.rubyforge_project } #{ This.lib } #{ This.version } #{ This.pkgdir }/#{ This.gem }"
|
211
|
+
puts cmd
|
212
|
+
system cmd
|
213
|
+
cmd = "gem push #{ This.pkgdir }/#{ This.gem }"
|
214
|
+
puts cmd
|
215
|
+
system cmd
|
216
|
+
end
|
217
|
+
|
218
|
+
|
219
|
+
|
220
|
+
|
221
|
+
|
222
|
+
BEGIN {
|
223
|
+
# support for this rakefile
|
224
|
+
#
|
225
|
+
$VERBOSE = nil
|
226
|
+
|
227
|
+
require 'ostruct'
|
228
|
+
require 'erb'
|
229
|
+
require 'fileutils'
|
230
|
+
require 'rbconfig'
|
231
|
+
|
232
|
+
# fu shortcut
|
233
|
+
#
|
234
|
+
Fu = FileUtils
|
235
|
+
|
236
|
+
# cache a bunch of stuff about this rakefile/environment
|
237
|
+
#
|
238
|
+
This = OpenStruct.new
|
239
|
+
|
240
|
+
This.file = File.expand_path(__FILE__)
|
241
|
+
This.dir = File.dirname(This.file)
|
242
|
+
This.pkgdir = File.join(This.dir, 'pkg')
|
243
|
+
|
244
|
+
# grok lib
|
245
|
+
#
|
246
|
+
lib = ENV['LIB']
|
247
|
+
unless lib
|
248
|
+
lib = File.basename(Dir.pwd).sub(/[-].*$/, '')
|
249
|
+
end
|
250
|
+
This.lib = lib
|
251
|
+
|
252
|
+
# grok version
|
253
|
+
#
|
254
|
+
version = ENV['VERSION']
|
255
|
+
unless version
|
256
|
+
require "./lib/#{ This.lib }"
|
257
|
+
This.name = lib.capitalize
|
258
|
+
This.object = eval(This.name)
|
259
|
+
version = This.object.send(:version)
|
260
|
+
end
|
261
|
+
This.version = version
|
262
|
+
|
263
|
+
# we need to know the name of the lib an it's version
|
264
|
+
#
|
265
|
+
abort('no lib') unless This.lib
|
266
|
+
abort('no version') unless This.version
|
267
|
+
|
268
|
+
# discover full path to this ruby executable
|
269
|
+
#
|
270
|
+
c = Config::CONFIG
|
271
|
+
bindir = c["bindir"] || c['BINDIR']
|
272
|
+
ruby_install_name = c['ruby_install_name'] || c['RUBY_INSTALL_NAME'] || 'ruby'
|
273
|
+
ruby_ext = c['EXEEXT'] || ''
|
274
|
+
ruby = File.join(bindir, (ruby_install_name + ruby_ext))
|
275
|
+
This.ruby = ruby
|
276
|
+
|
277
|
+
# some utils
|
278
|
+
#
|
279
|
+
module Util
|
280
|
+
def indent(s, n = 2)
|
281
|
+
s = unindent(s)
|
282
|
+
ws = ' ' * n
|
283
|
+
s.gsub(%r/^/, ws)
|
284
|
+
end
|
285
|
+
|
286
|
+
def unindent(s)
|
287
|
+
indent = nil
|
288
|
+
s.each_line do |line|
|
289
|
+
next if line =~ %r/^\s*$/
|
290
|
+
indent = line[%r/^\s*/] and break
|
291
|
+
end
|
292
|
+
indent ? s.gsub(%r/^#{ indent }/, "") : s
|
293
|
+
end
|
294
|
+
extend self
|
295
|
+
end
|
296
|
+
|
297
|
+
# template support
|
298
|
+
#
|
299
|
+
class Template
|
300
|
+
def initialize(&block)
|
301
|
+
@block = block.binding
|
302
|
+
@template = block.call.to_s
|
303
|
+
end
|
304
|
+
def expand(b=nil)
|
305
|
+
ERB.new(Util.unindent(@template)).result(b||@block)
|
306
|
+
end
|
307
|
+
alias_method 'to_s', 'expand'
|
308
|
+
end
|
309
|
+
def Template(*args, &block) Template.new(*args, &block) end
|
310
|
+
|
311
|
+
# colored console output support
|
312
|
+
#
|
313
|
+
This.ansi = {
|
314
|
+
:clear => "\e[0m",
|
315
|
+
:reset => "\e[0m",
|
316
|
+
:erase_line => "\e[K",
|
317
|
+
:erase_char => "\e[P",
|
318
|
+
:bold => "\e[1m",
|
319
|
+
:dark => "\e[2m",
|
320
|
+
:underline => "\e[4m",
|
321
|
+
:underscore => "\e[4m",
|
322
|
+
:blink => "\e[5m",
|
323
|
+
:reverse => "\e[7m",
|
324
|
+
:concealed => "\e[8m",
|
325
|
+
:black => "\e[30m",
|
326
|
+
:red => "\e[31m",
|
327
|
+
:green => "\e[32m",
|
328
|
+
:yellow => "\e[33m",
|
329
|
+
:blue => "\e[34m",
|
330
|
+
:magenta => "\e[35m",
|
331
|
+
:cyan => "\e[36m",
|
332
|
+
:white => "\e[37m",
|
333
|
+
:on_black => "\e[40m",
|
334
|
+
:on_red => "\e[41m",
|
335
|
+
:on_green => "\e[42m",
|
336
|
+
:on_yellow => "\e[43m",
|
337
|
+
:on_blue => "\e[44m",
|
338
|
+
:on_magenta => "\e[45m",
|
339
|
+
:on_cyan => "\e[46m",
|
340
|
+
:on_white => "\e[47m"
|
341
|
+
}
|
342
|
+
def say(phrase, *args)
|
343
|
+
options = args.last.is_a?(Hash) ? args.pop : {}
|
344
|
+
options[:color] = args.shift.to_s.to_sym unless args.empty?
|
345
|
+
keys = options.keys
|
346
|
+
keys.each{|key| options[key.to_s.to_sym] = options.delete(key)}
|
347
|
+
|
348
|
+
color = options[:color]
|
349
|
+
bold = options.has_key?(:bold)
|
350
|
+
|
351
|
+
parts = [phrase]
|
352
|
+
parts.unshift(This.ansi[color]) if color
|
353
|
+
parts.unshift(This.ansi[:bold]) if bold
|
354
|
+
parts.push(This.ansi[:clear]) if parts.size > 1
|
355
|
+
|
356
|
+
method = options[:method] || :puts
|
357
|
+
|
358
|
+
Kernel.send(method, parts.join)
|
359
|
+
end
|
360
|
+
|
361
|
+
# always run out of the project dir
|
362
|
+
#
|
363
|
+
Dir.chdir(This.dir)
|
364
|
+
}
|
data/lib/systemu.rb
CHANGED
@@ -14,7 +14,8 @@ class SystemUniversal
|
|
14
14
|
#
|
15
15
|
# constants
|
16
16
|
#
|
17
|
-
SystemUniversal::VERSION = '
|
17
|
+
SystemUniversal::VERSION = '2.2.0' unless SystemUniversal.send(:const_defined?, :VERSION)
|
18
|
+
def SystemUniversal.version() SystemUniversal::VERSION end
|
18
19
|
def version() SystemUniversal::VERSION end
|
19
20
|
#
|
20
21
|
# class methods
|
@@ -33,8 +34,12 @@ class SystemUniversal
|
|
33
34
|
system('%s -e 42' % 'ruby') ? 'ruby' : warn('no ruby in PATH/CONFIG')
|
34
35
|
end
|
35
36
|
|
36
|
-
class <<
|
37
|
+
class << SystemUniversal
|
37
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
|
38
43
|
end
|
39
44
|
|
40
45
|
#
|
@@ -68,7 +73,7 @@ class SystemUniversal
|
|
68
73
|
thread = nil
|
69
74
|
|
70
75
|
quietly{
|
71
|
-
IO.popen "#{ @ruby } #{ c['program'] }", 'r+' do |pipe|
|
76
|
+
IO.popen "#{ quote(@ruby) } #{ quote(c['program']) }", 'r+' do |pipe|
|
72
77
|
line = pipe.gets
|
73
78
|
case line
|
74
79
|
when %r/^pid: \d+$/
|
@@ -112,6 +117,10 @@ class SystemUniversal
|
|
112
117
|
end
|
113
118
|
end
|
114
119
|
|
120
|
+
def quote *args, &block
|
121
|
+
SystemUniversal.quote(*args, &block)
|
122
|
+
end
|
123
|
+
|
115
124
|
def new_thread cid, block
|
116
125
|
q = Queue.new
|
117
126
|
Thread.new(cid) do |cid|
|
@@ -200,7 +209,11 @@ class SystemUniversal
|
|
200
209
|
if src.respond_to? 'read'
|
201
210
|
while((buf = src.read(8192))); dst << buf; end
|
202
211
|
else
|
203
|
-
src.
|
212
|
+
if src.respond_to?(:each_line)
|
213
|
+
src.each_line{|buf| dst << buf}
|
214
|
+
else
|
215
|
+
src.each{|buf| dst << buf}
|
216
|
+
end
|
204
217
|
end
|
205
218
|
end
|
206
219
|
|
@@ -234,10 +247,10 @@ class SystemUniversal
|
|
234
247
|
def getopts opts = {}
|
235
248
|
lambda do |*args|
|
236
249
|
keys, default, ignored = args
|
237
|
-
catch(
|
250
|
+
catch(:opt) do
|
238
251
|
[keys].flatten.each do |key|
|
239
252
|
[key, key.to_s, key.to_s.intern].each do |key|
|
240
|
-
throw
|
253
|
+
throw :opt, opts[key] if opts.has_key?(key)
|
241
254
|
end
|
242
255
|
end
|
243
256
|
default
|
@@ -246,7 +259,52 @@ class SystemUniversal
|
|
246
259
|
end
|
247
260
|
end
|
248
261
|
|
262
|
+
# some monkeypatching for JRuby
|
263
|
+
if defined? JRUBY_VERSION
|
264
|
+
require 'jruby'
|
265
|
+
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
|
+
[
|
278
|
+
RubyProcess::RubyStatus.new_process_status(JRuby.runtime, exit_code),
|
279
|
+
stdout.join,
|
280
|
+
stderr.join
|
281
|
+
]
|
282
|
+
end
|
283
|
+
|
284
|
+
class StreamReader
|
285
|
+
def initialize(stream)
|
286
|
+
@data = ""
|
287
|
+
@thread = Thread.new do
|
288
|
+
reader = java.io.BufferedReader.new java.io.InputStreamReader.new(stream)
|
289
|
+
|
290
|
+
while line = reader.read_line
|
291
|
+
@data << line << "\n"
|
292
|
+
end
|
293
|
+
end
|
294
|
+
end
|
295
|
+
|
296
|
+
def join
|
297
|
+
@thread.join
|
298
|
+
@data
|
299
|
+
end
|
300
|
+
end
|
301
|
+
end
|
302
|
+
end
|
303
|
+
|
304
|
+
|
305
|
+
|
249
306
|
SystemU = SystemUniversal unless defined? SystemU
|
307
|
+
Systemu = SystemUniversal unless defined? Systemu
|
250
308
|
|
251
309
|
|
252
310
|
|
data/systemu.gemspec
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
## systemu.gemspec
|
2
|
+
#
|
3
|
+
|
4
|
+
Gem::Specification::new do |spec|
|
5
|
+
spec.name = "systemu"
|
6
|
+
spec.version = "2.2.0"
|
7
|
+
spec.platform = Gem::Platform::RUBY
|
8
|
+
spec.summary = "systemu"
|
9
|
+
spec.description = "description: systemu kicks the ass"
|
10
|
+
|
11
|
+
spec.files = ["lib", "lib/systemu.rb", "LICENSE", "Rakefile", "README", "README.erb", "samples", "samples/a.rb", "samples/b.rb", "samples/c.rb", "samples/d.rb", "samples/e.rb", "samples/f.rb", "systemu.gemspec"]
|
12
|
+
spec.executables = []
|
13
|
+
|
14
|
+
spec.require_path = "lib"
|
15
|
+
|
16
|
+
spec.has_rdoc = true
|
17
|
+
spec.test_files = nil
|
18
|
+
|
19
|
+
# spec.add_dependency 'lib', '>= version'
|
20
|
+
|
21
|
+
spec.extensions.push(*[])
|
22
|
+
|
23
|
+
spec.rubyforge_project = "codeforpeople"
|
24
|
+
spec.author = "Ara T. Howard"
|
25
|
+
spec.email = "ara.t.howard@gmail.com"
|
26
|
+
spec.homepage = "http://github.com/ahoward/systemu"
|
27
|
+
end
|
metadata
CHANGED
@@ -1,60 +1,78 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
|
-
rubygems_version: 0.9.4
|
3
|
-
specification_version: 1
|
4
2
|
name: systemu
|
5
3
|
version: !ruby/object:Gem::Version
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
-
|
11
|
-
|
12
|
-
|
13
|
-
rubyforge_project:
|
14
|
-
description:
|
15
|
-
autorequire: systemu
|
16
|
-
default_executable:
|
17
|
-
bindir: bin
|
18
|
-
has_rdoc: false
|
19
|
-
required_ruby_version: !ruby/object:Gem::Version::Requirement
|
20
|
-
requirements:
|
21
|
-
- - ">"
|
22
|
-
- !ruby/object:Gem::Version
|
23
|
-
version: 0.0.0
|
24
|
-
version:
|
4
|
+
hash: 7
|
5
|
+
prerelease:
|
6
|
+
segments:
|
7
|
+
- 2
|
8
|
+
- 2
|
9
|
+
- 0
|
10
|
+
version: 2.2.0
|
25
11
|
platform: ruby
|
26
|
-
signing_key:
|
27
|
-
cert_chain:
|
28
|
-
post_install_message:
|
29
12
|
authors:
|
30
13
|
- Ara T. Howard
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2011-04-12 00:00:00 -06:00
|
19
|
+
default_executable:
|
20
|
+
dependencies: []
|
21
|
+
|
22
|
+
description: "description: systemu kicks the ass"
|
23
|
+
email: ara.t.howard@gmail.com
|
24
|
+
executables: []
|
25
|
+
|
26
|
+
extensions: []
|
27
|
+
|
28
|
+
extra_rdoc_files: []
|
29
|
+
|
31
30
|
files:
|
32
|
-
- a.rb
|
33
|
-
- gemspec.rb
|
34
|
-
- gen_readme.rb
|
35
|
-
- install.rb
|
36
|
-
- lib
|
37
31
|
- lib/systemu.rb
|
32
|
+
- LICENSE
|
33
|
+
- Rakefile
|
38
34
|
- README
|
39
|
-
- README.
|
40
|
-
- samples
|
35
|
+
- README.erb
|
41
36
|
- samples/a.rb
|
42
37
|
- samples/b.rb
|
43
38
|
- samples/c.rb
|
44
39
|
- samples/d.rb
|
45
40
|
- samples/e.rb
|
46
41
|
- samples/f.rb
|
47
|
-
|
42
|
+
- systemu.gemspec
|
43
|
+
has_rdoc: true
|
44
|
+
homepage: http://github.com/ahoward/systemu
|
45
|
+
licenses: []
|
48
46
|
|
47
|
+
post_install_message:
|
49
48
|
rdoc_options: []
|
50
49
|
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
50
|
+
require_paths:
|
51
|
+
- lib
|
52
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
53
|
+
none: false
|
54
|
+
requirements:
|
55
|
+
- - ">="
|
56
|
+
- !ruby/object:Gem::Version
|
57
|
+
hash: 3
|
58
|
+
segments:
|
59
|
+
- 0
|
60
|
+
version: "0"
|
61
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
62
|
+
none: false
|
63
|
+
requirements:
|
64
|
+
- - ">="
|
65
|
+
- !ruby/object:Gem::Version
|
66
|
+
hash: 3
|
67
|
+
segments:
|
68
|
+
- 0
|
69
|
+
version: "0"
|
57
70
|
requirements: []
|
58
71
|
|
59
|
-
|
72
|
+
rubyforge_project: codeforpeople
|
73
|
+
rubygems_version: 1.4.2
|
74
|
+
signing_key:
|
75
|
+
specification_version: 3
|
76
|
+
summary: systemu
|
77
|
+
test_files: []
|
60
78
|
|
data/a.rb
DELETED
data/gemspec.rb
DELETED
@@ -1,23 +0,0 @@
|
|
1
|
-
lib, version = File::basename(File::dirname(File::expand_path(__FILE__))).split %r/-/, 2
|
2
|
-
|
3
|
-
require 'rubygems'
|
4
|
-
|
5
|
-
Gem::Specification::new do |spec|
|
6
|
-
spec.name = lib
|
7
|
-
spec.version = version
|
8
|
-
spec.platform = Gem::Platform::RUBY
|
9
|
-
spec.summary = lib
|
10
|
-
|
11
|
-
spec.files = Dir::glob "**/**"
|
12
|
-
spec.executables = Dir::glob("bin/*").map{|exe| File::basename exe}
|
13
|
-
|
14
|
-
spec.require_path = "lib"
|
15
|
-
spec.autorequire = lib
|
16
|
-
|
17
|
-
spec.has_rdoc = File::exist? "doc"
|
18
|
-
spec.test_suite_file = "test/#{ lib }.rb" if File::directory? "test"
|
19
|
-
|
20
|
-
spec.author = "Ara T. Howard"
|
21
|
-
spec.email = "ara.t.howard@noaa.gov"
|
22
|
-
spec.homepage = "http://codeforpeople.com/lib/ruby/#{ lib }/"
|
23
|
-
end
|
data/gen_readme.rb
DELETED
@@ -1,32 +0,0 @@
|
|
1
|
-
require 'pathname'
|
2
|
-
|
3
|
-
$VERBOSE=nil
|
4
|
-
|
5
|
-
def indent s, n = 2
|
6
|
-
ws = ' ' * n
|
7
|
-
s.gsub %r/^/, ws
|
8
|
-
end
|
9
|
-
|
10
|
-
template = IO::read 'README.tmpl'
|
11
|
-
|
12
|
-
samples = ''
|
13
|
-
prompt = '~ > '
|
14
|
-
|
15
|
-
Dir['sample*/*'].sort.each do |sample|
|
16
|
-
samples << "\n" << " <========< #{ sample } >========>" << "\n\n"
|
17
|
-
|
18
|
-
cmd = "cat #{ sample }"
|
19
|
-
samples << indent(prompt + cmd, 2) << "\n\n"
|
20
|
-
samples << indent(`#{ cmd }`, 4) << "\n"
|
21
|
-
|
22
|
-
cmd = "ruby #{ sample }"
|
23
|
-
samples << indent(prompt + cmd, 2) << "\n\n"
|
24
|
-
|
25
|
-
cmd = "ruby -W0 -Ilib #{ sample }"
|
26
|
-
samples << indent(`#{ cmd } 2>&1`, 4) << "\n"
|
27
|
-
end
|
28
|
-
|
29
|
-
#samples.gsub! %r/^/, ' '
|
30
|
-
|
31
|
-
readme = template.gsub %r/^\s*@samples\s*$/, samples
|
32
|
-
print readme
|
data/install.rb
DELETED
@@ -1,206 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
require 'rbconfig'
|
3
|
-
require 'find'
|
4
|
-
require 'ftools'
|
5
|
-
require 'tempfile'
|
6
|
-
include Config
|
7
|
-
|
8
|
-
LIBDIR = "lib"
|
9
|
-
LIBDIR_MODE = 0644
|
10
|
-
|
11
|
-
BINDIR = "bin"
|
12
|
-
BINDIR_MODE = 0755
|
13
|
-
|
14
|
-
|
15
|
-
$srcdir = CONFIG["srcdir"]
|
16
|
-
$version = CONFIG["MAJOR"]+"."+CONFIG["MINOR"]
|
17
|
-
$libdir = File.join(CONFIG["libdir"], "ruby", $version)
|
18
|
-
$archdir = File.join($libdir, CONFIG["arch"])
|
19
|
-
$site_libdir = $:.find {|x| x =~ /site_ruby$/}
|
20
|
-
$bindir = CONFIG["bindir"] || CONFIG['BINDIR']
|
21
|
-
$ruby_install_name = CONFIG['ruby_install_name'] || CONFIG['RUBY_INSTALL_NAME'] || 'ruby'
|
22
|
-
$ruby_ext = CONFIG['EXEEXT'] || ''
|
23
|
-
$ruby = File.join($bindir, ($ruby_install_name + $ruby_ext))
|
24
|
-
|
25
|
-
if !$site_libdir
|
26
|
-
$site_libdir = File.join($libdir, "site_ruby")
|
27
|
-
elsif $site_libdir !~ %r/#{Regexp.quote($version)}/
|
28
|
-
$site_libdir = File.join($site_libdir, $version)
|
29
|
-
end
|
30
|
-
|
31
|
-
def install_rb(srcdir=nil, destdir=nil, mode=nil, bin=nil)
|
32
|
-
#{{{
|
33
|
-
path = []
|
34
|
-
dir = []
|
35
|
-
Find.find(srcdir) do |f|
|
36
|
-
next unless FileTest.file?(f)
|
37
|
-
next if (f = f[srcdir.length+1..-1]) == nil
|
38
|
-
next if (/CVS$/ =~ File.dirname(f))
|
39
|
-
next if f =~ %r/\.lnk/
|
40
|
-
path.push f
|
41
|
-
dir |= [File.dirname(f)]
|
42
|
-
end
|
43
|
-
for f in dir
|
44
|
-
next if f == "."
|
45
|
-
next if f == "CVS"
|
46
|
-
File::makedirs(File.join(destdir, f))
|
47
|
-
end
|
48
|
-
for f in path
|
49
|
-
next if (/\~$/ =~ f)
|
50
|
-
next if (/^\./ =~ File.basename(f))
|
51
|
-
unless bin
|
52
|
-
File::install(File.join(srcdir, f), File.join(destdir, f), mode, true)
|
53
|
-
else
|
54
|
-
from = File.join(srcdir, f)
|
55
|
-
to = File.join(destdir, f)
|
56
|
-
shebangify(from) do |sf|
|
57
|
-
$deferr.print from, " -> ", File::catname(from, to), "\n"
|
58
|
-
$deferr.printf "chmod %04o %s\n", mode, to
|
59
|
-
File::install(sf, to, mode, false)
|
60
|
-
end
|
61
|
-
end
|
62
|
-
end
|
63
|
-
#}}}
|
64
|
-
end
|
65
|
-
def shebangify f
|
66
|
-
#{{{
|
67
|
-
open(f) do |fd|
|
68
|
-
buf = fd.read 42
|
69
|
-
if buf =~ %r/^\s*#\s*!.*ruby/o
|
70
|
-
ftmp = Tempfile::new("#{ $$ }_#{ File::basename(f) }")
|
71
|
-
begin
|
72
|
-
fd.rewind
|
73
|
-
ftmp.puts "#!#{ $ruby }"
|
74
|
-
while((buf = fd.read(8192)))
|
75
|
-
ftmp.write buf
|
76
|
-
end
|
77
|
-
ftmp.close
|
78
|
-
yield ftmp.path
|
79
|
-
ensure
|
80
|
-
ftmp.close!
|
81
|
-
end
|
82
|
-
else
|
83
|
-
yield f
|
84
|
-
end
|
85
|
-
end
|
86
|
-
#}}}
|
87
|
-
end
|
88
|
-
def ARGV.switch
|
89
|
-
#{{{
|
90
|
-
return nil if self.empty?
|
91
|
-
arg = self.shift
|
92
|
-
return nil if arg == '--'
|
93
|
-
if arg =~ /^-(.)(.*)/
|
94
|
-
return arg if $1 == '-'
|
95
|
-
raise 'unknown switch "-"' if $2.index('-')
|
96
|
-
self.unshift "-#{$2}" if $2.size > 0
|
97
|
-
"-#{$1}"
|
98
|
-
else
|
99
|
-
self.unshift arg
|
100
|
-
nil
|
101
|
-
end
|
102
|
-
#}}}
|
103
|
-
end
|
104
|
-
def ARGV.req_arg
|
105
|
-
#{{{
|
106
|
-
self.shift || raise('missing argument')
|
107
|
-
#}}}
|
108
|
-
end
|
109
|
-
def linkify d, linked = []
|
110
|
-
#--{{{
|
111
|
-
if test ?d, d
|
112
|
-
versioned = Dir[ File::join(d, "*-[0-9].[0-9].[0-9].rb") ]
|
113
|
-
versioned.each do |v|
|
114
|
-
src, dst = v, v.gsub(%r/\-[\d\.]+\.rb$/, '.rb')
|
115
|
-
lnk = nil
|
116
|
-
begin
|
117
|
-
if test ?l, dst
|
118
|
-
lnk = "#{ dst }.lnk"
|
119
|
-
puts "#{ dst } -> #{ lnk }"
|
120
|
-
File::rename dst, lnk
|
121
|
-
end
|
122
|
-
unless test ?e, dst
|
123
|
-
puts "#{ src } -> #{ dst }"
|
124
|
-
File::copy src, dst
|
125
|
-
linked << dst
|
126
|
-
end
|
127
|
-
ensure
|
128
|
-
if lnk
|
129
|
-
at_exit do
|
130
|
-
puts "#{ lnk } -> #{ dst }"
|
131
|
-
File::rename lnk, dst
|
132
|
-
end
|
133
|
-
end
|
134
|
-
end
|
135
|
-
end
|
136
|
-
end
|
137
|
-
linked
|
138
|
-
#--}}}
|
139
|
-
end
|
140
|
-
|
141
|
-
|
142
|
-
#
|
143
|
-
# main program
|
144
|
-
#
|
145
|
-
|
146
|
-
libdir = $site_libdir
|
147
|
-
bindir = $bindir
|
148
|
-
no_linkify = false
|
149
|
-
linked = nil
|
150
|
-
help = false
|
151
|
-
|
152
|
-
usage = <<-usage
|
153
|
-
#{ File::basename $0 }
|
154
|
-
-d, --destdir <destdir>
|
155
|
-
-l, --libdir <libdir>
|
156
|
-
-b, --bindir <bindir>
|
157
|
-
-r, --ruby <ruby>
|
158
|
-
-n, --no_linkify
|
159
|
-
-s, --sudo
|
160
|
-
-h, --help
|
161
|
-
usage
|
162
|
-
|
163
|
-
begin
|
164
|
-
while switch = ARGV.switch
|
165
|
-
case switch
|
166
|
-
when '-d', '--destdir'
|
167
|
-
libdir = ARGV.req_arg
|
168
|
-
when '-l', '--libdir'
|
169
|
-
libdir = ARGV.req_arg
|
170
|
-
when '-b', '--bindir'
|
171
|
-
bindir = ARGV.req_arg
|
172
|
-
when '-r', '--ruby'
|
173
|
-
$ruby = ARGV.req_arg
|
174
|
-
when '-n', '--no_linkify'
|
175
|
-
no_linkify = true
|
176
|
-
when '-s', '--sudo'
|
177
|
-
sudo = 'sudo'
|
178
|
-
when '-h', '--help'
|
179
|
-
help = true
|
180
|
-
else
|
181
|
-
raise "unknown switch #{switch.dump}"
|
182
|
-
end
|
183
|
-
end
|
184
|
-
rescue
|
185
|
-
STDERR.puts $!.to_s
|
186
|
-
STDERR.puts usage
|
187
|
-
exit 1
|
188
|
-
end
|
189
|
-
|
190
|
-
if help
|
191
|
-
STDOUT.puts usage
|
192
|
-
exit
|
193
|
-
end
|
194
|
-
|
195
|
-
unless no_linkify
|
196
|
-
linked = linkify('lib') + linkify('bin')
|
197
|
-
end
|
198
|
-
|
199
|
-
system "#{ $ruby } extconf.rb && make && #{ sudo } make install" if test(?s, 'extconf.rb')
|
200
|
-
|
201
|
-
install_rb(LIBDIR, libdir, LIBDIR_MODE)
|
202
|
-
install_rb(BINDIR, bindir, BINDIR_MODE, bin=true)
|
203
|
-
|
204
|
-
if linked
|
205
|
-
linked.each{|path| File::rm_f path}
|
206
|
-
end
|