class RemoteInfo
Constants
- FILENAME
Attributes
host[RW]
netns[RW]
operations[RW]
owner[RW]
path[RW]
port[RW]
user[RW]
Public Class Methods
filename(folder)
click to toggle source
# File lib/commons.rb, line 36 def self.filename(folder) return File.join(folder, FILENAME) end
load(folder=".")
click to toggle source
# File lib/commons.rb, line 30 def self.load(folder=".") rinfo = RemoteInfo.new rinfo.read_info(folder) return rinfo end
lock_all(local, prevent_write=true) { || ... }
click to toggle source
# File lib/commons.rb, line 96 def self.lock_all(local, prevent_write=true) if (prevent_write) FS.each_remote_info(local) do |rinfo| OS.run "chmod -w \"#{rinfo}\"" end end yield if (prevent_write) FS.each_remote_info(local) do |rinfo| OS.run "chmod +w \"#{rinfo}\"" end end end
new()
click to toggle source
# File lib/commons.rb, line 20 def initialize @netns = nil @owner = nil @port = nil @user = nil @operations = "rw" end
unlock_all(local)
click to toggle source
# File lib/commons.rb, line 92 def self.unlock_all(local) self.lock_all(local, true) {} end
Public Instance Methods
can_pull?()
click to toggle source
# File lib/commons.rb, line 40 def can_pull? return @operations.include? "r" end
can_push?()
click to toggle source
# File lib/commons.rb, line 44 def can_push? return @operations.include? "w" end
read_info(folder)
click to toggle source
# File lib/commons.rb, line 48 def read_info(folder) info = File.read(File.join(folder, FILENAME)) rows = info.split "\n" rows.each do |r| key, value = *r.split("\t") key = key.strip value = value.strip case key when "host" @host = value when "port" @port = value when "user" @user = value when "path" @path = value when "netns" @netns = value when "owner" @owner = value when "operations" @operations = value end end end
save_info(to=".")
click to toggle source
# File lib/commons.rb, line 77 def save_info(to=".") content = "" content += "host\t#@host\n" content += "port\t#@port\n" if @port content += "user\t#@user\n" if @user content += "path\t#@path\n" content += "netns\t#@netns\n" if @netns content += "owner\t#@owner\n" if @owner content += "operations\t#@operations\n" dest = to ? File.join(to, FILENAME) : FILENAME File.write dest, content end