class DRbFileServer::FileX
Public Class Methods
new(path='.')
click to toggle source
# File lib/drb_fileserver.rb, line 15 def initialize(path='.') @path = path end
Public Instance Methods
cp(path, path2)
click to toggle source
# File lib/drb_fileserver.rb, line 21 def cp(path, path2) #puts 'cp: ' + [File.join(@path, path), File.join(@path, path2)].inspect FileUtils.cp File.join(@path, path), File.join(@path, path2) end
directory?(filename)
click to toggle source
# File lib/drb_fileserver.rb, line 26 def directory?(filename) File.directory? File.join(@path, filename) end
exists?(filename)
click to toggle source
# File lib/drb_fileserver.rb, line 30 def exists?(filename) File.exists? File.join(@path, filename) end
ls(rawpath)
click to toggle source
path can include a wildcard and the switch -ltr
# File lib/drb_fileserver.rb, line 36 def ls(rawpath) path, switch = rawpath.split(/\s+/,2) wildcard = path.include?('*') ? '' : '*' path = File.join(path, wildcard) if File.exists? File.join(@path, path) a = Dir[File.join(@path, path)].map do |x| File.basename(x) end if switch == '-ltr' then a.sort_by {|x| File.mtime(File.join(@path, File.dirname(path), x)) } else a end end
mkdir(name)
click to toggle source
# File lib/drb_fileserver.rb, line 55 def mkdir(name) FileUtils.mkdir File.join(@path, name) end
mkdir_p(path)
click to toggle source
# File lib/drb_fileserver.rb, line 59 def mkdir_p(path) FileUtils.mkdir_p File.join(@path, path) end
mv(path, path2)
click to toggle source
# File lib/drb_fileserver.rb, line 63 def mv(path, path2) FileUtils.mv File.join(@path, path), File.join(@path, path2) end
read(filename)
click to toggle source
# File lib/drb_fileserver.rb, line 67 def read(filename) File.read File.join(@path, filename) end
rm(filename)
click to toggle source
# File lib/drb_fileserver.rb, line 71 def rm(filename) FileUtils.rm File.join(@path, filename) end
stop()
click to toggle source
# File lib/drb_fileserver.rb, line 75 def stop() puts 'stopping DFS service ...' DRb.stop_service 'connection closed' end
write(filename, s)
click to toggle source
# File lib/drb_fileserver.rb, line 81 def write(filename, s) File.write File.join(@path, filename), s end
zip(filename_zip, a)
click to toggle source
zips a file. Each array items contains a filename, and content to be written to the file.
# File lib/drb_fileserver.rb, line 88 def zip(filename_zip, a) Zip::File.open(filename_zip, Zip::File::CREATE) do |x| a.each do |filename, buffer| x.get_output_stream(filename) {|os| os.write buffer } end end end