sshfs-mapper: Updates for the ruby version.
git-svn-id: https://websvn.glenux.net/svn/Upoc/sshfs-mapper/trunk@1462 eaee96b3-f302-0410-b096-c6cfd47f7835
This commit is contained in:
parent
5ba60f4793
commit
f53924cfbd
3 changed files with 70 additions and 37 deletions
53
config.rb
53
config.rb
|
@ -1,5 +1,5 @@
|
|||
#!/usr/bin/ruby
|
||||
# vim: set ts=2 sw=2:
|
||||
# vim: set ts=4 sw=4:
|
||||
|
||||
require 'optparse'
|
||||
require 'ostruct'
|
||||
|
@ -8,7 +8,8 @@ require 'find'
|
|||
|
||||
module SshfsMapper
|
||||
class Config
|
||||
attr_reader :options
|
||||
attr_reader :maps_active
|
||||
attr_reader :maps
|
||||
|
||||
def initialize()
|
||||
user = if ENV['USER'] then
|
||||
|
@ -29,24 +30,23 @@ module SshfsMapper
|
|||
home_dir + '/.config'
|
||||
end
|
||||
|
||||
@options = OpenStruct.new( {
|
||||
:config_dir => xdg_dir + '/sshfs-mapper',
|
||||
:map_list => [],
|
||||
:initialize_enable => false,
|
||||
:umount_enable => false,
|
||||
:target => nil,
|
||||
:verbose_enable => false
|
||||
} )
|
||||
@config_dir = xdg_dir + '/sshfs-mapper'
|
||||
@maps = []
|
||||
@initialize_enable = false
|
||||
@umount_enable = false
|
||||
@target = nil
|
||||
@verbose_enable = false
|
||||
end
|
||||
|
||||
def parseFile( &blk )
|
||||
puts "Parsing config #{@options.config_dir}/config"
|
||||
puts "Parsing config #{@config_dir}/config"
|
||||
|
||||
maps = []
|
||||
Find.find( @options.config_dir ) do |path|
|
||||
Find.find( @config_dir ) do |path|
|
||||
if File.file?( path )
|
||||
if File.basename( path ) =~ /.map$/
|
||||
puts "* #{File.basename( path )}"
|
||||
begin
|
||||
map = Map.new( path )
|
||||
map.parse()
|
||||
if blk then
|
||||
|
@ -54,8 +54,9 @@ module SshfsMapper
|
|||
else
|
||||
maps.push( map )
|
||||
end
|
||||
else
|
||||
Find.prune # Don't look any further into this way
|
||||
rescue
|
||||
# error while parsing map
|
||||
end
|
||||
end
|
||||
#total_size += FileTest.size(path)
|
||||
end
|
||||
|
@ -71,39 +72,43 @@ module SshfsMapper
|
|||
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
|
||||
opts.on('-a', '--all', 'Mount all targets (disables -s)') do |all|
|
||||
@all_enable = all
|
||||
end
|
||||
|
||||
#FIXME: use target list there
|
||||
opts.on('-s', '--select TARGET', 'Mount only specified target') do |target|
|
||||
@targets << target
|
||||
end
|
||||
|
||||
opts.on('-u', '--umount', 'Umount') do |umount|
|
||||
@options.umount_enable = umount
|
||||
@umount_enable = umount
|
||||
end
|
||||
|
||||
opts.on('-i', '--initialize',
|
||||
'Populate default configuration and example map' ) do |init|
|
||||
@options.initialize_enable = init
|
||||
@initialize_enable = init
|
||||
end
|
||||
|
||||
opts.on('-v', '--[no-]verbose', 'Run verbosely' ) do |verbose|
|
||||
@options.verbose_enable = verbose
|
||||
@verbose_enable = verbose
|
||||
end
|
||||
end
|
||||
|
||||
begin
|
||||
opts.parse!( args )
|
||||
rescue OptionParser::ParseError => e
|
||||
puts opts.to_s
|
||||
puts ""
|
||||
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 << "config_file = #{@config_file}"
|
||||
s << "verbose_enable = #{@verbose_enable}"
|
||||
s.join("\n")
|
||||
end
|
||||
end
|
||||
|
|
30
map.rb
30
map.rb
|
@ -1,15 +1,43 @@
|
|||
module SshfsMapper
|
||||
class Map
|
||||
attr_reader :path, :host, :port, :user, :map
|
||||
|
||||
def initialize( map_path )
|
||||
@path = map_path
|
||||
@host = nil
|
||||
@port = 22
|
||||
@user = nil
|
||||
@map = {}
|
||||
end
|
||||
|
||||
def parse()
|
||||
puts "Parsing map #{@path}"
|
||||
#
|
||||
File.open( @path ) do |f|
|
||||
f.each do |line|
|
||||
case line
|
||||
when /^MAP\s*=\s*(\S+)\s*(\S+)\s*$/ then
|
||||
@map[$1] = $2
|
||||
when /^REMOTE_HOST\s*=\s*(\S+)\s*$/ then
|
||||
@host = $1
|
||||
when /^REMOTE_PORT\s*=\s*(\S+)\s*$/ then
|
||||
@port = $1
|
||||
when /^REMOTE_USER\s*=\s*(\S+)\s*$/ then
|
||||
@user = $1
|
||||
when /^\s*$/ then
|
||||
# skip
|
||||
else
|
||||
puts "unexpectd line '#{line}'"
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def is_alive?
|
||||
#FIXME: test liveness
|
||||
end
|
||||
|
||||
def is_connected?
|
||||
#FIXME test if connected / mounted
|
||||
end
|
||||
|
||||
def connect()
|
||||
|
|
|
@ -7,20 +7,20 @@ require 'map'
|
|||
module SshfsMapper
|
||||
class SshfsMapper
|
||||
def initialize()
|
||||
@maps = nil
|
||||
@active_maps = nil
|
||||
puts "-- sshfs-mapper --"
|
||||
conf = Config.new
|
||||
conf.parseCmd ARGV
|
||||
@maps = conf.parseFile
|
||||
@active_maps = conf.parseFile
|
||||
puts conf
|
||||
end
|
||||
|
||||
|
||||
def run()
|
||||
if @maps.nil? then
|
||||
if @active_maps.nil? then
|
||||
return
|
||||
end
|
||||
@maps.each do |map|
|
||||
@active_maps.each do |map|
|
||||
map.connect()
|
||||
end
|
||||
puts "--run"
|
||||
|
|
Loading…
Reference in a new issue