Class: DRbFileServer

Inherits:
Object
  • Object
show all
Defined in:
lib/drb_fileserver_plus.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(nodes, sps: nil, topic: 'file') ⇒ DRbFileServer

Returns a new instance of DRbFileServer.



16
17
18
19
20
21
22
# File 'lib/drb_fileserver_plus.rb', line 16

def initialize(nodes, sps: nil, topic: 'file')
  
  @nodes = nodes
  @failcount = 0
  @sps, @topic = sps, topic
  
end

Instance Attribute Details

#nodesObject

Returns the value of attribute nodes.



14
15
16
# File 'lib/drb_fileserver_plus.rb', line 14

def nodes
  @nodes
end

Instance Method Details

#chmod(permissions, fname) ⇒ Object



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/drb_fileserver_plus.rb', line 24

def chmod(permissions, fname)

  node = ''

  file_op do |f|
    node = 'dfs://' + @nodes.first
    f.chmod permissions, File.join(node, fname)
  end

  if @sps then
    @sps.notice "%s/chmod: %d %s" % [@topic, permissions,
                                     File.join(node, fname)]
  end

end

#cp(path, path2) ⇒ Object



41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/drb_fileserver_plus.rb', line 41

def cp(path, path2)
     
  node = ''
  
  file_op do |f|
    node = 'dfs://' + @nodes.first      
    f.cp File.join(node, path), File.join(node, path2)
  end
  
  if @sps then
    @sps.notice "%s/copy: %s %s" % [@topic, File.join(node, path), 
                             File.join(node, path2)]
  end

end

#directory?(fname) ⇒ Boolean

Returns:

  • (Boolean)


57
58
59
60
61
62
63
64
# File 'lib/drb_fileserver_plus.rb', line 57

def directory?(fname)
      
  file_op do |f| 
    node = 'dfs://' + @nodes.first
    f.directory? File.join(node, fname) 
  end

end

#exist?(fname) ⇒ Boolean Also known as: exists?

Returns:

  • (Boolean)


66
67
68
69
70
71
72
73
# File 'lib/drb_fileserver_plus.rb', line 66

def exist?(fname)
      
  file_op do |f| 
    node = 'dfs://' + @nodes.first
    f.exist? File.join(node, fname) 
  end

end

#glob(path) ⇒ Object



77
78
79
80
81
82
83
84
# File 'lib/drb_fileserver_plus.rb', line 77

def glob(path)

  file_op do |f|
    node = 'dfs://' + @nodes.first
    f.glob File.join(node, path)
  end

end

#ls(path) ⇒ Object



87
88
89
90
91
92
93
94
# File 'lib/drb_fileserver_plus.rb', line 87

def ls(path)
  
  file_op do |f| 
    node = 'dfs://' + @nodes.first
    f.ls File.join(node, path)
  end

end

#mkdir(path) ⇒ Object



96
97
98
99
100
101
102
103
104
105
106
107
108
109
# File 'lib/drb_fileserver_plus.rb', line 96

def mkdir(path)

  node = ''
  
  file_op do |f| 
    node = 'dfs://' + @nodes.first
    f.mkdir File.join(node, path)
  end
  
  if @sps then
    @sps.notice "%s/mkdir: %s" % [@topic, File.join(node, path)]    
  end

end

#mkdir_p(path) ⇒ Object



111
112
113
114
115
116
117
118
119
120
121
122
123
124
# File 'lib/drb_fileserver_plus.rb', line 111

def mkdir_p(path)

  node = ''    

  file_op do |f|
    node = 'dfs://' + @nodes.first
    f.mkdir_p File.join(node, path)
  end
  
  if @sps then
    @sps.notice "%s/mkdir_p: %s" % [@topic, File.join(node, path)]
  end
  
end

#mv(path, path2) ⇒ Object



126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
# File 'lib/drb_fileserver_plus.rb', line 126

def mv(path, path2)

  node = ''
  
  file_op do |f|
    node = 'dfs://' + @nodes.first
    f.mv File.join(node, path), File.join(node, path2)
  end
  
  if @sps then
    @sps.notice "%s/mv: %s %s" % [@topic, File.join(node, path), 
                             File.join(node, path2)]
  end

end

#read(fname) ⇒ Object



142
143
144
145
146
147
148
149
# File 'lib/drb_fileserver_plus.rb', line 142

def read(fname)
  
  file_op do |f|
    node = 'dfs://' + @nodes.first
    f.read File.join(node, fname)
  end

end

#rm(fname) ⇒ Object



151
152
153
154
155
156
157
158
159
160
161
162
163
164
# File 'lib/drb_fileserver_plus.rb', line 151

def rm(fname)

  node = ''
  
  file_op do |f|
    node = 'dfs://' + @nodes.first
    f.rm File.join(node, fname)
  end
  
  if @sps then
    @sps.notice "%s/rm: %s" % [@topic, File.join(node, fname)]
  end

end

#rm_r(fname, force: false) ⇒ Object



166
167
168
169
170
171
172
173
174
175
176
177
178
179
# File 'lib/drb_fileserver_plus.rb', line 166

def rm_r(fname, force: false)

  node = ''

  file_op do |f|
    node = 'dfs://' + @nodes.first
    f.rm_r File.join(node, fname), force: force
  end

  if @sps then
    @sps.notice "%s/rm_r: %s" % [@topic, File.join(node, fname)]
  end

end

#ru(path) ⇒ Object



181
182
183
184
185
186
187
188
189
190
191
192
193
194
# File 'lib/drb_fileserver_plus.rb', line 181

def ru(path)

  node = ''

  file_op do |f|
    node = 'dfs://' + @nodes.first
    f.rm File.join(node, path)
  end

  if @sps then
    @sps.notice "%s/ru: %s" % [@topic, File.join(node, path)]
  end

end

#ru_r(path) ⇒ Object



196
197
198
199
200
201
202
203
204
205
206
207
208
209
# File 'lib/drb_fileserver_plus.rb', line 196

def ru_r(path)

  node = ''

  file_op do |f|
    node = 'dfs://' + @nodes.first
    f.rm_r File.join(node, path)
  end

  if @sps then
    @sps.notice "%s/ru_r: %s" % [@topic, File.join(node, path)]
  end

end

#touch(fname, mtime: Time.now) ⇒ Object



211
212
213
214
215
216
217
218
219
220
221
222
223
224
# File 'lib/drb_fileserver_plus.rb', line 211

def touch(fname, mtime: Time.now)

  node = ''

  file_op do |f|
    node = 'dfs://' + @nodes.first
    f.touch File.join(node, fname), mtime: mtime
  end

  if @sps then
    @sps.notice "%s/touch: %s" % [@topic, File.join(node, fname)]
  end

end

#write(fname, content) ⇒ Object



226
227
228
229
230
231
232
233
234
235
236
237
238
239
# File 'lib/drb_fileserver_plus.rb', line 226

def write(fname, content)

  node = ''
  
  file_op do |f|
    node = 'dfs://' + @nodes.first
    f.write File.join(node, fname), content
  end
  
  if @sps then
    @sps.notice("%s/write: %s" % [@topic, File.join(node, fname)])
  end
  
end

#zip(fname, a) ⇒ Object



241
242
243
244
245
246
247
248
249
250
251
252
253
254
# File 'lib/drb_fileserver_plus.rb', line 241

def zip(fname, a)
  
  node = ''
  
  file_op do |f|
    node = 'dfs://' + @nodes.first
    f.zip File.join(node, fname), a
  end
  
  if @sps then
    @sps.notice "%s/zip: %s" % [@topic, File.join(node, fname)]
  end
  
end