ruby_ex 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- data/AUTHORS +51 -0
- data/ChangeLog +1763 -0
- data/NEWS +3 -0
- data/README +1 -0
- data/Rakefile +8 -0
- data/SPEC.dyn.yml +10 -0
- data/SPEC.gem.yml +269 -0
- data/SPEC.yml +36 -0
- data/src/abstract.rb +253 -0
- data/src/abstract_node.rb +85 -0
- data/src/algorithms.rb +12 -0
- data/src/algorithms/simulated_annealing.rb +142 -0
- data/src/ask.rb +100 -0
- data/src/attributed_class.rb +303 -0
- data/src/cache.rb +350 -0
- data/src/checkout.rb +12 -0
- data/src/choose.rb +271 -0
- data/src/commands.rb +20 -0
- data/src/commands/command.rb +492 -0
- data/src/commands/datas.rb +16 -0
- data/src/commands/datas/composite.rb +31 -0
- data/src/commands/datas/data.rb +65 -0
- data/src/commands/datas/factory.rb +69 -0
- data/src/commands/datas/temp.rb +26 -0
- data/src/commands/factory.rb +67 -0
- data/src/commands/helpers.rb +81 -0
- data/src/commands/pipe.rb +66 -0
- data/src/commands/runners.rb +16 -0
- data/src/commands/runners/exec.rb +50 -0
- data/src/commands/runners/fork.rb +130 -0
- data/src/commands/runners/runner.rb +140 -0
- data/src/commands/runners/system.rb +57 -0
- data/src/commands/seq.rb +32 -0
- data/src/config_file.rb +95 -0
- data/src/const_regexp.rb +57 -0
- data/src/daemon.rb +135 -0
- data/src/diff.rb +665 -0
- data/src/dlogger.rb +62 -0
- data/src/drb/drb_observable.rb +95 -0
- data/src/drb/drb_observable_pool.rb +27 -0
- data/src/drb/drb_service.rb +44 -0
- data/src/drb/drb_undumped_attributes.rb +56 -0
- data/src/drb/drb_undumped_indexed_object.rb +55 -0
- data/src/drb/insecure_protected_methods.rb +101 -0
- data/src/drb_ex.rb +12 -0
- data/src/dumpable_proc.rb +57 -0
- data/src/filetype.rb +229 -0
- data/src/generate_id.rb +44 -0
- data/src/histogram.rb +222 -0
- data/src/hookable.rb +283 -0
- data/src/hooker.rb +54 -0
- data/src/indexed_node.rb +65 -0
- data/src/io_marshal.rb +99 -0
- data/src/ioo.rb +193 -0
- data/src/labeled_node.rb +62 -0
- data/src/logger_observer.rb +24 -0
- data/src/md5sum.rb +70 -0
- data/src/module/autoload_tree.rb +65 -0
- data/src/module/hierarchy.rb +334 -0
- data/src/module/instance_method_visibility.rb +71 -0
- data/src/node.rb +81 -0
- data/src/object_monitor.rb +143 -0
- data/src/object_monitor_activity.rb +34 -0
- data/src/observable.rb +138 -0
- data/src/observable_pool.rb +291 -0
- data/src/orderedhash.rb +252 -0
- data/src/pp_hierarchy.rb +30 -0
- data/src/random_generators.rb +29 -0
- data/src/random_generators/random_generator.rb +33 -0
- data/src/random_generators/ruby.rb +25 -0
- data/src/ruby_ex.rb +124 -0
- data/src/safe_eval.rb +346 -0
- data/src/sendmail.rb +214 -0
- data/src/service_manager.rb +122 -0
- data/src/shuffle.rb +30 -0
- data/src/spring.rb +134 -0
- data/src/spring_set.rb +134 -0
- data/src/symtbl.rb +108 -0
- data/src/synflow.rb +474 -0
- data/src/thread_mutex.rb +11 -0
- data/src/timeout_ex.rb +79 -0
- data/src/trace.rb +26 -0
- data/src/uri/druby.rb +78 -0
- data/src/uri/file.rb +63 -0
- data/src/uri/ftp_ex.rb +36 -0
- data/src/uri/http_ex.rb +41 -0
- data/src/uri/pgsql.rb +136 -0
- data/src/uri/ssh.rb +87 -0
- data/src/uri/svn.rb +113 -0
- data/src/uri_ex.rb +71 -0
- data/src/verbose_object.rb +70 -0
- data/src/yaml/basenode_ext.rb +63 -0
- data/src/yaml/chop_header.rb +24 -0
- data/src/yaml/transform.rb +450 -0
- data/src/yaml/yregexpath.rb +76 -0
- data/test/algorithms/simulated_annealing_test.rb +102 -0
- data/test/check-pkg-ruby_ex.yml +15 -0
- data/test/check-ruby_ex.yml +12 -0
- data/test/resources/autoload_tree/A.rb +11 -0
- data/test/resources/autoload_tree/B.rb +10 -0
- data/test/resources/autoload_tree/foo/C.rb +18 -0
- data/test/resources/foo.txt +6 -0
- data/test/sanity-suite.yml +12 -0
- data/test/sanity/multiple-requires.yml +20 -0
- data/test/sanity/single-requires.yml +24 -0
- data/test/test-unit-setup.rb +6 -0
- data/test/unit-suite.yml +14 -0
- metadata +269 -0
@@ -0,0 +1,16 @@
|
|
1
|
+
# Author:: Nicolas Pouillard <ertai@lrde.epita.fr>.
|
2
|
+
# Copyright:: Copyright (c) 2005 Nicolas Pouillard. All rights reserved.
|
3
|
+
# License:: GNU General Public License (GPL).
|
4
|
+
# Revision:: $Id: datas.rb 255 2005-06-01 00:08:46Z ertai $
|
5
|
+
|
6
|
+
require 'commands'
|
7
|
+
|
8
|
+
module Commands
|
9
|
+
|
10
|
+
module Datas
|
11
|
+
|
12
|
+
autoloaded_module(__FILE__, false)
|
13
|
+
|
14
|
+
end # module Datas
|
15
|
+
|
16
|
+
end # module Commands
|
@@ -0,0 +1,31 @@
|
|
1
|
+
# Author:: Nicolas Pouillard <ertai@lrde.epita.fr>.
|
2
|
+
# Copyright:: Copyright (c) 2005 Nicolas Pouillard. All rights reserved.
|
3
|
+
# License:: GNU General Public License (GPL).
|
4
|
+
# Revision:: $Id: composite.rb 255 2005-06-01 00:08:46Z ertai $
|
5
|
+
|
6
|
+
require 'commands'
|
7
|
+
|
8
|
+
module Commands
|
9
|
+
|
10
|
+
module Datas
|
11
|
+
|
12
|
+
class Composite < Data
|
13
|
+
|
14
|
+
def initialize ( *cmd )
|
15
|
+
@commands = cmd.flatten
|
16
|
+
end
|
17
|
+
|
18
|
+
def each ( &block )
|
19
|
+
@commands.each(&block)
|
20
|
+
end
|
21
|
+
|
22
|
+
def waitpid
|
23
|
+
each { |x| x.waitpid }
|
24
|
+
end
|
25
|
+
|
26
|
+
|
27
|
+
end # class Composite
|
28
|
+
|
29
|
+
end # module Datas
|
30
|
+
|
31
|
+
end # module Commands
|
@@ -0,0 +1,65 @@
|
|
1
|
+
# Author:: Nicolas Pouillard <ertai@lrde.epita.fr>.
|
2
|
+
# Copyright:: Copyright (c) 2005 Nicolas Pouillard. All rights reserved.
|
3
|
+
# License:: GNU General Public License (GPL).
|
4
|
+
# Revision:: $Id: data.rb 255 2005-06-01 00:08:46Z ertai $
|
5
|
+
|
6
|
+
require 'commands'
|
7
|
+
|
8
|
+
module Commands
|
9
|
+
|
10
|
+
module Datas
|
11
|
+
|
12
|
+
#
|
13
|
+
# A CommandData instance contains all information returned by a Command#run:
|
14
|
+
#
|
15
|
+
# * It's exit status:
|
16
|
+
# - Exit number.
|
17
|
+
# - Signals
|
18
|
+
# - ...
|
19
|
+
#
|
20
|
+
# * It's outputs:
|
21
|
+
# - What it writes on stdout.
|
22
|
+
# - stderr.
|
23
|
+
class Data
|
24
|
+
|
25
|
+
attr_accessor :pid
|
26
|
+
attr_accessor :input
|
27
|
+
attr_accessor :output
|
28
|
+
attr_accessor :error
|
29
|
+
attr_accessor :status
|
30
|
+
|
31
|
+
|
32
|
+
def waitpid
|
33
|
+
return @status unless @status.nil?
|
34
|
+
Process.waitpid(@pid)
|
35
|
+
@status = $?
|
36
|
+
end
|
37
|
+
|
38
|
+
|
39
|
+
def | ( rhs ) # FIXME CHECK ME
|
40
|
+
raise unless rhs.is_a? Command
|
41
|
+
rhs < output
|
42
|
+
end
|
43
|
+
|
44
|
+
|
45
|
+
def method_missing ( meth, *a, &b )
|
46
|
+
if output.respond_to?(meth)
|
47
|
+
output.send(meth, *a, &b)
|
48
|
+
else
|
49
|
+
super
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
|
54
|
+
def display ( out=STDOUT, err=STDERR )
|
55
|
+
waitpid
|
56
|
+
out.print @output.read
|
57
|
+
err.print @error.read
|
58
|
+
end
|
59
|
+
|
60
|
+
|
61
|
+
end # class Data
|
62
|
+
|
63
|
+
end # module Datas
|
64
|
+
|
65
|
+
end # module Commands
|
@@ -0,0 +1,69 @@
|
|
1
|
+
# Author:: Nicolas Pouillard <ertai@lrde.epita.fr>.
|
2
|
+
# Copyright:: Copyright (c) 2005 Nicolas Pouillard. All rights reserved.
|
3
|
+
# License:: GNU General Public License (GPL).
|
4
|
+
# Revision:: $Id: factory.rb 255 2005-06-01 00:08:46Z ertai $
|
5
|
+
|
6
|
+
require 'commands'
|
7
|
+
|
8
|
+
module Commands
|
9
|
+
|
10
|
+
module Datas
|
11
|
+
|
12
|
+
class Factory < Data
|
13
|
+
|
14
|
+
attr_accessor :command_data_class
|
15
|
+
|
16
|
+
def initialize
|
17
|
+
@command_data_class = Temp
|
18
|
+
end
|
19
|
+
|
20
|
+
def new_command_data ( *a, &b )
|
21
|
+
data = @command_data_class.new(*a, &b)
|
22
|
+
instance_variables.each do |var|
|
23
|
+
next if var =~ /command_data_class/
|
24
|
+
val = instance_variable_get(var)
|
25
|
+
data.send(var[1..-1] + '=', val) unless val.nil?
|
26
|
+
end
|
27
|
+
data
|
28
|
+
end
|
29
|
+
|
30
|
+
alias :create :new_command_data
|
31
|
+
|
32
|
+
end # class Factory
|
33
|
+
|
34
|
+
|
35
|
+
|
36
|
+
|
37
|
+
test_section __FILE__ do
|
38
|
+
|
39
|
+
class FactoryTest < Test::Unit::TestCase
|
40
|
+
|
41
|
+
def setup
|
42
|
+
assert_nothing_raised { @fa = Factory.new }
|
43
|
+
end
|
44
|
+
|
45
|
+
def test_0_initialize
|
46
|
+
end
|
47
|
+
|
48
|
+
def test_new_command_data
|
49
|
+
assert_nothing_raised do
|
50
|
+
assert_kind_of(Data, @fa.create)
|
51
|
+
assert_kind_of(Data, @fa.new_command_data)
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
def test_simple
|
56
|
+
assert_nothing_raised do
|
57
|
+
@fa.pid = 42
|
58
|
+
@data = @fa.create
|
59
|
+
end
|
60
|
+
assert_equal(42, @data.pid)
|
61
|
+
end
|
62
|
+
|
63
|
+
end # class FactoryTest
|
64
|
+
|
65
|
+
end
|
66
|
+
|
67
|
+
end # module Datas
|
68
|
+
|
69
|
+
end # module Commands
|
@@ -0,0 +1,26 @@
|
|
1
|
+
# Author:: Nicolas Pouillard <ertai@lrde.epita.fr>.
|
2
|
+
# Copyright:: Copyright (c) 2005 Nicolas Pouillard. All rights reserved.
|
3
|
+
# License:: GNU General Public License (GPL).
|
4
|
+
# Revision:: $Id: temp.rb 255 2005-06-01 00:08:46Z ertai $
|
5
|
+
|
6
|
+
require 'commands'
|
7
|
+
|
8
|
+
module Commands
|
9
|
+
|
10
|
+
module Datas
|
11
|
+
|
12
|
+
class Temp < Data
|
13
|
+
|
14
|
+
def initialize ( *a, &b )
|
15
|
+
super
|
16
|
+
@output = TempPath.new('cmd-output')
|
17
|
+
@output.open_mode = 'w'
|
18
|
+
@error = TempPath.new('cmd-error')
|
19
|
+
@error.open_mode = 'w'
|
20
|
+
end
|
21
|
+
|
22
|
+
end # class Temp
|
23
|
+
|
24
|
+
end # module Datas
|
25
|
+
|
26
|
+
end # module Commands
|
@@ -0,0 +1,67 @@
|
|
1
|
+
# Author:: Nicolas Pouillard <ertai@lrde.epita.fr>.
|
2
|
+
# Copyright:: Copyright (c) 2005 Nicolas Pouillard. All rights reserved.
|
3
|
+
# License:: GNU General Public License (GPL).
|
4
|
+
# Revision:: $Id: factory.rb 255 2005-06-01 00:08:46Z ertai $
|
5
|
+
|
6
|
+
require 'commands'
|
7
|
+
|
8
|
+
module Commands
|
9
|
+
|
10
|
+
class Factory < Command
|
11
|
+
|
12
|
+
def initialize
|
13
|
+
super(nil)
|
14
|
+
@command_class = Command
|
15
|
+
end
|
16
|
+
|
17
|
+
def new_command ( *a, &b )
|
18
|
+
cmd = @command_class.new(*a, &b)
|
19
|
+
instance_variables.each do |var|
|
20
|
+
next if var =~ /^@command(_class)?$/
|
21
|
+
cmd.send(var[1..-1] + '=', instance_variable_get(var))
|
22
|
+
end
|
23
|
+
cmd
|
24
|
+
end
|
25
|
+
|
26
|
+
alias :create :new_command
|
27
|
+
|
28
|
+
end # class Factory
|
29
|
+
|
30
|
+
|
31
|
+
|
32
|
+
test_section __FILE__ do
|
33
|
+
|
34
|
+
class FactoryTest < Test::Unit::TestCase
|
35
|
+
|
36
|
+
def setup
|
37
|
+
assert_nothing_raised { @fa = Factory.new }
|
38
|
+
end
|
39
|
+
|
40
|
+
def test_0_initialize
|
41
|
+
end
|
42
|
+
|
43
|
+
def test_new_command
|
44
|
+
assert_nothing_raised do
|
45
|
+
assert_kind_of(Command, @fa.create('wc'))
|
46
|
+
assert_kind_of(Command, @fa.new_command('ls'))
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
def test_simple
|
51
|
+
assert_nothing_raised do
|
52
|
+
@fa << 42
|
53
|
+
@fa.input = 'inp'
|
54
|
+
@fa = @fa > 'out'
|
55
|
+
@cmd = @fa.create('foo')
|
56
|
+
end
|
57
|
+
assert_equal('foo', @cmd.command)
|
58
|
+
assert_equal(42, @cmd.args.first)
|
59
|
+
assert_equal('inp', @cmd.input)
|
60
|
+
assert_equal('out', @cmd.output)
|
61
|
+
end
|
62
|
+
|
63
|
+
end # class FactoryTest
|
64
|
+
|
65
|
+
end
|
66
|
+
|
67
|
+
end # module Commands
|
@@ -0,0 +1,81 @@
|
|
1
|
+
# Author:: Nicolas Pouillard <ertai@lrde.epita.fr>.
|
2
|
+
# Copyright:: Copyright (c) 2005 Nicolas Pouillard. All rights reserved.
|
3
|
+
# License:: GNU General Public License (GPL).
|
4
|
+
# Revision:: $Id: helpers.rb 255 2005-06-01 00:08:46Z ertai $
|
5
|
+
|
6
|
+
require 'commands'
|
7
|
+
|
8
|
+
module Commands
|
9
|
+
|
10
|
+
module Helpers
|
11
|
+
|
12
|
+
class ::Object
|
13
|
+
|
14
|
+
def to_io_for_commands
|
15
|
+
to_io
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
19
|
+
|
20
|
+
class ::String
|
21
|
+
|
22
|
+
#
|
23
|
+
# Make a command from a String.
|
24
|
+
#
|
25
|
+
# Split your command when no quotations are used.
|
26
|
+
#
|
27
|
+
# Do not touch the String and give as one argument.
|
28
|
+
def to_cmd
|
29
|
+
if self =~ /['"`]/
|
30
|
+
Command.new(self)
|
31
|
+
else
|
32
|
+
Command.new(*split(/\s+/))
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
def to_io_for_commands
|
37
|
+
tmp = TempPath.new
|
38
|
+
tmp.open('w') { |f| f.write self }
|
39
|
+
tmp.to_io_for_commands
|
40
|
+
end
|
41
|
+
|
42
|
+
end # class ::String
|
43
|
+
|
44
|
+
|
45
|
+
|
46
|
+
class ::Array
|
47
|
+
|
48
|
+
def to_cmd
|
49
|
+
Command.new(*self)
|
50
|
+
end
|
51
|
+
|
52
|
+
end # class ::Array
|
53
|
+
|
54
|
+
end # module Helpers
|
55
|
+
|
56
|
+
|
57
|
+
|
58
|
+
test_section __FILE__ do
|
59
|
+
|
60
|
+
class HelpersTest < Test::Unit::TestCase
|
61
|
+
|
62
|
+
def test_string_to_cmd
|
63
|
+
assert_equal(['foo', 'bar'], "foo bar".to_cmd.to_a)
|
64
|
+
|
65
|
+
assert_equal(['foo', 'b/ar', 'qu44x32'],
|
66
|
+
"foo b/ar \t \n qu44x32".to_cmd.to_a)
|
67
|
+
|
68
|
+
s = "foo 'b/ar \t' \n qu44x32"
|
69
|
+
assert_equal([s], s.to_cmd.to_a)
|
70
|
+
end
|
71
|
+
|
72
|
+
def test_array_to_cmd
|
73
|
+
a = ['foo', "b/ar \t", "\n qu44x32"]
|
74
|
+
assert_equal(a, a.to_cmd.to_a)
|
75
|
+
end
|
76
|
+
|
77
|
+
end # class HelpersTest
|
78
|
+
|
79
|
+
end
|
80
|
+
|
81
|
+
end # module Commands
|
@@ -0,0 +1,66 @@
|
|
1
|
+
# Author:: Nicolas Pouillard <ertai@lrde.epita.fr>.
|
2
|
+
# Copyright:: Copyright (c) 2005 Nicolas Pouillard. All rights reserved.
|
3
|
+
# License:: GNU General Public License (GPL).
|
4
|
+
# Revision:: $Id: pipe.rb 255 2005-06-01 00:08:46Z ertai $
|
5
|
+
|
6
|
+
require 'commands'
|
7
|
+
|
8
|
+
module Commands
|
9
|
+
|
10
|
+
class Pipe < Command
|
11
|
+
|
12
|
+
def initialize ( *cmds )
|
13
|
+
@cmds = cmds.map { |x| x.dup }
|
14
|
+
end
|
15
|
+
|
16
|
+
def run ( *a )
|
17
|
+
pids = []
|
18
|
+
([nil] + @cmds).zip(@cmds + [nil]).each do |cmd1, cmd2|
|
19
|
+
next if cmd1.nil? or cmd2.nil?
|
20
|
+
rd, wr = IO.pipe
|
21
|
+
cmd1.output = wr
|
22
|
+
cmd2.input = rd
|
23
|
+
pids << Kernel.fork do
|
24
|
+
rd.close
|
25
|
+
cmd1.exec
|
26
|
+
end
|
27
|
+
wr.close
|
28
|
+
end
|
29
|
+
pids << Kernel.fork do
|
30
|
+
@cmds.last.exec
|
31
|
+
end
|
32
|
+
pids.each { |pid| Process.waitpid pid }
|
33
|
+
end
|
34
|
+
|
35
|
+
def input= ( arg )
|
36
|
+
@cmds.first.input = arg
|
37
|
+
end
|
38
|
+
|
39
|
+
def input
|
40
|
+
@cmds.first.input
|
41
|
+
end
|
42
|
+
|
43
|
+
def output= ( arg )
|
44
|
+
@cmds.last.output = arg
|
45
|
+
end
|
46
|
+
|
47
|
+
def output
|
48
|
+
@cmds.last.output
|
49
|
+
end
|
50
|
+
|
51
|
+
def error= ( arg )
|
52
|
+
@cmds.last.error = arg
|
53
|
+
end
|
54
|
+
|
55
|
+
def error
|
56
|
+
@cmds.last.error
|
57
|
+
end
|
58
|
+
|
59
|
+
def to_sh
|
60
|
+
strs = @cmds.map { |cmd| "(#{cmd.to_sh})" }
|
61
|
+
"(#{strs.join(' | ')})#{sh_args}"
|
62
|
+
end
|
63
|
+
|
64
|
+
end # class Pipe
|
65
|
+
|
66
|
+
end # module Commands
|
@@ -0,0 +1,16 @@
|
|
1
|
+
# Author:: Nicolas Pouillard <ertai@lrde.epita.fr>.
|
2
|
+
# Copyright:: Copyright (c) 2005 Nicolas Pouillard. All rights reserved.
|
3
|
+
# License:: GNU General Public License (GPL).
|
4
|
+
# Revision:: $Id: runners.rb 255 2005-06-01 00:08:46Z ertai $
|
5
|
+
|
6
|
+
require 'commands'
|
7
|
+
|
8
|
+
module Commands
|
9
|
+
|
10
|
+
module Runners
|
11
|
+
|
12
|
+
autoloaded_module(__FILE__, false)
|
13
|
+
|
14
|
+
end # module Runners
|
15
|
+
|
16
|
+
end # module Commands
|