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:
glenux 2009-05-22 21:01:23 +00:00
parent 25cf230fe4
commit a2b00e87ae
3 changed files with 116 additions and 106 deletions

View file

@ -5,7 +5,8 @@ require 'ostruct'
require 'pp' require 'pp'
require 'find' require 'find'
class Config module SshfsMapper
class Config
attr_reader :options attr_reader :options
def initialize() def initialize()
@ -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 )
@ -97,5 +101,5 @@ class Config
s << "verbose_enable = #{@options.verbose_enable}" s << "verbose_enable = #{@options.verbose_enable}"
s.join("\n") s.join("\n")
end end
end
end end

10
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() class SshfsMapper
end
def self.loadFromFile( filename )
end
end
class Config
end
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
app = SshfsMapper::SshfsMapper.new
SshfsMapper.new app.run