sshfs-mapper map: Added write() method.

git-svn-id: https://websvn.glenux.net/svn/Upoc/sshfs-mapper/trunk@1657 eaee96b3-f302-0410-b096-c6cfd47f7835
This commit is contained in:
Glenn Y. Rolland 2011-03-07 23:50:27 +00:00
parent 1cc3489f4a
commit 9bd9c6f490

View file

@ -1,33 +1,47 @@
require 'rubygems'
require 'rdebug/base' require 'rdebug/base'
module SshfsMapper module SshfsMapper
class Map class Map
attr_reader :path, :host, :port, :user, :map attr_reader :path,
:host,
:port,
:enable,
:user,
:map
class MapParseError < RuntimeError class MapParseError < RuntimeError
end end
def initialize( map_path ) CYPHER_ARCFOUR = :arcfour
CYPHER_AES256CBC = :"aes-256-cbc"
CYPHERS = [ CYPHER_ARCFOUR, CYPHER_AES256CBC ]
def initialize map_path
@path = map_path @path = map_path
@host = nil @host = nil
@port = 22 @port = 22
@enable = false
@user = nil @user = nil
@engine = :arcfour @cypher = :arcfour
@maps = {} @maps = {}
@debug = false @debug = false
self.load @path
end end
def parse def load path=nil
puts "Parsing map #{@path}" @path=path unless path.nil?
f = File.open( @path ) rdebug "Parsing map #{@path}"
f = File.open @path
linect = 0 linect = 0
f.each do |line| f.each do |line|
line = line.strip line = line.strip
linect += 1 linect += 1
#puts " [#{line}]"
case line case line
when /^\s*REMOTE_USER\s*=\s*(.*)\s*$/ then when /^\s*REMOTE_USER\s*=\s*(.*)\s*$/ then
@user = $1 @user = $1
@ -39,28 +53,37 @@ module SshfsMapper
@host = $1 @host = $1
rdebug "d: remote_host => #{$1}" rdebug "d: remote_host => #{$1}"
when /^\s*REMOTE_CYPHER\s*=\s*(.*)\s*$/ then when /^\s*REMOTE_CYPHER\s*=\s*(.*)\s*$/ then
cyphers = ["arcfour", "aes-256-cbc"] if CYPHERS.map{|x| x.to_s}.include? $1 then
if cyphers.include? $1 then @host = $1.to_sym
@host = $1
end end
when /^\s*MAP\s*=\s*(.*)\s+(.*)\s*$/ then when /^\s*MAP\s*=\s*(.*)\s+(.*)\s*$/ then
@maps[$1] = $2 @maps[$1] = $2
rdebug "d: map #{$1} => #{$2}" rdebug "d: map #{$1} => #{$2}"
when /^\s*$/ then when /^\s*$/,/^\s*#/ then
rdebug "d: dropping empty line" rdebug "d: dropping empty line"
else else
raise MapParseError, "parse error at #{@path}:#{linect}" raise MapParseError, "parse error at #{@path}:#{linect}"
end end
end end
f.close f.close
# end
def write path=nil
@path=path unless path.nil?
File.open @path, "w" do |f|
f.puts "REMOTE_USER=%s" % @user
f.puts "REMOTE_PORT=%s" % @port
f.puts "REMOTE_HOST=%s" % @host
f.puts "REMOTE_CYPHER=%s" % @cypher
end
end end
def alive? def alive?
#FIXME: test liveness #FIXME: test liveness
end end
def is_connected? def connected?
#FIXME test if connected / mounted #FIXME test if connected / mounted
end end