Fixed error handling in GUI.
* Renamed map components of a map to link. * Fixed error handling for multiple links.
This commit is contained in:
parent
f778670a1f
commit
b143509fce
2 changed files with 40 additions and 12 deletions
|
@ -6,6 +6,8 @@ $DEBUG = true
|
||||||
$VERBOSE = true
|
$VERBOSE = true
|
||||||
|
|
||||||
require 'pp'
|
require 'pp'
|
||||||
|
require 'set'
|
||||||
|
|
||||||
require 'qasim/constants'
|
require 'qasim/constants'
|
||||||
require 'qasim/config'
|
require 'qasim/config'
|
||||||
require 'qasim/map'
|
require 'qasim/map'
|
||||||
|
@ -27,6 +29,8 @@ module Qasim
|
||||||
|
|
||||||
@map_menu = nil
|
@map_menu = nil
|
||||||
@context_menu = nil
|
@context_menu = nil
|
||||||
|
@connect_error = {}
|
||||||
|
@connect_running = {}
|
||||||
end
|
end
|
||||||
|
|
||||||
def dbus_notify title, body, icon
|
def dbus_notify title, body, icon
|
||||||
|
@ -94,19 +98,38 @@ module Qasim
|
||||||
puts "connect !"
|
puts "connect !"
|
||||||
begin
|
begin
|
||||||
success = true
|
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 = Qt::Process.new
|
||||||
process.connect(SIGNAL('finished(int, QProcess::ExitStatus)')) do |exitcode,exitstatus|
|
process.connect(SIGNAL('finished(int, QProcess::ExitStatus)')) do |exitcode,exitstatus|
|
||||||
puts "exitcode = %s, exitstatus = %s" % [exitcode, exitstatus]
|
puts "exitcode = %s, exitstatus = %s" % [exitcode, exitstatus]
|
||||||
|
@connect_running[map.path] -= 1
|
||||||
if exitcode != 0 then
|
if exitcode != 0 then
|
||||||
success = false
|
@connect_error[map.path].add linkname
|
||||||
item.setChecked success
|
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
|
end
|
||||||
|
end
|
||||||
|
@connect_running[map.path] += 1
|
||||||
process.start cmd, cmd_args
|
process.start cmd, cmd_args
|
||||||
end
|
end
|
||||||
|
|
||||||
dbus_notify map.name, "Map connected successfully", 'dialog-information'
|
|
||||||
rescue Map::ConnectError => e
|
rescue Map::ConnectError => e
|
||||||
puts e.inspect
|
puts e.inspect
|
||||||
end
|
end
|
||||||
|
|
21
qasim/map.rb
21
qasim/map.rb
|
@ -29,7 +29,7 @@ module Qasim
|
||||||
@enable = false
|
@enable = false
|
||||||
@user = nil
|
@user = nil
|
||||||
@cypher = :arcfour
|
@cypher = :arcfour
|
||||||
@maps = {}
|
@links = {}
|
||||||
@debug = true
|
@debug = true
|
||||||
@name = (File.basename map_path).gsub(/\.map$/,'')
|
@name = (File.basename map_path).gsub(/\.map$/,'')
|
||||||
|
|
||||||
|
@ -76,8 +76,8 @@ module Qasim
|
||||||
@host = $1.to_sym
|
@host = $1.to_sym
|
||||||
end
|
end
|
||||||
when /^\s*MAP\s*=\s*(.*)\s+(.*)\s*$/ then
|
when /^\s*MAP\s*=\s*(.*)\s+(.*)\s*$/ then
|
||||||
@maps[$1] = $2
|
@links[$1] = $2
|
||||||
rdebug "d: map #{$1} => #{$2}"
|
rdebug "d: link #{$1} => #{$2}"
|
||||||
when /^\s*$/,/^\s*#/ then
|
when /^\s*$/,/^\s*#/ then
|
||||||
rdebug "d: dropping empty line"
|
rdebug "d: dropping empty line"
|
||||||
else
|
else
|
||||||
|
@ -103,8 +103,10 @@ module Qasim
|
||||||
#FIXME: test liveness
|
#FIXME: test liveness
|
||||||
end
|
end
|
||||||
|
|
||||||
|
#
|
||||||
|
# test if map is connected / mounted
|
||||||
|
#
|
||||||
def connected?
|
def connected?
|
||||||
#FIXME test if connected / mounted
|
|
||||||
f = File.open("/proc/mounts")
|
f = File.open("/proc/mounts")
|
||||||
sshfs_mounted = (f.readlines.select do |line|
|
sshfs_mounted = (f.readlines.select do |line|
|
||||||
line =~ /\s+fuse.sshfs\s+/
|
line =~ /\s+fuse.sshfs\s+/
|
||||||
|
@ -114,7 +116,7 @@ module Qasim
|
||||||
f.close
|
f.close
|
||||||
|
|
||||||
score = 0
|
score = 0
|
||||||
@maps.each do |name, remotepath|
|
@links.each do |name, remotepath|
|
||||||
score += 1
|
score += 1
|
||||||
local_path = File.join @config.mnt_dir, name
|
local_path = File.join @config.mnt_dir, name
|
||||||
|
|
||||||
|
@ -128,16 +130,19 @@ module Qasim
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
#
|
||||||
|
# connect given map
|
||||||
|
#
|
||||||
def connect &block
|
def connect &block
|
||||||
puts "[#{File.basename @path}] Connecting..."
|
puts "[#{File.basename @path}] Connecting..."
|
||||||
puts " #{@user}@#{@host}:#{@port}"
|
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
|
# do something
|
||||||
# test server connection
|
# test server connection
|
||||||
# mount
|
# mount
|
||||||
#
|
#
|
||||||
# FIXME: test connexion with Net::SSH + timeout or ask password
|
# FIXME: test connexion with Net::SSH + timeout or ask password
|
||||||
@maps.each do |name, remotepath|
|
@links.each do |name, remotepath|
|
||||||
pp map
|
pp map
|
||||||
localpath = File.join ENV['HOME'], "mnt", name
|
localpath = File.join ENV['HOME'], "mnt", name
|
||||||
cmd = "sshfs"
|
cmd = "sshfs"
|
||||||
|
@ -157,7 +162,7 @@ module Qasim
|
||||||
localpath ]
|
localpath ]
|
||||||
rdebug "command: %s" % [ cmd, cmd_args ].flatten.join(' ')
|
rdebug "command: %s" % [ cmd, cmd_args ].flatten.join(' ')
|
||||||
if block_given? then
|
if block_given? then
|
||||||
yield cmd, cmd_args
|
yield name, cmd, cmd_args
|
||||||
else
|
else
|
||||||
system cmd, cmd_args
|
system cmd, cmd_args
|
||||||
if $?.exitstatus != 0 then
|
if $?.exitstatus != 0 then
|
||||||
|
|
Loading…
Reference in a new issue