From acdc03a4c8d795474f8fe00edf9d42f097d2fc51 Mon Sep 17 00:00:00 2001 From: glenux Date: Sun, 24 Jul 2011 16:49:07 +0000 Subject: [PATCH] sshfs-mapper qasim: check mounted maps in menu. git-svn-id: https://websvn.glenux.net/svn/Upoc/sshfs-mapper/trunk@1711 eaee96b3-f302-0410-b096-c6cfd47f7835 --- bin/qasim-gui.rb | 3 +++ qasim/config.rb | 5 +++-- qasim/map.rb | 34 ++++++++++++++++++++++++++++++---- 3 files changed, 36 insertions(+), 6 deletions(-) diff --git a/bin/qasim-gui.rb b/bin/qasim-gui.rb index 8dcd992..1c34d2d 100755 --- a/bin/qasim-gui.rb +++ b/bin/qasim-gui.rb @@ -72,6 +72,9 @@ module Qasim end itemx = Qt::Action.new(map.name, @map_menu) itemx.setCheckable true; + if map.connected? then + itemx.setChecked true + end itemx.connect(SIGNAL(:triggered)) do action_trigger_map_item map, itemx end diff --git a/qasim/config.rb b/qasim/config.rb index f0c6b88..9a8ee88 100644 --- a/qasim/config.rb +++ b/qasim/config.rb @@ -8,6 +8,7 @@ require 'find' require 'rubygems' require 'rdebug/base' +require 'qasim/map' module Qasim class Config @@ -36,7 +37,7 @@ module Qasim home_dir + '/.config' end - mnt_dir = File.join home_dir, "mnt" + @mnt_dir = File.join home_dir, "mnt" @config_dir = xdg_dir + '/sshfs-mapper' @config_file = nil @@ -56,7 +57,7 @@ module Qasim if File.file? path if File.basename( path ) =~ /.map$/ begin - map = Map.new path + map = Map.new self, path yield map if block_given? maps.push map rescue diff --git a/qasim/map.rb b/qasim/map.rb index cc0dd57..7bc6678 100644 --- a/qasim/map.rb +++ b/qasim/map.rb @@ -1,6 +1,7 @@ require 'rubygems' require 'rdebug/base' +require 'qasim/config' module Qasim @@ -20,7 +21,8 @@ module Qasim CYPHER_AES256CBC = "aes-256-cbc".to_sym CYPHERS = [ CYPHER_ARCFOUR, CYPHER_AES256CBC ] - def initialize map_path + def initialize config, map_path + @config = config @path = map_path @host = nil @port = 22 @@ -44,15 +46,18 @@ module Qasim line = line.strip linect += 1 - while line =~ /\$(.*)/ do + while line =~ /\$(\w+)/ do puts "FOUND PATTERN %s => %s" % [$1, local_env[$1]] case line - when /\$\{(.+?)\}/ then + when /\$\{(.+)\}/ then pattern = $1 - line.gsub!(/\$\{#{attern}\}/,local_env[pattern]) + puts pattern + line.gsub!(/\$\{#{pattern}\}/,local_env[pattern]) when /\$(\w+)/ then pattern = $1 line.gsub!(/\$#{pattern}/,local_env[pattern]) + else + puts "unknown pattern: %s" % line end end @@ -100,6 +105,27 @@ module Qasim def connected? #FIXME test if connected / mounted + f = File.open("/proc/mounts") + sshfs_mounted = (f.readlines.select do |line| + line =~ /\s+fuse.sshfs\s+/ + end).map do |line| + line.split(/\s+/)[1] + end + f.close + + score = 0 + @maps.each do |name, remotepath| + score += 1 + local_path = File.join @config.mnt_dir, name + + if sshfs_mounted.include? local_path then + score -= 1 + end + end + if score == 0 then return true + else return false + # FIXME: explain why ? + end end def connect &block