Fixed error handling in GUI.

* Renamed map components of a map to link.
* Fixed error handling for multiple links.
This commit is contained in:
Glenn Y. Rolland 2011-07-28 15:41:46 +02:00
parent f778670a1f
commit b143509fce
2 changed files with 40 additions and 12 deletions

View file

@ -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],
"<b>Map connected successfully<b>",
'dialog-information'
else
erroneous = @connect_error[map.path].to_a.join(', ')
dbus_notify "%s (%s)" % [APP_NAME, map.name],
("<b>Unable to connect map</b><br>" +
"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

View file

@ -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