aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichael Buesch <m@bues.ch>2019-07-13 19:23:34 +0200
committerMichael Buesch <m@bues.ch>2019-07-13 19:29:45 +0200
commite951a22ec7d9db86b3912a055b09a69be4e50459 (patch)
tree52aa4c4dfd2ee8f1cf8323a78992d44490d4ed1e
parentde7928b0344f118cb638a09de492f591c3be1d42 (diff)
downloadawlsim-e951a22ec7d9db86b3912a055b09a69be4e50459.zip
awlsim-e951a22ec7d9db86b3912a055b09a69be4e50459.tar.xz
sshtunnel: Add support for cancelling handshaking.
Signed-off-by: Michael Buesch <m@bues.ch>
-rw-r--r--awlsim/coreclient/sshtunnel.py6
-rw-r--r--awlsim/gui/awlsimclient.py10
2 files changed, 14 insertions, 2 deletions
diff --git a/awlsim/coreclient/sshtunnel.py b/awlsim/coreclient/sshtunnel.py
index 8741c6a..7675e21 100644
--- a/awlsim/coreclient/sshtunnel.py
+++ b/awlsim/coreclient/sshtunnel.py
@@ -213,7 +213,8 @@ class SSHTunnel(object):
timeoutEnd = monotonic_time() + (timeout or 0)
sentPw, authReq, finished = False, [], False
while not finished:
- self.sleep(0.1)
+ if not self.sleep(0.1):
+ raise AwlSimError("Establishing SSH tunnel cancelled.")
if timeout and monotonic_time() >= timeoutEnd:
raise AwlSimError("Timeout establishing SSH tunnel.")
fromSsh = self.__read(ptyMasterFd)
@@ -267,8 +268,11 @@ class SSHTunnel(object):
def sleep(self, seconds):
"""Sleep for a number of seconds.
+ Returns True, if everything is Ok.
+ Returns False, if the connection operation shall be cancelled.
"""
time.sleep(seconds)
+ return True
def sshMessage(self, message, isDebug):
"""Print a SSH log message.
diff --git a/awlsim/gui/awlsimclient.py b/awlsim/gui/awlsimclient.py
index 7a83344..d4ec292 100644
--- a/awlsim/gui/awlsimclient.py
+++ b/awlsim/gui/awlsimclient.py
@@ -40,6 +40,8 @@ class GuiSSHTunnel(SSHTunnel, QDialog):
"""
def __init__(self, parent, *args, **kwargs):
+ self.__cancelRequest = False
+
QDialog.__init__(self, parent)
SSHTunnel.__init__(self, *args, **kwargs)
@@ -53,10 +55,16 @@ class GuiSSHTunnel(SSHTunnel, QDialog):
self.resize(750, 180)
+ def closeEvent(self, ev):
+ self.__cancelRequest = True
+ QDialog.closeEvent(self, ev)
+
def sleep(self, seconds):
- sleepWithEventLoop(seconds, excludeInput=True)
+ sleepWithEventLoop(seconds, excludeInput=False)
+ return not self.__cancelRequest
def connect(self):
+ self.__cancelRequest = False
self.hide()
self.setWindowModality(Qt.ApplicationModal)
self.show()
bues.ch cgit interface