ruby_ex 0.1.2 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/ChangeLog +693 -0
- data/NEWS +74 -0
- data/SPEC.dyn.yml +6 -6
- data/SPEC.gemspec +14 -0
- data/SPEC.yml +4 -4
- data/lib/abstract.rb +2 -4
- data/lib/abstract_node.rb +1 -2
- data/lib/algorithms/simulated_annealing.rb +50 -29
- data/lib/attributed_class.rb +50 -21
- data/lib/auto_object.rb +102 -0
- data/lib/blank_slate.rb +102 -0
- data/lib/cache.rb +1 -2
- data/lib/choose.rb +165 -163
- data/lib/commands.rb +2 -3
- data/lib/commands/command.rb +47 -20
- data/lib/commands/datas.rb +1 -1
- data/lib/commands/datas/composite.rb +5 -1
- data/lib/commands/datas/data.rb +102 -5
- data/lib/commands/datas/factory.rb +13 -6
- data/lib/commands/datas/temp.rb +3 -5
- data/lib/commands/factory.rb +1 -1
- data/lib/commands/helpers.rb +1 -1
- data/lib/commands/pipe.rb +10 -1
- data/lib/commands/runners.rb +1 -1
- data/lib/commands/runners/exec.rb +1 -1
- data/lib/commands/runners/fork.rb +3 -16
- data/lib/commands/runners/mock.rb +67 -0
- data/lib/commands/runners/runner.rb +5 -3
- data/lib/commands/runners/system.rb +1 -1
- data/lib/commands/seq.rb +2 -1
- data/lib/config_file.rb +10 -2
- data/lib/const_regexp.rb +1 -2
- data/lib/{dlogger.rb → d_logger.rb} +1 -2
- data/lib/daemon.rb +1 -2
- data/lib/diff.rb +1 -2
- data/lib/drb/drb_observable.rb +1 -2
- data/lib/drb/drb_observable_pool.rb +2 -2
- data/lib/drb/drb_service.rb +1 -2
- data/lib/drb/drb_undumped_attributes.rb +1 -2
- data/lib/drb/drb_undumped_indexed_object.rb +1 -2
- data/lib/drb/insecure_protected_methods.rb +1 -2
- data/lib/drb_ex.rb +2 -2
- data/lib/file_type.rb +466 -0
- data/lib/generate_id.rb +12 -6
- data/lib/genpasswd.rb +22 -0
- data/lib/hash_eval.rb +83 -0
- data/lib/histogram.rb +1 -2
- data/lib/hookable.rb +3 -4
- data/lib/hooker.rb +1 -3
- data/lib/html_encode.rb +191 -0
- data/lib/indexed_node.rb +0 -1
- data/lib/io_marshal.rb +4 -2
- data/lib/ioo.rb +3 -2
- data/lib/kill_all.rb +46 -0
- data/lib/labeled_node.rb +0 -1
- data/lib/logger_observer.rb +8 -4
- data/lib/md5sum.rb +3 -3
- data/lib/meta_factory.rb +99 -0
- data/lib/method_call.rb +87 -0
- data/lib/mocks.rb +12 -0
- data/lib/mocks/assertions.rb +50 -0
- data/lib/mocks/method_logger.rb +40 -0
- data/lib/mocks/mock.rb +64 -0
- data/lib/mocks/object.rb +47 -0
- data/lib/mocks/observer.rb +38 -0
- data/lib/module/autoload_tree.rb +30 -29
- data/lib/module/hierarchy.rb +176 -171
- data/lib/module/instance_method_visibility.rb +39 -38
- data/lib/node.rb +0 -1
- data/lib/object_monitor.rb +1 -2
- data/lib/object_monitor_activity.rb +1 -2
- data/lib/observable.rb +1 -2
- data/lib/observable_pool.rb +1 -2
- data/lib/{orderedhash.rb → ordered_hash.rb} +41 -5
- data/lib/pp_hierarchy.rb +7 -2
- data/lib/r_path.rb +307 -0
- data/lib/random_generators.rb +7 -20
- data/lib/random_generators/random_generator.rb +2 -4
- data/lib/random_generators/ruby.rb +4 -2
- data/lib/regex_path.rb +124 -0
- data/lib/ruby_ex.rb +28 -98
- data/lib/safe_eval.rb +1 -2
- data/lib/sendmail.rb +14 -17
- data/lib/service_manager.rb +1 -2
- data/lib/shuffle.rb +6 -2
- data/lib/spring.rb +1 -2
- data/lib/spring_set.rb +1 -2
- data/lib/{symtbl.rb → sym_tbl.rb} +90 -5
- data/lib/sym_tbl_gsub.rb +227 -0
- data/lib/{synflow.rb → syn_flow.rb} +1 -2
- data/lib/text.rb +218 -0
- data/lib/timeout_ex.rb +1 -2
- data/lib/trace.rb +9 -8
- data/lib/uri/druby.rb +1 -2
- data/lib/uri/file.rb +1 -1
- data/lib/uri/ftp_ex.rb +1 -1
- data/lib/uri/http_ex.rb +1 -1
- data/lib/uri/mysql.rb +121 -0
- data/lib/uri/pgsql.rb +19 -38
- data/lib/uri/svn.rb +1 -2
- data/lib/uri_ex.rb +45 -3
- data/lib/verbose_object.rb +181 -38
- data/lib/yaml/chop_header.rb +19 -11
- data/lib/yaml/transform.rb +17 -11
- data/lib/yaml/yregexpath.rb +11 -5
- data/test/algorithms/simulated_annealing_test.rb +2 -2
- data/test/resources/foo.tar.gz +0 -0
- data/test/resources/tar.gz.log +49 -0
- data/test/sanity-suite.yml +5 -7
- data/test/sanity/multiple-requires.yml +17 -7
- data/test/sanity/single-requires.yml +38 -20
- data/test/stress-tests/threads_and_exceptions.yml +13 -0
- data/test/test-unit-setup.rb +3 -1
- data/test/unit-suite.yml +7 -8
- metadata +42 -31
- data/lib/algorithms.rb +0 -12
- data/lib/ask.rb +0 -100
- data/lib/checkout.rb +0 -12
- data/lib/dumpable_proc.rb +0 -57
- data/lib/filetype.rb +0 -229
- data/lib/thread_mutex.rb +0 -11
- data/lib/yaml/basenode_ext.rb +0 -63
data/lib/generate_id.rb
CHANGED
@@ -1,15 +1,14 @@
|
|
1
1
|
# Copyright:: Copyright (c) 2004 Nicolas Despres. All rights reserved.
|
2
2
|
# Author:: Nicolas Despres <polrop@lrde.epita.fr>.
|
3
3
|
# License:: Gnu General Public License.
|
4
|
-
# Revision:: $Id: generate_id.rb
|
4
|
+
# Revision:: $Id: generate_id.rb 341 2005-09-07 00:01:43Z ertai $
|
5
5
|
|
6
6
|
|
7
|
-
require 'ruby_ex'
|
8
7
|
require 'md5'
|
9
8
|
|
10
|
-
|
9
|
+
class GenerateId
|
11
10
|
|
12
|
-
def
|
11
|
+
def initialize ( &already_exist )
|
13
12
|
md5 = Digest::MD5::new
|
14
13
|
id = ''
|
15
14
|
begin
|
@@ -23,8 +22,15 @@ module Kernel
|
|
23
22
|
id
|
24
23
|
end
|
25
24
|
|
26
|
-
end #
|
25
|
+
end # class GenerateId
|
26
|
+
|
27
|
+
module Kernel
|
27
28
|
|
29
|
+
def generate_id ( &already_exist )
|
30
|
+
GenerateId.new(&already_exist)
|
31
|
+
end
|
32
|
+
|
33
|
+
end # module Kernel
|
28
34
|
|
29
35
|
|
30
36
|
test_section __FILE__ do
|
@@ -34,7 +40,7 @@ test_section __FILE__ do
|
|
34
40
|
100.times { tab << generate_id }
|
35
41
|
assert_equal(tab.size, tab.uniq.size)
|
36
42
|
end
|
37
|
-
def
|
43
|
+
def test_complex
|
38
44
|
tab = []
|
39
45
|
bool = true
|
40
46
|
100.times { tab << generate_id { bool = !bool ; bool } }
|
data/lib/genpasswd.rb
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
# Copyright:: Copyright (c) 2004, 2005 Nicolas Despres. All rights reserved.
|
2
|
+
# Author:: Nicolas Despr�s <nicolas.despres@gmail.com>.
|
3
|
+
# License:: Gnu General Public License.
|
4
|
+
# Revision:: $Id: genpasswd.rb 339 2005-09-06 23:27:27Z ertai $
|
5
|
+
|
6
|
+
require 'choose'
|
7
|
+
|
8
|
+
class Genpasswd
|
9
|
+
|
10
|
+
def initialize ( length=8 )
|
11
|
+
str = new
|
12
|
+
length.times do
|
13
|
+
str << ('!'..'~').choose
|
14
|
+
end
|
15
|
+
str
|
16
|
+
end
|
17
|
+
|
18
|
+
end # class Genpasswd
|
19
|
+
|
20
|
+
def String.genpasswd(length=8)
|
21
|
+
Genpasswd.new(length)
|
22
|
+
end
|
data/lib/hash_eval.rb
ADDED
@@ -0,0 +1,83 @@
|
|
1
|
+
# Copyright: Copyright (c) 2004 Nicolas Despres. All rights reserved.
|
2
|
+
# Author: Nicolas Despr�s <nicolas.despres@gmail.com>.
|
3
|
+
# License: Gnu General Public License.
|
4
|
+
# $Id: hash_eval.rb 339 2005-09-06 23:27:27Z ertai $
|
5
|
+
|
6
|
+
|
7
|
+
class HashEval
|
8
|
+
|
9
|
+
def initialize(hash={}, &block)
|
10
|
+
@hash = hash
|
11
|
+
if block_given?
|
12
|
+
if block.arity == -1
|
13
|
+
instance_eval(&block)
|
14
|
+
else
|
15
|
+
block[self]
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
attr_reader :hash
|
21
|
+
|
22
|
+
def method_missing(meth, *args, &block)
|
23
|
+
args << self.class.new(&block).hash if block_given?
|
24
|
+
if args.size == 1
|
25
|
+
@hash[meth] = args.first
|
26
|
+
else
|
27
|
+
@hash[meth] = args
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
end # class HashEval
|
32
|
+
|
33
|
+
|
34
|
+
test_section __FILE__ do
|
35
|
+
|
36
|
+
class HashEvalTest < Test::Unit::TestCase
|
37
|
+
|
38
|
+
def test_block_without_arg
|
39
|
+
hash_eval = HashEval.new do
|
40
|
+
k1 'v1'
|
41
|
+
k2 do
|
42
|
+
k1 'v1'
|
43
|
+
end
|
44
|
+
k3 'v3' do
|
45
|
+
k1 'v4'
|
46
|
+
end
|
47
|
+
k4 'v5', 'v6'
|
48
|
+
k5 do
|
49
|
+
k1 'v1'
|
50
|
+
k2 do
|
51
|
+
k1 'v1'
|
52
|
+
end
|
53
|
+
end
|
54
|
+
@hash[:k6] = 'v10'
|
55
|
+
end
|
56
|
+
assert_equal 'v1', hash_eval.hash[:k1]
|
57
|
+
assert_equal({ :k1 => 'v1'}, hash_eval.hash[:k2])
|
58
|
+
assert_equal [ 'v3', {:k1 => 'v4'} ], hash_eval.hash[:k3]
|
59
|
+
assert_equal [ 'v5', 'v6' ], hash_eval.hash[:k4]
|
60
|
+
assert_equal({:k1=>"v1", :k2=>{:k1=>"v1"}}, hash_eval.hash[:k5])
|
61
|
+
assert_equal 'v10', hash_eval.hash[:k6]
|
62
|
+
end
|
63
|
+
|
64
|
+
def test_block_arg
|
65
|
+
hash_eval = HashEval.new do |h|
|
66
|
+
h.k1 'v1'
|
67
|
+
assert self.class != HashEval
|
68
|
+
end
|
69
|
+
assert_equal 'v1', hash_eval.hash[:k1]
|
70
|
+
end
|
71
|
+
|
72
|
+
def test_no_block
|
73
|
+
hash_eval = HashEval.new
|
74
|
+
hash_eval[:k1] = 'v1'
|
75
|
+
hash_eval.hash[:k2] = 'v2'
|
76
|
+
assert_equal [:k1, 'v1'], hash_eval.hash[:[]=]
|
77
|
+
assert_equal 'v2', hash_eval.hash[:k2]
|
78
|
+
end
|
79
|
+
|
80
|
+
end # end HashEvalTest
|
81
|
+
|
82
|
+
end # end test_section
|
83
|
+
|
data/lib/histogram.rb
CHANGED
@@ -1,9 +1,8 @@
|
|
1
1
|
# Copyright:: Copyright (c) 2005 Nicolas Pouillard. All rights reserved.
|
2
2
|
# Author:: Nicolas Pouillard <ertai@lrde.epita.fr>.
|
3
3
|
# License:: Gnu General Public License.
|
4
|
-
# Revision:: $Id: histogram.rb
|
4
|
+
# Revision:: $Id: histogram.rb 339 2005-09-06 23:27:27Z ertai $
|
5
5
|
|
6
|
-
require 'ruby_ex'
|
7
6
|
|
8
7
|
class Histogram
|
9
8
|
|
data/lib/hookable.rb
CHANGED
@@ -1,9 +1,8 @@
|
|
1
1
|
# Copyright:: Copyright (c) 2005 Nicolas Pouillard. All rights reserved.
|
2
2
|
# Author:: Nicolas Pouillard <ertai@lrde.epita.fr>.
|
3
3
|
# License:: Gnu General Public License.
|
4
|
-
# Revision:: $Id: hookable.rb
|
4
|
+
# Revision:: $Id: hookable.rb 343 2005-09-08 01:32:57Z ertai $
|
5
5
|
|
6
|
-
require 'ruby_ex'
|
7
6
|
require 'hooker'
|
8
7
|
|
9
8
|
|
@@ -132,7 +131,7 @@ test_section __FILE__ do
|
|
132
131
|
end
|
133
132
|
|
134
133
|
def reset
|
135
|
-
@stack.clear if @stack
|
134
|
+
@stack.clear if defined? @stack and @stack
|
136
135
|
end
|
137
136
|
end
|
138
137
|
|
@@ -158,7 +157,7 @@ test_section __FILE__ do
|
|
158
157
|
|
159
158
|
def run2
|
160
159
|
hook_trigger :hook2, 42
|
161
|
-
hook_trigger :hook3
|
160
|
+
suppress(ArgumentError) { hook_trigger :hook3 }
|
162
161
|
end
|
163
162
|
|
164
163
|
def << ( hooker )
|
data/lib/hooker.rb
CHANGED
@@ -1,10 +1,8 @@
|
|
1
1
|
# Copyright:: Copyright (c) 2005 Nicolas Pouillard. All rights reserved.
|
2
2
|
# Author:: Nicolas Pouillard <ertai@lrde.epita.fr>.
|
3
3
|
# License:: Gnu General Public License.
|
4
|
-
# Revision:: $Id: hooker.rb
|
4
|
+
# Revision:: $Id: hooker.rb 339 2005-09-06 23:27:27Z ertai $
|
5
5
|
|
6
|
-
require 'rubygems'
|
7
|
-
require_gem 'activesupport'
|
8
6
|
require 'active_support/class_inheritable_attributes'
|
9
7
|
|
10
8
|
|
data/lib/html_encode.rb
ADDED
@@ -0,0 +1,191 @@
|
|
1
|
+
# Copyright:: Copyright (c) 2005 Nicolas Pouillard. All rights reserved.
|
2
|
+
# Author:: Nicolas Pouillard <ertai@lrde.epita.fr>.
|
3
|
+
# License:: Gnu General Public License.
|
4
|
+
# Revision:: $Id: html_encode.rb 339 2005-09-06 23:27:27Z ertai $
|
5
|
+
|
6
|
+
module HtmlEncode
|
7
|
+
|
8
|
+
class RegexpHashUnion
|
9
|
+
attr_reader :regexp
|
10
|
+
|
11
|
+
def initialize ( aHash )
|
12
|
+
@hash = aHash
|
13
|
+
@regexp = Regexp.compile(@hash.keys.map { |re| re.source }.join('|'))
|
14
|
+
end
|
15
|
+
|
16
|
+
def gsub! ( anObject )
|
17
|
+
@hash.each { |re, str| anObject.gsub!(re, str) }
|
18
|
+
self
|
19
|
+
end
|
20
|
+
|
21
|
+
def =~ ( arg )
|
22
|
+
@regexp =~ arg
|
23
|
+
end
|
24
|
+
|
25
|
+
end # class RegexpHashUnion
|
26
|
+
|
27
|
+
|
28
|
+
@@html_encode_basic = RegexpHashUnion.new(
|
29
|
+
/\"/ => '"',
|
30
|
+
/</ => '<',
|
31
|
+
/>/ => '>',
|
32
|
+
/~/ => '¬'
|
33
|
+
)
|
34
|
+
|
35
|
+
@@html_encode_medium = RegexpHashUnion.new(
|
36
|
+
/�/ => 'ç',
|
37
|
+
/�/ => 'è',
|
38
|
+
/�/ => 'é',
|
39
|
+
/�/ => 'ê',
|
40
|
+
/�/ => 'ë',
|
41
|
+
/�/ => 'á',
|
42
|
+
/�/ => 'â',
|
43
|
+
/�/ => 'ô',
|
44
|
+
/�/ => 'É',
|
45
|
+
/�/ => 'Ê',
|
46
|
+
/�/ => 'Ë',
|
47
|
+
/�/ => 'à',
|
48
|
+
/�/ => 'î',
|
49
|
+
/�/ => 'ï',
|
50
|
+
/�/ => 'ù',
|
51
|
+
/�/ => 'ú',
|
52
|
+
/�/ => 'û',
|
53
|
+
/�/ => 'ü'
|
54
|
+
)
|
55
|
+
|
56
|
+
@@html_encode_advanced = RegexpHashUnion.new(
|
57
|
+
/�/ => '¡',
|
58
|
+
/�/ => '¢',
|
59
|
+
/�/ => '£',
|
60
|
+
/�/ => '¤',
|
61
|
+
/�/ => '¥',
|
62
|
+
/�/ => '¦',
|
63
|
+
/�/ => '§',
|
64
|
+
/�/ => '¨',
|
65
|
+
/�/ => '©',
|
66
|
+
/�/ => 'ª',
|
67
|
+
/\�/ => '«',
|
68
|
+
/�/ => '­',
|
69
|
+
/�/ => '®',
|
70
|
+
/�/ => '°',
|
71
|
+
/�/ => '±',
|
72
|
+
/�/ => '²',
|
73
|
+
/�/ => '³',
|
74
|
+
/�/ => '´',
|
75
|
+
/�/ => 'µ',
|
76
|
+
/�/ => '¶',
|
77
|
+
/�/ => '·',
|
78
|
+
/�/ => '¸',
|
79
|
+
/�/ => '¹',
|
80
|
+
/�/ => 'º',
|
81
|
+
/\�/ => '»',
|
82
|
+
/�/ => '¿',
|
83
|
+
/�/ => 'À',
|
84
|
+
/�/ => 'Á',
|
85
|
+
/�/ => 'Â',
|
86
|
+
/�/ => 'Ã',
|
87
|
+
/�/ => 'Ä',
|
88
|
+
/�/ => 'Å',
|
89
|
+
/�/ => 'Æ',
|
90
|
+
/�/ => 'Ç',
|
91
|
+
/�/ => 'È',
|
92
|
+
/�/ => 'Ì',
|
93
|
+
/�/ => 'Í',
|
94
|
+
/�/ => 'Î',
|
95
|
+
/�/ => 'Ï',
|
96
|
+
/�/ => 'Đ',
|
97
|
+
/�/ => 'Ñ',
|
98
|
+
/�/ => 'Ò',
|
99
|
+
/�/ => 'Ó',
|
100
|
+
/�/ => 'Ô',
|
101
|
+
/�/ => 'Õ',
|
102
|
+
/�/ => 'Ö',
|
103
|
+
/�/ => '×',
|
104
|
+
/�/ => 'Ø',
|
105
|
+
/�/ => 'Ù',
|
106
|
+
/�/ => 'Ú',
|
107
|
+
/�/ => 'Û',
|
108
|
+
/�/ => 'Ü',
|
109
|
+
/�/ => 'Ý',
|
110
|
+
/�/ => 'Þ',
|
111
|
+
/�/ => 'ß',
|
112
|
+
/�/ => 'ã',
|
113
|
+
/�/ => 'ä',
|
114
|
+
/�/ => 'å',
|
115
|
+
/�/ => 'æ',
|
116
|
+
/�/ => 'ð',
|
117
|
+
/�/ => 'ñ',
|
118
|
+
/�/ => 'ò',
|
119
|
+
/�/ => 'ó',
|
120
|
+
/�/ => 'õ',
|
121
|
+
/�/ => 'ö',
|
122
|
+
/�/ => '÷',
|
123
|
+
/�/ => 'ø',
|
124
|
+
/�/ => 'ì',
|
125
|
+
/�/ => 'í',
|
126
|
+
/�/ => 'ý',
|
127
|
+
/�/ => 'þ',
|
128
|
+
/�/ => 'ÿ'
|
129
|
+
)
|
130
|
+
|
131
|
+
def html_encode!
|
132
|
+
gsub!(/&/, '&')
|
133
|
+
@@html_encode_basic.gsub!(self)
|
134
|
+
self
|
135
|
+
end
|
136
|
+
|
137
|
+
def html_encode_latin1_accents!
|
138
|
+
@@html_encode_medium.gsub!(self) if @@html_encode_medium =~ self
|
139
|
+
@@html_encode_advanced.gsub!(self) if @@html_encode_advanced =~ self
|
140
|
+
self
|
141
|
+
end
|
142
|
+
|
143
|
+
def html_encode_latin1!
|
144
|
+
html_encode!
|
145
|
+
html_encode_latin1_accents!
|
146
|
+
end
|
147
|
+
|
148
|
+
def html_encode
|
149
|
+
dup.html_encode!
|
150
|
+
end
|
151
|
+
|
152
|
+
def html_encode_latin1_accents
|
153
|
+
dup.html_encode_latin1_accents!
|
154
|
+
end
|
155
|
+
|
156
|
+
def html_encode_latin1
|
157
|
+
dup.html_encode_latin1!
|
158
|
+
end
|
159
|
+
|
160
|
+
end # module HtmlEncode
|
161
|
+
|
162
|
+
class String
|
163
|
+
include HtmlEncode unless include? HtmlEncode
|
164
|
+
end # class String
|
165
|
+
|
166
|
+
test_section __FILE__ do
|
167
|
+
|
168
|
+
class TestHtmlEncode < ::Test::Unit::TestCase
|
169
|
+
|
170
|
+
def setup
|
171
|
+
@str = '<fo"o>b�a�r'
|
172
|
+
end
|
173
|
+
|
174
|
+
def teardown
|
175
|
+
end
|
176
|
+
|
177
|
+
def test_html_encode
|
178
|
+
assert_equal "<fo"o>b�a�r", @str.html_encode
|
179
|
+
end
|
180
|
+
|
181
|
+
def test_html_encode_latin1_accents
|
182
|
+
assert_equal '<fo"o>béaÔr', @str.html_encode_latin1_accents
|
183
|
+
end
|
184
|
+
|
185
|
+
def test_html_encode_latin1
|
186
|
+
assert_equal '<fo"o>béaÔr', @str.html_encode_latin1
|
187
|
+
end
|
188
|
+
|
189
|
+
end # class TestHtmlEncode
|
190
|
+
|
191
|
+
end
|
data/lib/indexed_node.rb
CHANGED
data/lib/io_marshal.rb
CHANGED
@@ -3,10 +3,12 @@
|
|
3
3
|
# License: Gnu General Public License.
|
4
4
|
|
5
5
|
# $LastChangedBy: ertai $
|
6
|
-
# $Id: io_marshal.rb
|
6
|
+
# $Id: io_marshal.rb 339 2005-09-06 23:27:27Z ertai $
|
7
7
|
|
8
8
|
|
9
|
-
|
9
|
+
|
10
|
+
module IoMarshal
|
11
|
+
end # module IoMarshal
|
10
12
|
|
11
13
|
class IO
|
12
14
|
|
data/lib/ioo.rb
CHANGED
@@ -3,10 +3,9 @@
|
|
3
3
|
# License: Gnu General Public License.
|
4
4
|
|
5
5
|
# $LastChangedBy: ertai $
|
6
|
-
# $Id: ioo.rb
|
6
|
+
# $Id: ioo.rb 339 2005-09-06 23:27:27Z ertai $
|
7
7
|
|
8
8
|
require 'delegate'
|
9
|
-
require 'ruby_ex'
|
10
9
|
|
11
10
|
# With this class you can easily overwrite only write or read methods
|
12
11
|
# to change the whole IO.
|
@@ -126,6 +125,8 @@ class IOO < DelegateClass(IO)
|
|
126
125
|
include ImplIOO
|
127
126
|
end # class IOO
|
128
127
|
|
128
|
+
Ioo = IOO
|
129
|
+
|
129
130
|
require 'socket'
|
130
131
|
class TCPSocket
|
131
132
|
alias :real_send :send
|
data/lib/kill_all.rb
ADDED
@@ -0,0 +1,46 @@
|
|
1
|
+
# Author:: Nicolas Pouillard <ertai@lrde.epita.fr>.
|
2
|
+
# Copyright:: Copyright (c) 2004, 2005 TTK team. All rights reserved.
|
3
|
+
# License:: LGPL
|
4
|
+
# $Id: kill_all.rb 339 2005-09-06 23:27:27Z ertai $
|
5
|
+
|
6
|
+
require 'commands'
|
7
|
+
|
8
|
+
class KillAll
|
9
|
+
|
10
|
+
attr_accessor :signal
|
11
|
+
attr_accessor :regexp
|
12
|
+
|
13
|
+
PS = 'ps'.to_cmd
|
14
|
+
|
15
|
+
def initialize ( aSignal='KILL' )
|
16
|
+
@signal = aSignal
|
17
|
+
@pids = []
|
18
|
+
end
|
19
|
+
|
20
|
+
def call ( aRegexp )
|
21
|
+
data = PS['a'].system
|
22
|
+
data.output.open do |ps|
|
23
|
+
ps.readline
|
24
|
+
ps.each do |line|
|
25
|
+
if line =~ /^\s*(\d+)(?:\s+\S+){3}\s+(.*)$/
|
26
|
+
pid, name = $1.to_i, $2
|
27
|
+
if name =~ aRegexp and pid != $$
|
28
|
+
@pids << pid
|
29
|
+
begin
|
30
|
+
Process.kill(@signal, pid)
|
31
|
+
rescue
|
32
|
+
raise RuntimeError, "Cannot kill #{name}:#{pid}"
|
33
|
+
end
|
34
|
+
end
|
35
|
+
else
|
36
|
+
raise RuntimeError, "bad ps output (#{line})"
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
alias :[] :call
|
43
|
+
|
44
|
+
end # class KillAll
|
45
|
+
|
46
|
+
KillAll.new[Regexp.new(ARGV[0])] if $0 == __FILE__
|