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
67
config.rb
67
config.rb
|
@ -1,5 +1,5 @@
|
||||||
#!/usr/bin/ruby
|
#!/usr/bin/ruby
|
||||||
# vim: set ts=2 sw=2:
|
# vim: set ts=4 sw=4:
|
||||||
|
|
||||||
require 'optparse'
|
require 'optparse'
|
||||||
require 'ostruct'
|
require 'ostruct'
|
||||||
|
@ -8,7 +8,8 @@ require 'find'
|
||||||
|
|
||||||
module SshfsMapper
|
module SshfsMapper
|
||||||
class Config
|
class Config
|
||||||
attr_reader :options
|
attr_reader :maps_active
|
||||||
|
attr_reader :maps
|
||||||
|
|
||||||
def initialize()
|
def initialize()
|
||||||
user = if ENV['USER'] then
|
user = if ENV['USER'] then
|
||||||
|
@ -29,33 +30,33 @@ module SshfsMapper
|
||||||
home_dir + '/.config'
|
home_dir + '/.config'
|
||||||
end
|
end
|
||||||
|
|
||||||
@options = OpenStruct.new( {
|
@config_dir = xdg_dir + '/sshfs-mapper'
|
||||||
:config_dir => xdg_dir + '/sshfs-mapper',
|
@maps = []
|
||||||
:map_list => [],
|
@initialize_enable = false
|
||||||
:initialize_enable => false,
|
@umount_enable = false
|
||||||
:umount_enable => false,
|
@target = nil
|
||||||
:target => nil,
|
@verbose_enable = false
|
||||||
:verbose_enable => false
|
|
||||||
} )
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def parseFile(&blk)
|
def parseFile( &blk )
|
||||||
puts "Parsing config #{@options.config_dir}/config"
|
puts "Parsing config #{@config_dir}/config"
|
||||||
|
|
||||||
maps = []
|
maps = []
|
||||||
Find.find( @options.config_dir ) do |path|
|
Find.find( @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 )}"
|
||||||
map = Map.new( path )
|
begin
|
||||||
map.parse()
|
map = Map.new( path )
|
||||||
if blk then
|
map.parse()
|
||||||
yield map
|
if blk then
|
||||||
else
|
yield map
|
||||||
maps.push( map )
|
else
|
||||||
|
maps.push( map )
|
||||||
|
end
|
||||||
|
rescue
|
||||||
|
# error while parsing map
|
||||||
end
|
end
|
||||||
else
|
|
||||||
Find.prune # Don't look any further into this way
|
|
||||||
end
|
end
|
||||||
#total_size += FileTest.size(path)
|
#total_size += FileTest.size(path)
|
||||||
end
|
end
|
||||||
|
@ -71,39 +72,43 @@ module SshfsMapper
|
||||||
opts.separator ""
|
opts.separator ""
|
||||||
opts.separator "Specific options:"
|
opts.separator "Specific options:"
|
||||||
|
|
||||||
opts.on('-t', '--target TARGET', 'Mount only specified target') do |target|
|
opts.on('-a', '--all', 'Mount all targets (disables -s)') do |all|
|
||||||
@options.resize_enable = true
|
@all_enable = all
|
||||||
@options.resize_width = resizeX.to_i
|
end
|
||||||
@options.resize_height = resizeY.to_i
|
|
||||||
|
#FIXME: use target list there
|
||||||
|
opts.on('-s', '--select TARGET', 'Mount only specified target') do |target|
|
||||||
|
@targets << target
|
||||||
end
|
end
|
||||||
|
|
||||||
opts.on('-u', '--umount', 'Umount') do |umount|
|
opts.on('-u', '--umount', 'Umount') do |umount|
|
||||||
@options.umount_enable = umount
|
@umount_enable = umount
|
||||||
end
|
end
|
||||||
|
|
||||||
opts.on('-i', '--initialize',
|
opts.on('-i', '--initialize',
|
||||||
'Populate default configuration and example map' ) do |init|
|
'Populate default configuration and example map' ) do |init|
|
||||||
@options.initialize_enable = init
|
@initialize_enable = init
|
||||||
end
|
end
|
||||||
|
|
||||||
opts.on('-v', '--[no-]verbose', 'Run verbosely' ) do |verbose|
|
opts.on('-v', '--[no-]verbose', 'Run verbosely' ) do |verbose|
|
||||||
@options.verbose_enable = verbose
|
@verbose_enable = verbose
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
begin
|
begin
|
||||||
opts.parse!( args )
|
opts.parse!( args )
|
||||||
rescue OptionParser::ParseError => e
|
rescue OptionParser::ParseError => e
|
||||||
|
puts opts.to_s
|
||||||
|
puts ""
|
||||||
puts e.message
|
puts e.message
|
||||||
exit 1
|
exit 1
|
||||||
end
|
end
|
||||||
@options
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def to_s
|
def to_s
|
||||||
s = []
|
s = []
|
||||||
s << "config_file = #{@options.config_file}"
|
s << "config_file = #{@config_file}"
|
||||||
s << "verbose_enable = #{@options.verbose_enable}"
|
s << "verbose_enable = #{@verbose_enable}"
|
||||||
s.join("\n")
|
s.join("\n")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
30
map.rb
30
map.rb
|
@ -1,15 +1,43 @@
|
||||||
module SshfsMapper
|
module SshfsMapper
|
||||||
class Map
|
class Map
|
||||||
|
attr_reader :path, :host, :port, :user, :map
|
||||||
|
|
||||||
def initialize( map_path )
|
def initialize( map_path )
|
||||||
@path = map_path
|
@path = map_path
|
||||||
@host = nil
|
@host = nil
|
||||||
@port = 22
|
@port = 22
|
||||||
@user = nil
|
@user = nil
|
||||||
|
@map = {}
|
||||||
end
|
end
|
||||||
|
|
||||||
def parse()
|
def parse()
|
||||||
puts "Parsing map #{@path}"
|
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
|
end
|
||||||
|
|
||||||
def connect()
|
def connect()
|
||||||
|
|
|
@ -7,20 +7,20 @@ require 'map'
|
||||||
module SshfsMapper
|
module SshfsMapper
|
||||||
class SshfsMapper
|
class SshfsMapper
|
||||||
def initialize()
|
def initialize()
|
||||||
@maps = nil
|
@active_maps = nil
|
||||||
puts "-- sshfs-mapper --"
|
puts "-- sshfs-mapper --"
|
||||||
conf = Config.new
|
conf = Config.new
|
||||||
conf.parseCmd ARGV
|
conf.parseCmd ARGV
|
||||||
@maps = conf.parseFile
|
@active_maps = conf.parseFile
|
||||||
puts conf
|
puts conf
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
def run()
|
def run()
|
||||||
if @maps.nil? then
|
if @active_maps.nil? then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
@maps.each do |map|
|
@active_maps.each do |map|
|
||||||
map.connect()
|
map.connect()
|
||||||
end
|
end
|
||||||
puts "--run"
|
puts "--run"
|
||||||
|
|
Loading…
Reference in a new issue