Class: DRbFileServer
- Inherits:
-
Object
- Object
- DRbFileServer
- Defined in:
- lib/drb_fileserver_plus.rb
Instance Attribute Summary collapse
-
#nodes ⇒ Object
Returns the value of attribute nodes.
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
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
#nodes ⇒ Object
Returns the value of attribute nodes.
14 15 16 |
# File 'lib/drb_fileserver_plus.rb', line 14 def nodes @nodes end |
Instance Method Details
#cp(path, path2) ⇒ 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 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 |
#exists?(fname) ⇒ Boolean
40 41 42 43 44 45 46 47 |
# File 'lib/drb_fileserver_plus.rb', line 40 def exists?(fname) file_op do |f| node = 'dfs://' + @nodes.first f.exists? File.join(node, fname) end end |
#ls(path) ⇒ Object
49 50 51 52 53 54 55 56 |
# File 'lib/drb_fileserver_plus.rb', line 49 def ls(path) file_op do |f| node = 'dfs://' + @nodes.first f.ls File.join(node, path) end end |
#mkdir(path) ⇒ Object
58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/drb_fileserver_plus.rb', line 58 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
73 74 75 76 77 78 79 80 81 82 83 84 85 86 |
# File 'lib/drb_fileserver_plus.rb', line 73 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
88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 |
# File 'lib/drb_fileserver_plus.rb', line 88 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
104 105 106 107 108 109 110 111 |
# File 'lib/drb_fileserver_plus.rb', line 104 def read(fname) file_op do |f| node = 'dfs://' + @nodes.first f.read File.join(node, fname) end end |
#rm(fname) ⇒ Object
113 114 115 116 117 118 119 120 121 122 123 124 125 126 |
# File 'lib/drb_fileserver_plus.rb', line 113 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 |
#write(fname, content) ⇒ Object
128 129 130 131 132 133 134 135 136 137 138 139 140 141 |
# File 'lib/drb_fileserver_plus.rb', line 128 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
143 144 145 146 147 148 149 150 151 152 153 154 155 156 |
# File 'lib/drb_fileserver_plus.rb', line 143 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 |