diff options
Diffstat (limited to 'src/leap/baseapp')
-rw-r--r-- | src/leap/baseapp/eip.py | 2 | ||||
-rw-r--r-- | src/leap/baseapp/mainwindow.py | 3 | ||||
-rw-r--r-- | src/leap/baseapp/network.py | 57 |
3 files changed, 62 insertions, 0 deletions
diff --git a/src/leap/baseapp/eip.py b/src/leap/baseapp/eip.py index b0e14be7..ad074abc 100644 --- a/src/leap/baseapp/eip.py +++ b/src/leap/baseapp/eip.py @@ -224,9 +224,11 @@ class EIPConductorAppMixin(object): # we could bring Timer Init to this Mixin # or to its own Mixin. self.timer.start(constants.TIMER_MILLISECONDS) + self.network_checker.start() return if self.eip_service_started is True: + self.network_checker.stop() self.conductor.disconnect() if self.debugmode: self.startStopButton.setText('&Connect') diff --git a/src/leap/baseapp/mainwindow.py b/src/leap/baseapp/mainwindow.py index 10b23d9a..7b2ecb1d 100644 --- a/src/leap/baseapp/mainwindow.py +++ b/src/leap/baseapp/mainwindow.py @@ -8,6 +8,7 @@ from PyQt4 import QtGui from leap.baseapp.eip import EIPConductorAppMixin from leap.baseapp.log import LogPaneMixin from leap.baseapp.systray import StatusAwareTrayIconMixin +from leap.baseapp.network import NetworkCheckerAppMixin from leap.baseapp.leap_app import MainWindowMixin logger = logging.getLogger(name=__name__) @@ -16,6 +17,7 @@ logger = logging.getLogger(name=__name__) class LeapWindow(QtGui.QMainWindow, MainWindowMixin, EIPConductorAppMixin, StatusAwareTrayIconMixin, + NetworkCheckerAppMixin, LogPaneMixin): """ main window for the leap app. @@ -36,6 +38,7 @@ class LeapWindow(QtGui.QMainWindow, self.createLogBrowser() EIPConductorAppMixin.__init__(self, opts=opts) StatusAwareTrayIconMixin.__init__(self) + NetworkCheckerAppMixin.__init__(self) MainWindowMixin.__init__(self) # bind signals diff --git a/src/leap/baseapp/network.py b/src/leap/baseapp/network.py new file mode 100644 index 00000000..75690cc9 --- /dev/null +++ b/src/leap/baseapp/network.py @@ -0,0 +1,57 @@ +from __future__ import print_function +import logging +import time +logger = logging.getLogger(name=__name__) + +from leap.base.network import NetworkChecker +from leap.baseapp.dialogs import ErrorDialog + + +class NetworkCheckerAppMixin(object): + """ + initialize an instance of the Network Checker, + which gathers error and passes them on. + """ + + def __init__(self, *args, **kwargs): + opts = kwargs.pop('opts', None) + config_file = getattr(opts, 'config_file', None) + + self.network_checker_started = False + + self.network_checker = NetworkChecker( + watcher_cb=self.newLogLine.emit, + status_signals=(self.statusChange.emit, ), + debug=self.debugmode) + + self.network_checker.run_checks() + self.error_check() + + def error_check(self): + """ + consumes the conductor error queue. + pops errors, and acts accordingly (launching user dialogs). + """ + logger.debug('error check') + + errq = self.conductor.error_queue + while errq.qsize() != 0: + logger.debug('%s errors left in network queue', errq.qsize()) + # we get exception and original traceback from queue + error, tb = errq.get() + + # redundant log, debugging the loop. + logger.error('%s: %s', error.__class__.__name__, error.message) + + if issubclass(error.__class__, eip_exceptions.EIPClientError): + self.handle_network_error(error) + + else: + # deprecated form of raising exception. + raise error, None, tb + + if error.failfirst is True: + break + + def handle_network_error(self, error): + pass |