sshfs-mapper map: Clean up ruby code.

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

View file

@ -1,8 +1,10 @@
require 'rdebug/base'
module SshfsMapper module SshfsMapper
class Map class Map
attr_reader :path, :host, :port, :user, :map attr_reader :path, :host, :port, :user, :map
@@debug = false
class MapParseError < RuntimeError class MapParseError < RuntimeError
end end
@ -14,6 +16,7 @@ module SshfsMapper
@user = nil @user = nil
@engine = :arcfour @engine = :arcfour
@maps = {} @maps = {}
@debug = false
end end
def parse def parse
@ -28,13 +31,13 @@ module SshfsMapper
case line case line
when /^\s*REMOTE_USER\s*=\s*(.*)\s*$/ then when /^\s*REMOTE_USER\s*=\s*(.*)\s*$/ then
@user = $1 @user = $1
puts "d: remote_user => #{$1}" if @@debug rdebug "d: remote_user => #{$1}"
when /^\s*REMOTE_PORT\s*=\s*(.*)\s*$/ then when /^\s*REMOTE_PORT\s*=\s*(.*)\s*$/ then
@port = $1.to_i @port = $1.to_i
puts "d: remote_port => #{$1}" if @@debug rdebug "d: remote_port => #{$1}"
when /^\s*REMOTE_HOST\s*=\s*(.*)\s*$/ then when /^\s*REMOTE_HOST\s*=\s*(.*)\s*$/ then
@host = $1 @host = $1
puts "d: remote_host => #{$1}" if @@debug 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"] cyphers = ["arcfour", "aes-256-cbc"]
if cyphers.include? $1 then if cyphers.include? $1 then
@ -42,9 +45,9 @@ module SshfsMapper
end end
when /^\s*MAP\s*=\s*(.*)\s+(.*)\s*$/ then when /^\s*MAP\s*=\s*(.*)\s+(.*)\s*$/ then
@maps[$1] = $2 @maps[$1] = $2
puts "d: map #{$1} => #{$2}" if @@debug rdebug "d: map #{$1} => #{$2}"
when /^\s*$/ then when /^\s*$/ then
puts "d: dropping empty line" if @@debug rdebug "d: dropping empty line"
else else
raise MapParseError, "parse error at #{@path}:#{linect}" raise MapParseError, "parse error at #{@path}:#{linect}"
end end
@ -53,7 +56,7 @@ module SshfsMapper
# #
end end
def is_alive? def alive?
#FIXME: test liveness #FIXME: test liveness
end end
@ -61,7 +64,7 @@ module SshfsMapper
#FIXME test if connected / mounted #FIXME test if connected / mounted
end end
def connect() def connect
puts "[#{File.basename @path}] Connecting..." puts "[#{File.basename @path}] Connecting..."
puts " #{@user}@#{@host}:#{@port}" puts " #{@user}@#{@host}:#{@port}"
puts " maps = %s" % @maps.map{ |k,v| "%s => %s" % [ k, v ] }.join(', ') puts " maps = %s" % @maps.map{ |k,v| "%s => %s" % [ k, v ] }.join(', ')
@ -70,7 +73,7 @@ module SshfsMapper
# mount # mount
end end
def disconnect() def disconnect
puts "Disconnecting map #{@path}" puts "Disconnecting map #{@path}"
# umount # umount
end end