class DRbFileClient
Public Class Methods
new(location=nil, host: nil, port: '61010', debug: false)
click to toggle source
# File lib/drb_fileclient.rb, line 13 def initialize(location=nil, host: nil, port: '61010', debug: false) @debug = debug if location then host = location[/(?<=^dfs:\/\/)[^\/:]+/] port = location[/(?<=^dfs:\/\/)[^:]+:(\d+)/,1] || '61010' @directory = location[/(?<=^dfs:\/\/)[^\/]+\/(.*)/,1] end DRb.start_service end
Public Instance Methods
chdir(raw_path)
click to toggle source
# File lib/drb_fileclient.rb, line 29 def chdir(raw_path) return Dir.chdir raw_path unless @directory or raw_path =~ /^dfs:\/\// if raw_path[0] == '/' then directory = raw_path[1..-1] elsif raw_path =~ /^dfs:\/\// @file, directory = parse_path(raw_path) else directory = File.join(@directory, raw_path) end if @file.exists? directory then @directory = directory else 'No such file or directory' end end
cp(raw_path, raw_path2)
click to toggle source
# File lib/drb_fileclient.rb, line 49 def cp(raw_path, raw_path2) puts 'inside cp'.info if @debug if raw_path =~ /^dfs:\/\// then if @debug then puts ('raw_path: ' + raw_path.inspect).debug puts ('raw_path2: ' + raw_path2.inspect).debug end if raw_path[/^dfs:\/\/([^\/]+)/] == raw_path2[/^dfs:\/\/([^\/]+)/] then _, path = parse_path(raw_path) @file, path2 = parse_path(raw_path2) @file.cp path, path2 else @file, path = parse_path(raw_path) file2, path2 = parse_path(raw_path2) content = @file.read path file2.write path2, content end elsif raw_path2 =~ /dfs:\/\// then puts 'option2'.info if @debug file2, path2 = parse_path(raw_path2) puts ('path2: ' + path2.inspect).debug if @debug file2.write path2, File.read(raw_path) else puts 'option3'.info if @debug FileUtils.cp raw_path, raw_path2 end end
directory?(filename=@filename)
click to toggle source
# File lib/drb_fileclient.rb, line 93 def directory?(filename=@filename) return File.directory? filename unless @directory or filename =~ /^dfs:\/\// if filename =~ /^dfs:\/\// then @file, filename2 = parse_path(filename) else filename2 = File.join(@directory, filename) end @file.directory?(filename2) end
exists?(filename=@filename)
click to toggle source
# File lib/drb_fileclient.rb, line 108 def exists?(filename=@filename) return File.exists? filename unless @directory or filename =~ /^dfs:\/\// if filename =~ /^dfs:\/\// then @file, filename2 = parse_path(filename) else filename2 = File.join(@directory, filename) end @file.exists?(filename2) end
Also aliased as: exist?
ls(raw_path)
click to toggle source
# File lib/drb_fileclient.rb, line 125 def ls(raw_path) return Dir[raw_path] unless @directory or raw_path =~ /^dfs:\/\// if raw_path[0] == '/' then path = raw_path[1..-1] elsif raw_path =~ /^dfs:\/\// @file, path = parse_path(raw_path) else path = File.join(@directory, raw_path) end @file.ls path end
mkdir(name)
click to toggle source
# File lib/drb_fileclient.rb, line 141 def mkdir(name) return FileUtils.mkdir name unless @directory or name =~ /^dfs:\/\// @file, path = parse_path(name) @file.mkdir path end
mkdir_p(raw_path)
click to toggle source
# File lib/drb_fileclient.rb, line 149 def mkdir_p(raw_path) unless @directory or raw_path =~ /^dfs:\/\// then return FileUtils.mkdir_p raw_path end if raw_path =~ /^dfs:\/\// then @file, filepath = parse_path(raw_path) else filepath = File.join(@directory, raw_path) end @file.mkdir_p filepath end
mv(raw_path, raw_path2)
click to toggle source
# File lib/drb_fileclient.rb, line 164 def mv(raw_path, raw_path2) unless @directory or raw_path =~ /^dfs:\/\// then return FileUtils.mv raw_path, raw_path2 end if raw_path =~ /^dfs:\/\// then _, path = parse_path(raw_path) else path = File.join(@directory, raw_path) end if raw_path2 =~ /^dfs:\/\// then _, path2 = parse_path(raw_path2) else path2 = File.join(@directory, raw_path2) end @file.mv path, path2 end
pwd()
click to toggle source
# File lib/drb_fileclient.rb, line 185 def pwd() return Dir.pwd unless @directory '/' + @directory if @file end
read(filename=@filename)
click to toggle source
# File lib/drb_fileclient.rb, line 193 def read(filename=@filename) return File.read filename, s unless @directory or filename =~ /^dfs:\/\// if filename =~ /^dfs:\/\// then @file, path = parse_path(filename) else path = File.join(@directory, filename) end @file.read path end
rm(path)
click to toggle source
# File lib/drb_fileclient.rb, line 206 def rm(path) return FileUtils.rm path unless @directory or path =~ /^dfs:\/\// if path =~ /^dfs:\/\// then @file, path2 = parse_path( path) else path2 = File.join(@directory, path) end @file.rm path2 end
write(filename=@filename, s)
click to toggle source
# File lib/drb_fileclient.rb, line 220 def write(filename=@filename, s) return File.write filename, s unless @directory or filename =~ /^dfs:\/\// if filename =~ /^dfs:\/\// then @file, path = parse_path(filename) else path = File.join(@directory, filename) end @file.write path, s end
zip(filename_zip, a)
click to toggle source
# File lib/drb_fileclient.rb, line 234 def zip(filename_zip, a) puts '@directory: ' + @directory.inspect if @debug unless @directory or filename_zip =~ /^dfs:\/\// then Zip::File.open(zipfile_zip, Zip::File::CREATE) do |x| a.each do |filename, buffer| x.get_output_stream(filename) {|os| os.write buffer } end end end if filename_zip =~ /^dfs:\/\// then @file, filepath = parse_path(filename_zip) else filepath = File.join(@directory, filename_zip) end @file.zip filepath, a end
Private Instance Methods
parse_path(filename)
click to toggle source
# File lib/drb_fileclient.rb, line 262 def parse_path(filename) host = filename[/(?<=^dfs:\/\/)[^\/:]+/] @host = host if host port = filename[/(?<=^dfs:\/\/)[^:]+:(\d+)/,1] || '61010' file_server = DRbObject.new nil, "druby://#{host || @host}:#{port}" [file_server, filename[/(?<=^dfs:\/\/)[^\/]+\/(.*)/,1]] end