sshfs-mapper: completed map, config & app class.

git-svn-id: https://websvn.glenux.net/svn/Upoc/sshfs-mapper/trunk@1363 eaee96b3-f302-0410-b096-c6cfd47f7835
This commit is contained in:
Glenn Y. Rolland 2009-05-22 21:01:23 +00:00
parent b31d20a0ce
commit 81a325116c
3 changed files with 116 additions and 106 deletions

View file

@ -5,6 +5,7 @@ require 'ostruct'
require 'pp' require 'pp'
require 'find' require 'find'
module SshfsMapper
class Config class Config
attr_reader :options attr_reader :options
@ -37,21 +38,24 @@ class Config
} ) } )
end end
def parseFile def parseFile(&blk)
puts "Parsing #{@options.config_dir}/config" puts "Parsing #{@options.config_dir}/config"
puts "Parsing maps..." puts "Parsing maps..."
maps = []
Find.find( @options.config_dir ) do |path| Find.find( @options.config_dir ) do |path|
if File.file?( path ) if File.file?( path )
if File.basename( path ) =~ /.map$/ if File.basename( path ) =~ /.map$/
puts "* #{File.basename( path )}" puts "* #{File.basename( path )}"
maps.push( path )
if blk then yield path end
else else
Find.prune # Don't look any further into this way Find.prune # Don't look any further into this way
end end
#total_size += FileTest.size(path) #total_size += FileTest.size(path)
end end
end end
return maps
end end
def parseCmd( args ) def parseCmd( args )
@ -98,4 +102,4 @@ class Config
s.join("\n") s.join("\n")
end end
end end
end

8
map.rb
View file

@ -1,6 +1,12 @@
module SshfsMapper
class Map class Map
def initialize def initialize
@host = nil
@port = 22
@user = nil
end end
end end
end

View file

@ -1,33 +1,33 @@
#!/usr/bin/ruby #!/usr/bin/ruby
require 'config' require 'config'
require 'map'
class Map module SshfsMapper
def initialize()
end
def self.loadFromFile( filename )
end
end
class Config
end
class SshfsMapper class SshfsMapper
def initialize() def initialize()
@maps = nil
puts "-- sshfs-mapper --" puts "-- sshfs-mapper --"
conf = Config.new conf = Config.new
conf.parseCmd ARGV conf.parseCmd ARGV
conf.parseFile @maps = conf.parseFile
puts conf puts conf
end end
def run()
if @maps.nil? then
return
end
@maps.each do |map_path|
map = Map.new( map_path )
end
puts "--run"
end end
end
end
SshfsMapper.new app = SshfsMapper::SshfsMapper.new
app.run