sshfs-mapper: Reorganized code.

git-svn-id: https://websvn.glenux.net/svn/Upoc/sshfs-mapper/trunk@1655 eaee96b3-f302-0410-b096-c6cfd47f7835
This commit is contained in:
glenux 2011-03-07 23:25:47 +00:00
parent 2c979d9de2
commit b6fe3b2d35
3 changed files with 13 additions and 12 deletions

View file

@ -4,22 +4,22 @@
$DEBUG = true $DEBUG = true
$VERBOSE = true $VERBOSE = true
require 'config' require 'sshfs-mapper/config'
require 'map' require 'sshfs-mapper/map'
module SshfsMapper module SshfsMapper
class SshfsMapper class SshfsMapper
def initialize() def initialize
@active_maps = nil @active_maps = nil
puts "-- sshfs-mapper --" puts "-- sshfs-mapper --"
conf = Config.new conf = Config.new
conf.parseCmd ARGV conf.parse_cmd_line ARGV
@active_maps = conf.parseFile @active_maps = conf.parse_file
puts conf puts conf
end end
def run() def run
if @active_maps.nil? then if @active_maps.nil? then
return return
end end
@ -35,3 +35,4 @@ end
app = SshfsMapper::SshfsMapper.new app = SshfsMapper::SshfsMapper.new
app.run app.run

View file

@ -11,7 +11,7 @@ module SshfsMapper
attr_reader :maps_active attr_reader :maps_active
attr_reader :maps attr_reader :maps
def initialize() def initialize
user = if ENV['USER'] then user = if ENV['USER'] then
ENV['USER'] ENV['USER']
else else
@ -39,20 +39,20 @@ module SshfsMapper
@verbose_enable = false @verbose_enable = false
end end
def parseFile( &blk ) def parse_file &blk
puts "Config: #{@config_dir}/config" puts "Config: #{@config_dir}/config"
maps = [] maps = []
Find.find( @config_dir ) do |path| Find.find( @config_dir ) do |path|
if File.file?( path ) if File.file? path
if File.basename( path ) =~ /.map$/ if File.basename( path ) =~ /.map$/
begin begin
map = Map.new( path ) map = Map.new path
map.parse() map.parse()
if blk then if blk then
yield map yield map
else else
maps.push( map ) maps.push map
end end
rescue rescue
# error while parsing map # error while parsing map
@ -64,7 +64,7 @@ module SshfsMapper
return maps return maps
end end
def parseCmd( args ) def parse_cmd_line args
opts = OptionParser.new do |opts| opts = OptionParser.new do |opts|
opts.banner = "Usage: #{$0} [options]" opts.banner = "Usage: #{$0} [options]"