From 81a325116c0572fe26c9a2790b710f8c51d46257 Mon Sep 17 00:00:00 2001 From: "Glenn Y. Rolland" Date: Fri, 22 May 2009 21:01:23 +0000 Subject: [PATCH] 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 --- config.rb | 160 +++++++++++++++++++++++++----------------------- map.rb | 12 +++- sshfs-mapper.rb | 50 +++++++-------- 3 files changed, 116 insertions(+), 106 deletions(-) diff --git a/config.rb b/config.rb index 5a49d83..1f62771 100644 --- a/config.rb +++ b/config.rb @@ -5,97 +5,101 @@ require 'ostruct' require 'pp' require 'find' -class Config - attr_reader :options +module SshfsMapper + class Config + attr_reader :options - def initialize() - user = if ENV['USER'] then - ENV['USER'] - else - raise "Environment variable 'USER' is missing!" - end - - home_dir = if ENV['HOME'] then - ENV['HOME'] + def initialize() + user = if ENV['USER'] then + ENV['USER'] else - "/home/" + user + raise "Environment variable 'USER' is missing!" end - xdg_dir = if ENV['XDG_CONFIG_HOME'] then - ENV['XDG_CONFIG_HOME'] - else - home_dir + '/.config' - end + home_dir = if ENV['HOME'] then + ENV['HOME'] + else + "/home/" + user + end - @options = OpenStruct.new( { - :config_dir => xdg_dir + '/sshfs-mapper', - :map_list => [], - :initialize_enable => false, - :umount_enable => false, - :target => nil, - :verbose_enable => false - } ) - end + xdg_dir = if ENV['XDG_CONFIG_HOME'] then + ENV['XDG_CONFIG_HOME'] + else + home_dir + '/.config' + end - def parseFile - puts "Parsing #{@options.config_dir}/config" - puts "Parsing maps..." - - Find.find( @options.config_dir ) do |path| - if File.file?( path ) - if File.basename( path ) =~ /.map$/ - puts "* #{File.basename( path )}" - else - Find.prune # Don't look any further into this way - end - #total_size += FileTest.size(path) - end + @options = OpenStruct.new( { + :config_dir => xdg_dir + '/sshfs-mapper', + :map_list => [], + :initialize_enable => false, + :umount_enable => false, + :target => nil, + :verbose_enable => false + } ) end - end + def parseFile(&blk) + puts "Parsing #{@options.config_dir}/config" + puts "Parsing maps..." - def parseCmd( args ) - opts = OptionParser.new do |opts| - - opts.banner = "Usage: #{$0} [options]" - - opts.separator "" - opts.separator "Specific options:" - - 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 + maps = [] + Find.find( @options.config_dir ) do |path| + if File.file?( path ) + if File.basename( path ) =~ /.map$/ + puts "* #{File.basename( path )}" + maps.push( path ) + if blk then yield path end + else + Find.prune # Don't look any further into this way end - - opts.on('-v', '--[no-]verbose', 'Run verbosely' ) do |verbose| - @options.verbose_enable = verbose + #total_size += FileTest.size(path) + end end + return maps end - begin - opts.parse!( args ) - rescue OptionParser::ParseError => e - puts e.message - exit 1 - end - @options - end + def parseCmd( args ) + opts = OptionParser.new do |opts| - def to_s - s = [] - s << "config_file = #{@options.config_file}" - s << "verbose_enable = #{@options.verbose_enable}" - s.join("\n") + opts.banner = "Usage: #{$0} [options]" + + opts.separator "" + opts.separator "Specific options:" + + 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 - diff --git a/map.rb b/map.rb index 091d348..1d510b3 100644 --- a/map.rb +++ b/map.rb @@ -1,6 +1,12 @@ +module SshfsMapper + class Map + def initialize + @host = nil + @port = 22 + @user = nil + + + end -class Map - def initialize end - end diff --git a/sshfs-mapper.rb b/sshfs-mapper.rb index 8211d41..222b783 100755 --- a/sshfs-mapper.rb +++ b/sshfs-mapper.rb @@ -1,33 +1,33 @@ #!/usr/bin/ruby 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 - - def self.loadFromFile( filename ) - end - - end -class Config - -end - - -class SshfsMapper - def initialize() - puts "-- sshfs-mapper --" - conf = Config.new - conf.parseCmd ARGV - conf.parseFile - puts conf - end - -end - - -SshfsMapper.new +app = SshfsMapper::SshfsMapper.new +app.run