Class: DRbFileServer
- Inherits:
-
Object
- Object
- DRbFileServer
- Defined in:
- lib/drb_fileserver_plus.rb
Instance Method Summary collapse
- #cp(path, path2) ⇒ Object
- #exists?(fname) ⇒ Boolean
-
#initialize(nodes, sps: nil, topic: 'file') ⇒ DRbFileServer
constructor
A new instance of DRbFileServer.
- #ls(path) ⇒ Object
- #mkdir(path) ⇒ Object
- #mkdir_p(path) ⇒ Object
- #mv(path, path2) ⇒ Object
- #read(fname) ⇒ Object
- #rm(fname) ⇒ Object
- #write(fname, content) ⇒ Object
- #zip(fname, a) ⇒ Object
Constructor Details
#initialize(nodes, sps: nil, topic: 'file') ⇒ DRbFileServer
14 15 16 17 18 19 20 |
# File 'lib/drb_fileserver_plus.rb', line 14 def initialize(nodes, sps: nil, topic: 'file') @nodes = nodes.map {|x| 'dfs://' + x} @failcount = 0 @sps, @topic = sps, topic end |
Instance Method Details
#cp(path, path2) ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/drb_fileserver_plus.rb', line 22 def cp(path, path2) file_op do |f| f.cp File.join(@nodes.first, path), File.join(@nodes.first, path2) end if @sps then @sps.notice "%s/copy: %s %s" % [@topic, File.join(@nodes.first, path), File.join(@nodes.first, path2)] end end |
#exists?(fname) ⇒ Boolean
35 36 37 38 39 |
# File 'lib/drb_fileserver_plus.rb', line 35 def exists?(fname) file_op {|f| f.exists? File.join(@nodes.first, fname) } end |
#ls(path) ⇒ Object
41 42 43 44 45 |
# File 'lib/drb_fileserver_plus.rb', line 41 def ls(path) file_op {|f| f.ls File.join(@nodes.first, path) } end |
#mkdir(path) ⇒ Object
47 48 49 50 51 52 53 54 55 |
# File 'lib/drb_fileserver_plus.rb', line 47 def mkdir(path) file_op {|f| f.mkdir File.join(@nodes.first, path) } if @sps then @sps.notice "%s/mkdir: %s" % [@topic, File.join(@nodes.first, path)] end end |
#mkdir_p(path) ⇒ Object
57 58 59 60 61 62 63 64 65 |
# File 'lib/drb_fileserver_plus.rb', line 57 def mkdir_p(path) file_op {|f| f.mkdir_p File.join(@nodes.first, path) } if @sps then @sps.notice "%s/mkdir_p: %s" % [@topic, File.join(@nodes.first, path)] end end |
#mv(path, path2) ⇒ Object
67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/drb_fileserver_plus.rb', line 67 def mv(path, path2) file_op do |f| f.mv File.join(@nodes.first, path), File.join(@nodes.first, path2) end if @sps then @sps.notice "%s/mv: %s %s" % [@topic, File.join(@nodes.first, path), File.join(@nodes.first, path2)] end end |
#read(fname) ⇒ Object
80 81 82 83 84 |
# File 'lib/drb_fileserver_plus.rb', line 80 def read(fname) file_op {|f| f.read File.join(@nodes.first, fname) } end |
#rm(fname) ⇒ Object
86 87 88 89 90 91 92 93 94 |
# File 'lib/drb_fileserver_plus.rb', line 86 def rm(fname) file_op {|f| f.rm File.join(@nodes.first, fname) } if @sps then @sps.notice "%s/rm: %s" % [@topic, File.join(@nodes.first, fname)] end end |
#write(fname, content) ⇒ Object
96 97 98 99 100 101 102 103 104 |
# File 'lib/drb_fileserver_plus.rb', line 96 def write(fname, content) file_op {|f| f.write File.join(@nodes.first, fname), content } if @sps then @sps.notice("%s/write: %s" % [@topic, File.join(@nodes.first, fname)]) end end |
#zip(fname, a) ⇒ Object
106 107 108 109 110 111 112 113 114 |
# File 'lib/drb_fileserver_plus.rb', line 106 def zip(fname, a) file_op {|f| f.zip File.join(@nodes.first, fname), a } if @sps then @sps.notice "%s/zip: %s" % [@topic, File.join(@nodes.first, fname)] end end |