vcs 0.1 → 0.2.148
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/Rakefile +17 -3
- data/bin/vcs +57 -34
- data/doc/jamis.rb +564 -0
- data/ruby_ex/abstract.rb +254 -0
- data/ruby_ex/abstract_node.rb +85 -0
- data/ruby_ex/algorithms/simulated_annealing.rb +140 -0
- data/ruby_ex/array_each_pair.rb +18 -0
- data/ruby_ex/ask.rb +101 -0
- data/ruby_ex/attributed_class.rb +302 -0
- data/ruby_ex/cache.rb +373 -0
- data/ruby_ex/checkout.rb +12 -0
- data/ruby_ex/choose.rb +271 -0
- data/ruby_ex/commands.rb +18 -0
- data/ruby_ex/commands/command.rb +401 -0
- data/ruby_ex/commands/datas.rb +16 -0
- data/ruby_ex/commands/datas/data.rb +33 -0
- data/ruby_ex/commands/datas/factory.rb +66 -0
- data/ruby_ex/commands/factory.rb +66 -0
- data/ruby_ex/commands/helpers.rb +67 -0
- data/ruby_ex/commands/pipe.rb +64 -0
- data/ruby_ex/commands/runners.rb +17 -0
- data/ruby_ex/commands/runners/exec.rb +49 -0
- data/ruby_ex/commands/runners/fork.rb +97 -0
- data/ruby_ex/commands/runners/runner.rb +107 -0
- data/ruby_ex/commands/seq.rb +27 -0
- data/ruby_ex/config_file.rb +96 -0
- data/ruby_ex/const_regexp.rb +59 -0
- data/ruby_ex/daemon.rb +134 -0
- data/ruby_ex/diff.rb +667 -0
- data/ruby_ex/dlogger.rb +62 -0
- data/ruby_ex/drb/dispatcher.rb +252 -0
- data/ruby_ex/drb/dispatcher_server_test.rb +29 -0
- data/ruby_ex/drb/drb_observable.rb +97 -0
- data/ruby_ex/drb/drb_observable_pool.rb +27 -0
- data/ruby_ex/drb/drb_service.rb +43 -0
- data/ruby_ex/drb/drb_undumped_attributes.rb +55 -0
- data/ruby_ex/drb/drb_undumped_indexed_object.rb +54 -0
- data/ruby_ex/drb/insecure_protected_methods.rb +103 -0
- data/ruby_ex/drb/session_client_test.rb +40 -0
- data/ruby_ex/drb/session_manager.rb +246 -0
- data/ruby_ex/drb/session_server.rb +53 -0
- data/ruby_ex/dtime.rb +143 -0
- data/ruby_ex/dumpable_proc.rb +63 -0
- data/ruby_ex/exception.rb +32 -0
- data/ruby_ex/filetype.rb +229 -0
- data/ruby_ex/fileutils_ex.rb +44 -0
- data/ruby_ex/fold.rb +58 -0
- data/ruby_ex/generate_id.rb +44 -0
- data/ruby_ex/hookable.rb +262 -0
- data/ruby_ex/hooker.rb +54 -0
- data/ruby_ex/inactive_timeout.rb +137 -0
- data/ruby_ex/indexed_node.rb +66 -0
- data/ruby_ex/io_marshal.rb +100 -0
- data/ruby_ex/ioo.rb +194 -0
- data/ruby_ex/labeled_node.rb +63 -0
- data/ruby_ex/logger_observer.rb +23 -0
- data/ruby_ex/md5sum.rb +66 -0
- data/ruby_ex/mktemp.rb +208 -0
- data/ruby_ex/module/attr_once.rb +36 -0
- data/ruby_ex/module/autoload_tree.rb +75 -0
- data/ruby_ex/module/hierarchy.rb +335 -0
- data/ruby_ex/module/instance_method_visibility.rb +73 -0
- data/ruby_ex/module_ex.rb +11 -0
- data/ruby_ex/node.rb +80 -0
- data/ruby_ex/object_monitor.rb +145 -0
- data/ruby_ex/object_monitor_activity.rb +33 -0
- data/ruby_ex/observable.rb +140 -0
- data/ruby_ex/observable_pool.rb +293 -0
- data/ruby_ex/orderedhash.rb +252 -0
- data/ruby_ex/pathname_ex.rb +152 -0
- data/ruby_ex/pp_hierarchy.rb +29 -0
- data/ruby_ex/pseudo_cache.rb +190 -0
- data/ruby_ex/queue.rb +56 -0
- data/ruby_ex/random_generators.rb +25 -0
- data/ruby_ex/random_generators/random_generator.rb +31 -0
- data/ruby_ex/random_generators/ruby.rb +23 -0
- data/ruby_ex/safe_eval.rb +348 -0
- data/ruby_ex/sendmail.rb +215 -0
- data/ruby_ex/service_manager.rb +121 -0
- data/ruby_ex/session/administrable.rb +120 -0
- data/ruby_ex/session/client.rb +153 -0
- data/ruby_ex/session/const.rb +18 -0
- data/ruby_ex/session/dispatcher.rb +184 -0
- data/ruby_ex/session/error.rb +21 -0
- data/ruby_ex/session/fetchable.rb +57 -0
- data/ruby_ex/session/fetcher.rb +62 -0
- data/ruby_ex/session/hookable.rb +26 -0
- data/ruby_ex/session/profile.rb +110 -0
- data/ruby_ex/session/server.rb +582 -0
- data/ruby_ex/session/test/administrable_test.rb +337 -0
- data/ruby_ex/session/test/basic_test.rb +523 -0
- data/ruby_ex/session/test/dispatcher_test.rb +409 -0
- data/ruby_ex/session/test/fetchable_test.rb +119 -0
- data/ruby_ex/session/test/sub_server_test.rb +188 -0
- data/ruby_ex/shuffle.rb +30 -0
- data/ruby_ex/spring.rb +136 -0
- data/ruby_ex/spring_set.rb +137 -0
- data/ruby_ex/string_ex.rb +28 -0
- data/ruby_ex/symtbl.rb +106 -0
- data/ruby_ex/synflow.rb +474 -0
- data/ruby_ex/test/unit/ui/yaml/testrunner.rb +164 -0
- data/ruby_ex/thread_mutex.rb +10 -0
- data/ruby_ex/timeout_ex.rb +81 -0
- data/ruby_ex/top_down.rb +73 -0
- data/ruby_ex/trace.rb +26 -0
- data/ruby_ex/uri/druby.rb +81 -0
- data/ruby_ex/uri/file.rb +65 -0
- data/ruby_ex/uri/ftp_ex.rb +37 -0
- data/ruby_ex/uri/http_ex.rb +43 -0
- data/ruby_ex/uri/ssh.rb +92 -0
- data/ruby_ex/uri/svn.rb +118 -0
- data/ruby_ex/uri_ex.rb +45 -0
- data/ruby_ex/verbose_object.rb +30 -0
- data/ruby_ex/version.rb +66 -0
- data/ruby_ex/yaml/basenode_ext.rb +63 -0
- data/ruby_ex/yaml/chop_header.rb +23 -0
- data/ruby_ex/yaml/transform.rb +449 -0
- data/ruby_ex/yaml/yregexpath.rb +76 -0
- data/src/changelog.rb +28 -18
- data/src/conflict.rb +20 -0
- data/src/diff.rb +18 -0
- data/src/diffstat.rb +9 -3
- data/src/last_changed_date.rb +18 -0
- data/src/mail.rb +33 -65
- data/src/message.rb +15 -9
- data/src/mycommit.rb +29 -14
- data/src/news.rb +24 -3
- data/src/status.rb +17 -0
- data/src/svn.rb +2 -2
- data/src/vcs.rb +24 -3
- metadata +124 -5
- data/lrdetools.rb +0 -12
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
# Copyright: Copyright (c) 2004 Nicolas Despres. All rights reserved.
|
|
2
|
+
# Author: Nicolas Despres <polrop@lrde.epita.fr>.
|
|
3
|
+
# License: Gnu General Public License.
|
|
4
|
+
|
|
5
|
+
# $LastChangedBy: polrop $
|
|
6
|
+
# $Id: client.rb 67 2004-12-07 01:00:10Z polrop $
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
require 'drb'
|
|
10
|
+
|
|
11
|
+
require 'session/const'
|
|
12
|
+
require 'session/hookable'
|
|
13
|
+
require 'session/profile'
|
|
14
|
+
require 'const_regexp'
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
module Session
|
|
18
|
+
|
|
19
|
+
class Client
|
|
20
|
+
include Hookable
|
|
21
|
+
|
|
22
|
+
#
|
|
23
|
+
# Constants
|
|
24
|
+
#
|
|
25
|
+
URI = 'druby://localhost:42000'
|
|
26
|
+
USRNAME = 'guest'
|
|
27
|
+
PASSWD = 'guest'.crypt(Const::SALT_KEY)
|
|
28
|
+
|
|
29
|
+
#
|
|
30
|
+
# Attributs
|
|
31
|
+
#
|
|
32
|
+
attr_reader :sid, :uri, :protocol, :hostname, :port, :usrname, :passwd,
|
|
33
|
+
:local_uri, :force_login
|
|
34
|
+
|
|
35
|
+
#
|
|
36
|
+
# Constructor
|
|
37
|
+
#
|
|
38
|
+
def initialize(uri=URI,
|
|
39
|
+
usrname=USRNAME,
|
|
40
|
+
passwd=PASSWD,
|
|
41
|
+
force_login=false,
|
|
42
|
+
*hooks)
|
|
43
|
+
unless force_login.is_a?(TrueClass) or force_login.is_a?(FalseClass)
|
|
44
|
+
raise(ArgumentError, 'force_login must be a boolean')
|
|
45
|
+
end
|
|
46
|
+
hooks.each do |hook|
|
|
47
|
+
unless hook.respond_to?(:hook)
|
|
48
|
+
raise(ArgumentError, 'hookable object must respond to hook')
|
|
49
|
+
end
|
|
50
|
+
end
|
|
51
|
+
self.uri = uri
|
|
52
|
+
@usrname = usrname
|
|
53
|
+
@passwd = passwd
|
|
54
|
+
@force_login = force_login
|
|
55
|
+
@hooks = hooks
|
|
56
|
+
@srv = nil
|
|
57
|
+
@sid = nil
|
|
58
|
+
@online = false
|
|
59
|
+
@local_nb_requests = 0
|
|
60
|
+
@online_mutex = Mutex.new
|
|
61
|
+
@local_logout_mutex = Mutex.new
|
|
62
|
+
login if @force_login
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
#
|
|
66
|
+
# Methods
|
|
67
|
+
#
|
|
68
|
+
def uri=(uri)
|
|
69
|
+
@uri = uri
|
|
70
|
+
@protocol, @hostname, @port = Profile.parse_uri(uri)
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
def online?
|
|
74
|
+
@online_mutex.synchronize { @online }
|
|
75
|
+
end
|
|
76
|
+
|
|
77
|
+
def login
|
|
78
|
+
@online_mutex.synchronize do
|
|
79
|
+
return true if @online
|
|
80
|
+
start_service
|
|
81
|
+
begin
|
|
82
|
+
@sid = @srv_front.login(@usrname, @passwd, DRb.uri, self, *@hooks)
|
|
83
|
+
rescue Exception
|
|
84
|
+
stop_service
|
|
85
|
+
raise
|
|
86
|
+
end
|
|
87
|
+
@online = true
|
|
88
|
+
@local_nb_requests = 0
|
|
89
|
+
end
|
|
90
|
+
end
|
|
91
|
+
|
|
92
|
+
def logout
|
|
93
|
+
@online_mutex.synchronize do
|
|
94
|
+
return true unless @online
|
|
95
|
+
@srv_front.request(@sid, :logout)
|
|
96
|
+
local_logout
|
|
97
|
+
true
|
|
98
|
+
end
|
|
99
|
+
end
|
|
100
|
+
|
|
101
|
+
def method_missing(meth, *args, &block)
|
|
102
|
+
request(meth, *args, &block)
|
|
103
|
+
end
|
|
104
|
+
|
|
105
|
+
def request(meth, *args, &block)
|
|
106
|
+
login
|
|
107
|
+
@online_mutex.synchronize { @local_nb_requests += 1 }
|
|
108
|
+
result = @srv_front.request(@sid, meth, *args, &block)
|
|
109
|
+
@online_mutex.synchronize { @local_nb_requests -= 1 }
|
|
110
|
+
result
|
|
111
|
+
end
|
|
112
|
+
|
|
113
|
+
# sid equal @sid when I'm loging out.
|
|
114
|
+
protected
|
|
115
|
+
def hook_logout(sid, profile)
|
|
116
|
+
local_logout if sid == @sid
|
|
117
|
+
end
|
|
118
|
+
|
|
119
|
+
# sid equal nil when I'm loging in.
|
|
120
|
+
protected
|
|
121
|
+
def hook_login(sid, profile)
|
|
122
|
+
end
|
|
123
|
+
|
|
124
|
+
protected
|
|
125
|
+
def local_logout
|
|
126
|
+
@local_logout_mutex.synchronize do
|
|
127
|
+
@online = false
|
|
128
|
+
@sid = nil
|
|
129
|
+
@local_nb_requests = 0
|
|
130
|
+
end
|
|
131
|
+
end
|
|
132
|
+
|
|
133
|
+
protected
|
|
134
|
+
def start_service
|
|
135
|
+
stop_service unless @srv.nil?
|
|
136
|
+
@srv = DRb.start_service
|
|
137
|
+
@srv_front = DRbObject.new(nil, @uri)
|
|
138
|
+
@local_uri = @srv.uri
|
|
139
|
+
end
|
|
140
|
+
|
|
141
|
+
protected
|
|
142
|
+
def stop_service
|
|
143
|
+
@srv.stop_service
|
|
144
|
+
@srv_front = nil
|
|
145
|
+
@local_uri = nil
|
|
146
|
+
@srv = nil
|
|
147
|
+
end
|
|
148
|
+
|
|
149
|
+
end # Client
|
|
150
|
+
|
|
151
|
+
end # module Session
|
|
152
|
+
|
|
153
|
+
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
# Copyright: Copyright (c) 2004 Nicolas Despres. All rights reserved.
|
|
2
|
+
# Author: Nicolas Despres <polrop@lrde.epita.fr>.
|
|
3
|
+
# License: Gnu General Public License.
|
|
4
|
+
|
|
5
|
+
# $LastChangedBy: polrop $
|
|
6
|
+
# $Id: const.rb 64 2004-12-06 13:28:14Z polrop $
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
module Session
|
|
10
|
+
|
|
11
|
+
module Const
|
|
12
|
+
|
|
13
|
+
SALT_KEY = 'ab'
|
|
14
|
+
|
|
15
|
+
end # module Const
|
|
16
|
+
|
|
17
|
+
end # module Session
|
|
18
|
+
|
|
@@ -0,0 +1,184 @@
|
|
|
1
|
+
# Copyright: Copyright (c) 2004 Nicolas Despres. All rights reserved.
|
|
2
|
+
# Author: Nicolas Despres <polrop@lrde.epita.fr>.
|
|
3
|
+
# License: Gnu General Public License.
|
|
4
|
+
|
|
5
|
+
# $LastChangedBy: ertai $
|
|
6
|
+
# $Id: dispatcher.rb 186 2005-04-03 00:07:45Z ertai $
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
require 'drb'
|
|
10
|
+
|
|
11
|
+
require 'session/client'
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
module Session
|
|
15
|
+
|
|
16
|
+
class Dispatcher
|
|
17
|
+
include DRb::DRbUndumped
|
|
18
|
+
|
|
19
|
+
#
|
|
20
|
+
# Constants
|
|
21
|
+
#
|
|
22
|
+
MAX_JOBS = 5
|
|
23
|
+
MAX_JOBS_LIMIT = 100
|
|
24
|
+
SRVDB = {
|
|
25
|
+
'druby://localhost:42000' => {
|
|
26
|
+
:usrname => 'guest',
|
|
27
|
+
:passwd => 'guest'.crypt(Const::SALT_KEY)
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
BASE_CLIENT_CLASS = Client
|
|
31
|
+
|
|
32
|
+
#
|
|
33
|
+
# Attributes
|
|
34
|
+
#
|
|
35
|
+
attr_reader :max_jobs
|
|
36
|
+
|
|
37
|
+
#
|
|
38
|
+
# Constructor
|
|
39
|
+
#
|
|
40
|
+
def initialize(srvdb=SRVDB,
|
|
41
|
+
max_jobs=MAX_JOBS,
|
|
42
|
+
client_class=BASE_CLIENT_CLASS,
|
|
43
|
+
*args)
|
|
44
|
+
unless 1 <= max_jobs && max_jobs <= MAX_JOBS_LIMIT
|
|
45
|
+
raise(ArgumentError,
|
|
46
|
+
"`#{max_jobs}' - too big max jobs (must be <= #{MAX_JOBS_LIMIT})")
|
|
47
|
+
end
|
|
48
|
+
@max_jobs = max_jobs
|
|
49
|
+
@srvdb = {}
|
|
50
|
+
srvdb.each do |uri, srv|
|
|
51
|
+
add(uri, srv[:usrname], srv[:passwd], client_class, *args)
|
|
52
|
+
end
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
def dispatch(clts, request, *args, &block)
|
|
56
|
+
mutex = Mutex.new
|
|
57
|
+
threads = []
|
|
58
|
+
nb_threads = [ clts.size, @max_jobs].min
|
|
59
|
+
clts_q = clts.dup
|
|
60
|
+
result = {}
|
|
61
|
+
nb_threads.times do
|
|
62
|
+
threads << Thread.new do
|
|
63
|
+
loop do
|
|
64
|
+
clt = mutex.synchronize { clts_q.shift }
|
|
65
|
+
break if clt.nil?
|
|
66
|
+
res = request(clt, request, *args, &block)
|
|
67
|
+
mutex.synchronize { result.update(res) }
|
|
68
|
+
end
|
|
69
|
+
end
|
|
70
|
+
end
|
|
71
|
+
threads.each { |thread| thread.join }
|
|
72
|
+
result
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
alias update dispatch
|
|
76
|
+
|
|
77
|
+
def select(&comp)
|
|
78
|
+
clts = []
|
|
79
|
+
each_client { |uri, clt| clts << clt if comp[clt] }
|
|
80
|
+
clts
|
|
81
|
+
end
|
|
82
|
+
|
|
83
|
+
def select_all
|
|
84
|
+
select { |clt| true }
|
|
85
|
+
end
|
|
86
|
+
|
|
87
|
+
def select_by(attr, value)
|
|
88
|
+
select { |clt| test_client_attribut(clt, attr, value) }
|
|
89
|
+
end
|
|
90
|
+
|
|
91
|
+
def multi_select_by(hash, init_val=true, &bool_fun)
|
|
92
|
+
select do |clt|
|
|
93
|
+
ret = init_val
|
|
94
|
+
hash.each do |k, v|
|
|
95
|
+
ret = bool_fun[ret, test_client_attribut(clt, k, v)]
|
|
96
|
+
end
|
|
97
|
+
ret
|
|
98
|
+
end
|
|
99
|
+
end
|
|
100
|
+
|
|
101
|
+
def and_multi_select_by(hash)
|
|
102
|
+
select do |clt|
|
|
103
|
+
ret = true
|
|
104
|
+
hash.each do |k, v|
|
|
105
|
+
ret = (ret and test_client_attribut(clt, k, v))
|
|
106
|
+
end
|
|
107
|
+
ret
|
|
108
|
+
end
|
|
109
|
+
end
|
|
110
|
+
|
|
111
|
+
def or_multi_select_by(hash)
|
|
112
|
+
select do |clt|
|
|
113
|
+
ret = false
|
|
114
|
+
hash.each { |k, v| ret = (ret or test_client_attribut(clt, k, v)) }
|
|
115
|
+
ret
|
|
116
|
+
end
|
|
117
|
+
end
|
|
118
|
+
|
|
119
|
+
def dispatch_all(request, *args, &block)
|
|
120
|
+
dispatch(select_all, request, *args, &block)
|
|
121
|
+
end
|
|
122
|
+
|
|
123
|
+
def method_missing(request, *args, &block)
|
|
124
|
+
dispatch_all(request, *args, &block)
|
|
125
|
+
end
|
|
126
|
+
|
|
127
|
+
# overload me
|
|
128
|
+
def choose(clients)
|
|
129
|
+
raise(NotImplementedError, "`choose' - not implemented at this level")
|
|
130
|
+
end
|
|
131
|
+
|
|
132
|
+
def choose_and_select(&block)
|
|
133
|
+
choose(select(&block))
|
|
134
|
+
end
|
|
135
|
+
|
|
136
|
+
def each
|
|
137
|
+
@srvdb.each { |uri, desc| yield(uri, desc) }
|
|
138
|
+
end
|
|
139
|
+
|
|
140
|
+
def each_client
|
|
141
|
+
@srvdb.each { |uri, desc| yield(uri, desc[:client]) }
|
|
142
|
+
end
|
|
143
|
+
|
|
144
|
+
def [](uri)
|
|
145
|
+
@srvdb[uri]
|
|
146
|
+
end
|
|
147
|
+
|
|
148
|
+
def add(uri, usrname, passwd, client_class, *args)
|
|
149
|
+
return nil if @srvdb[uri]
|
|
150
|
+
@srvdb[uri] = {
|
|
151
|
+
:usrname => usrname,
|
|
152
|
+
:passwd => passwd,
|
|
153
|
+
:client => client_class.new(uri, usrname, passwd, *args)
|
|
154
|
+
}
|
|
155
|
+
end
|
|
156
|
+
|
|
157
|
+
def del(uri)
|
|
158
|
+
@srvdb.delete(uri)
|
|
159
|
+
end
|
|
160
|
+
|
|
161
|
+
def request(clt, request, *args, &block)
|
|
162
|
+
res = nil
|
|
163
|
+
begin
|
|
164
|
+
res = clt.send(request, *args, &block)
|
|
165
|
+
rescue Exception => err
|
|
166
|
+
res = err
|
|
167
|
+
end
|
|
168
|
+
{ clt.uri => res }
|
|
169
|
+
end
|
|
170
|
+
|
|
171
|
+
protected
|
|
172
|
+
def test_client_attribut(clt, attr, value)
|
|
173
|
+
if value.is_a? Regexp
|
|
174
|
+
clt.send(attr).to_s =~ value
|
|
175
|
+
else
|
|
176
|
+
clt.send(attr) == value
|
|
177
|
+
end
|
|
178
|
+
end
|
|
179
|
+
|
|
180
|
+
end # module Dispatcher
|
|
181
|
+
|
|
182
|
+
end # module Session
|
|
183
|
+
|
|
184
|
+
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
# Copyright: Copyright (c) 2004 Nicolas Despres. All rights reserved.
|
|
2
|
+
# Author: Nicolas Despres <polrop@lrde.epita.fr>.
|
|
3
|
+
# License: Gnu General Public License.
|
|
4
|
+
|
|
5
|
+
# $LastChangedBy: polrop $
|
|
6
|
+
# $Id: error.rb 67 2004-12-07 01:00:10Z polrop $
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
module Session
|
|
10
|
+
|
|
11
|
+
class Error < DRb::DRbError; end
|
|
12
|
+
class PermissionError < Error; end
|
|
13
|
+
class RequestError < Error; end
|
|
14
|
+
class SessionError < Error; end
|
|
15
|
+
class FullError < Error; end
|
|
16
|
+
class AuthError < Error; end
|
|
17
|
+
class UserError < Error; end
|
|
18
|
+
class ParameterError < Error; end
|
|
19
|
+
|
|
20
|
+
end # module Session
|
|
21
|
+
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
# Copyright: Copyright (c) 2004 Nicolas Despres. All rights reserved.
|
|
2
|
+
# Author: Nicolas Despres <polrop@lrde.epita.fr>.
|
|
3
|
+
# License: Gnu General Public License.
|
|
4
|
+
|
|
5
|
+
# $LastChangedBy: ertai $
|
|
6
|
+
# $Id: fetchable.rb 186 2005-04-03 00:07:45Z ertai $
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
module Session
|
|
10
|
+
|
|
11
|
+
module Fetchable
|
|
12
|
+
|
|
13
|
+
#
|
|
14
|
+
# Sessions-oriented requests
|
|
15
|
+
#
|
|
16
|
+
protected
|
|
17
|
+
def request_fetch(sid, profile, filename, mode='r', perm=0644, &block)
|
|
18
|
+
f = nil
|
|
19
|
+
ret = false
|
|
20
|
+
exc = nil
|
|
21
|
+
begin
|
|
22
|
+
f = File.open(filename, mode, perm)
|
|
23
|
+
f.flock(File::LOCK_EX)
|
|
24
|
+
md5 = Digest::MD5.new
|
|
25
|
+
case mode
|
|
26
|
+
when 'a', 'w'
|
|
27
|
+
while (str = block[])
|
|
28
|
+
f.write(str)
|
|
29
|
+
md5 << str
|
|
30
|
+
end
|
|
31
|
+
ret = (md5.to_s == block[].to_s)
|
|
32
|
+
when 'r'
|
|
33
|
+
until f.eof?
|
|
34
|
+
str = f.read(1024)
|
|
35
|
+
md5 << str
|
|
36
|
+
block[str]
|
|
37
|
+
end
|
|
38
|
+
ret = (md5.to_s == block[nil].to_s)
|
|
39
|
+
else
|
|
40
|
+
raise(ArgumentError, "`#{mode}' - bad mode")
|
|
41
|
+
end
|
|
42
|
+
rescue Exception => exc
|
|
43
|
+
ensure
|
|
44
|
+
unless f.nil?
|
|
45
|
+
f.flock(File::LOCK_UN)
|
|
46
|
+
f.close
|
|
47
|
+
end
|
|
48
|
+
raise exc unless exc.nil?
|
|
49
|
+
return ret
|
|
50
|
+
end
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
end # module Fetchable
|
|
54
|
+
|
|
55
|
+
end # module Session
|
|
56
|
+
|
|
57
|
+
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
# Copyright: Copyright (c) 2004 Nicolas Despres. All rights reserved.
|
|
2
|
+
# Author: Nicolas Despres <polrop@lrde.epita.fr>.
|
|
3
|
+
# License: Gnu General Public License.
|
|
4
|
+
|
|
5
|
+
# $LastChangedBy: polrop $
|
|
6
|
+
# $Id: fetcher.rb 67 2004-12-07 01:00:10Z polrop $
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
require 'md5'
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
module Session
|
|
13
|
+
|
|
14
|
+
module Fetcher
|
|
15
|
+
|
|
16
|
+
#
|
|
17
|
+
# Requests
|
|
18
|
+
#
|
|
19
|
+
def upload(local_filename, remote_filename)
|
|
20
|
+
ret = false
|
|
21
|
+
File.open(local_filename, 'r') do |f|
|
|
22
|
+
md5 = Digest::MD5.new
|
|
23
|
+
local_eof = false
|
|
24
|
+
ret = request(:fetch, remote_filename, 'w') do
|
|
25
|
+
if f.eof?
|
|
26
|
+
unless local_eof
|
|
27
|
+
local_eof = true
|
|
28
|
+
nil
|
|
29
|
+
else
|
|
30
|
+
md5
|
|
31
|
+
end
|
|
32
|
+
else
|
|
33
|
+
str = f.read(1024)
|
|
34
|
+
md5 << str
|
|
35
|
+
str
|
|
36
|
+
end
|
|
37
|
+
end
|
|
38
|
+
end
|
|
39
|
+
ret
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
def download(remote_filename, local_filename)
|
|
43
|
+
ret = false
|
|
44
|
+
File.open(local_filename, 'w') do |f|
|
|
45
|
+
md5 = Digest::MD5.new
|
|
46
|
+
ret = request(:fetch, remote_filename) do |str|
|
|
47
|
+
if str.nil?
|
|
48
|
+
md5
|
|
49
|
+
else
|
|
50
|
+
md5 << str
|
|
51
|
+
f.write(str)
|
|
52
|
+
end
|
|
53
|
+
end
|
|
54
|
+
end
|
|
55
|
+
ret
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
end # Fetcher
|
|
59
|
+
|
|
60
|
+
end # module Session
|
|
61
|
+
|
|
62
|
+
|