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

160
config.rb
View file

@ -5,97 +5,101 @@ require 'ostruct'
require 'pp' require 'pp'
require 'find' require 'find'
class Config module SshfsMapper
attr_reader :options class Config
attr_reader :options
def initialize() def initialize()
user = if ENV['USER'] then user = if ENV['USER'] then
ENV['USER'] ENV['USER']
else
raise "Environment variable 'USER' is missing!"
end
home_dir = if ENV['HOME'] then
ENV['HOME']
else else
"/home/" + user raise "Environment variable 'USER' is missing!"
end end
xdg_dir = if ENV['XDG_CONFIG_HOME'] then home_dir = if ENV['HOME'] then
ENV['XDG_CONFIG_HOME'] ENV['HOME']
else else
home_dir + '/.config' "/home/" + user
end end
@options = OpenStruct.new( { xdg_dir = if ENV['XDG_CONFIG_HOME'] then
:config_dir => xdg_dir + '/sshfs-mapper', ENV['XDG_CONFIG_HOME']
:map_list => [], else
:initialize_enable => false, home_dir + '/.config'
:umount_enable => false, end
:target => nil,
:verbose_enable => false
} )
end
def parseFile @options = OpenStruct.new( {
puts "Parsing #{@options.config_dir}/config" :config_dir => xdg_dir + '/sshfs-mapper',
puts "Parsing maps..." :map_list => [],
:initialize_enable => false,
Find.find( @options.config_dir ) do |path| :umount_enable => false,
if File.file?( path ) :target => nil,
if File.basename( path ) =~ /.map$/ :verbose_enable => false
puts "* #{File.basename( path )}" } )
else
Find.prune # Don't look any further into this way
end
#total_size += FileTest.size(path)
end
end end
end def parseFile(&blk)
puts "Parsing #{@options.config_dir}/config"
puts "Parsing maps..."
def parseCmd( args ) maps = []
opts = OptionParser.new do |opts| Find.find( @options.config_dir ) do |path|
if File.file?( path )
opts.banner = "Usage: #{$0} [options]" if File.basename( path ) =~ /.map$/
puts "* #{File.basename( path )}"
opts.separator "" maps.push( path )
opts.separator "Specific options:" if blk then yield path end
else
opts.on('-t', '--target TARGET', 'Mount only specified target') do |target| Find.prune # Don't look any further into this way
@options.resize_enable = true
@options.resize_width = resizeX.to_i
@options.resize_height = resizeY.to_i
end
opts.on('-u', '--umount', 'Umount') do |umount|
@options.umount_enable = umount
end
opts.on('-i', '--initialize',
'Populate default configuration and example map' ) do |init|
@options.initialize_enable = init
end end
#total_size += FileTest.size(path)
opts.on('-v', '--[no-]verbose', 'Run verbosely' ) do |verbose| end
@options.verbose_enable = verbose
end end
return maps
end end
begin def parseCmd( args )
opts.parse!( args ) opts = OptionParser.new do |opts|
rescue OptionParser::ParseError => e
puts e.message
exit 1
end
@options
end
def to_s opts.banner = "Usage: #{$0} [options]"
s = []
s << "config_file = #{@options.config_file}" opts.separator ""
s << "verbose_enable = #{@options.verbose_enable}" opts.separator "Specific options:"
s.join("\n")
opts.on('-t', '--target TARGET', 'Mount only specified target') do |target|
@options.resize_enable = true
@options.resize_width = resizeX.to_i
@options.resize_height = resizeY.to_i
end
opts.on('-u', '--umount', 'Umount') do |umount|
@options.umount_enable = umount
end
opts.on('-i', '--initialize',
'Populate default configuration and example map' ) do |init|
@options.initialize_enable = init
end
opts.on('-v', '--[no-]verbose', 'Run verbosely' ) do |verbose|
@options.verbose_enable = verbose
end
end
begin
opts.parse!( args )
rescue OptionParser::ParseError => e
puts e.message
exit 1
end
@options
end
def to_s
s = []
s << "config_file = #{@options.config_file}"
s << "verbose_enable = #{@options.verbose_enable}"
s.join("\n")
end
end end
end end

12
map.rb
View file

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

View file

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