From 9cb84c06bb3a5753f95bd090b3847193f2b27b0b Mon Sep 17 00:00:00 2001 From: "Glenn Y. Rolland" Date: Thu, 28 Jul 2011 15:41:46 +0200 Subject: [PATCH] Fixed error handling in GUI. * Renamed map components of a map to link. * Fixed error handling for multiple links. --- bin/qasim-gui.rb | 31 +++++++++++++++++++++++++++---- qasim/map.rb | 21 +++++++++++++-------- 2 files changed, 40 insertions(+), 12 deletions(-) diff --git a/bin/qasim-gui.rb b/bin/qasim-gui.rb index 1c34d2d..f373f19 100755 --- a/bin/qasim-gui.rb +++ b/bin/qasim-gui.rb @@ -6,6 +6,8 @@ $DEBUG = true $VERBOSE = true require 'pp' +require 'set' + require 'qasim/constants' require 'qasim/config' require 'qasim/map' @@ -27,6 +29,8 @@ module Qasim @map_menu = nil @context_menu = nil + @connect_error = {} + @connect_running = {} end def dbus_notify title, body, icon @@ -94,19 +98,38 @@ module Qasim puts "connect !" begin success = true - map.connect do |cmd,cmd_args| + + @connect_error[map.path] = Set.new + @connect_running[map.path] = 0 + map.connect do |linkname,cmd,cmd_args| process = Qt::Process.new process.connect(SIGNAL('finished(int, QProcess::ExitStatus)')) do |exitcode,exitstatus| puts "exitcode = %s, exitstatus = %s" % [exitcode, exitstatus] + @connect_running[map.path] -= 1 if exitcode != 0 then - success = false - item.setChecked success + @connect_error[map.path].add linkname + else + end + if @connect_running[map.path] == 0 then + # display someting + if @connect_error[map.path] == 0 then + + dbus_notify "%s (%s)" % [APP_NAME, map.name], + "Map connected successfully", + 'dialog-information' + else + erroneous = @connect_error[map.path].to_a.join(', ') + dbus_notify "%s (%s)" % [APP_NAME, map.name], + ("Unable to connect map
" + + "Broken link(s): %s" % erroneous), + 'dialog-error' + end end end + @connect_running[map.path] += 1 process.start cmd, cmd_args end - dbus_notify map.name, "Map connected successfully", 'dialog-information' rescue Map::ConnectError => e puts e.inspect end diff --git a/qasim/map.rb b/qasim/map.rb index 7bc6678..620cf8f 100644 --- a/qasim/map.rb +++ b/qasim/map.rb @@ -29,7 +29,7 @@ module Qasim @enable = false @user = nil @cypher = :arcfour - @maps = {} + @links = {} @debug = true @name = (File.basename map_path).gsub(/\.map$/,'') @@ -76,8 +76,8 @@ module Qasim @host = $1.to_sym end when /^\s*MAP\s*=\s*(.*)\s+(.*)\s*$/ then - @maps[$1] = $2 - rdebug "d: map #{$1} => #{$2}" + @links[$1] = $2 + rdebug "d: link #{$1} => #{$2}" when /^\s*$/,/^\s*#/ then rdebug "d: dropping empty line" else @@ -103,8 +103,10 @@ module Qasim #FIXME: test liveness end + # + # test if map is connected / mounted + # def connected? - #FIXME test if connected / mounted f = File.open("/proc/mounts") sshfs_mounted = (f.readlines.select do |line| line =~ /\s+fuse.sshfs\s+/ @@ -114,7 +116,7 @@ module Qasim f.close score = 0 - @maps.each do |name, remotepath| + @links.each do |name, remotepath| score += 1 local_path = File.join @config.mnt_dir, name @@ -128,16 +130,19 @@ module Qasim end end + # + # connect given map + # def connect &block puts "[#{File.basename @path}] Connecting..." puts " #{@user}@#{@host}:#{@port}" - #puts " maps = %s" % @maps.map{ |k,v| "%s => %s" % [ k, v ] }.join(', ') + #puts " links = %s" % @links.map{ |k,v| "%s => %s" % [ k, v ] }.join(', ') # do something # test server connection # mount # # FIXME: test connexion with Net::SSH + timeout or ask password - @maps.each do |name, remotepath| + @links.each do |name, remotepath| pp map localpath = File.join ENV['HOME'], "mnt", name cmd = "sshfs" @@ -157,7 +162,7 @@ module Qasim localpath ] rdebug "command: %s" % [ cmd, cmd_args ].flatten.join(' ') if block_given? then - yield cmd, cmd_args + yield name, cmd, cmd_args else system cmd, cmd_args if $?.exitstatus != 0 then