diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/leap/base/checks.py | 3 | ||||
-rw-r--r-- | src/leap/base/constants.py | 2 | ||||
-rw-r--r-- | src/leap/base/exceptions.py | 55 | ||||
-rw-r--r-- | src/leap/baseapp/mainwindow.py | 2 | ||||
-rw-r--r-- | src/leap/baseapp/network.py | 25 | ||||
-rw-r--r-- | src/leap/eip/checks.py | 6 | ||||
-rw-r--r-- | src/leap/eip/exceptions.py | 1 | ||||
-rw-r--r-- | src/leap/util/coroutines.py | 6 |
8 files changed, 79 insertions, 21 deletions
diff --git a/src/leap/base/checks.py b/src/leap/base/checks.py index 0dbb2846..84f9dd46 100644 --- a/src/leap/base/checks.py +++ b/src/leap/base/checks.py @@ -1,5 +1,4 @@ # -*- coding: utf-8 -*- - import logging import platform @@ -17,8 +16,6 @@ class LeapNetworkChecker(object): """ all network related checks """ - # TODO refactor to use psutil --- - # #718 # XXX get provider gateway as a parameter # for constructor. diff --git a/src/leap/base/constants.py b/src/leap/base/constants.py index 8a76b6b4..3f32176f 100644 --- a/src/leap/base/constants.py +++ b/src/leap/base/constants.py @@ -29,4 +29,4 @@ DEFAULT_PROVIDER_DEFINITION = { MAX_ICMP_PACKET_LOSS = 10 -ROUTE_CHECK_INTERVAL = 120 +ROUTE_CHECK_INTERVAL = 10 diff --git a/src/leap/base/exceptions.py b/src/leap/base/exceptions.py index 48d827f5..f12a49d5 100644 --- a/src/leap/base/exceptions.py +++ b/src/leap/base/exceptions.py @@ -1,3 +1,43 @@ +""" +Exception attributes and their meaning/uses +------------------------------------------- + +* critical: if True, will abort execution prematurely, + after attempting any cleaning + action. + +* failfirst: breaks any error_check loop that is examining + the error queue. + +* message: the message that will be used in the __repr__ of the exception. + +* usermessage: the message that will be passed to user in ErrorDialogs + in Qt-land. +""" + + +class LeapException(Exception): + """ + base LeapClient exception + sets some parameters that we will check + during error checking routines + """ + critical = False + failfirst = False + warning = False + + +class CriticalError(LeapException): + """ + we cannot do anything about it + """ + critical = True + failfirst = True + + +# In use ??? +# don't thing so. purge if not... + class MissingConfigFileError(Exception): pass @@ -6,24 +46,27 @@ class ImproperlyConfigured(Exception): pass -class NoDefaultInterfaceFoundError(Exception): +class NoDefaultInterfaceFoundError(LeapException): message = "no default interface found" usermessage = "Looks like your computer is not connected to the internet" -class InterfaceNotFoundError(Exception): +class InterfaceNotFoundError(LeapException): # XXX should take iface arg on init maybe? message = "interface not found" -class NoConnectionToGateway(Exception): +class NoConnectionToGateway(CriticalError): message = "no connection to gateway" usermessage = "Looks like there are problems with your internet connection" -class NoInternetConnection(Exception): +class NoInternetConnection(CriticalError): message = "No Internet connection found" + usermessage = "It looks like there is no internet connection." + # and now we try to connect to our web to troubleshoot LOL :P -class TunnelNotDefaultRouteError(Exception): - message = "VPN Maybe be down." +class TunnelNotDefaultRouteError(CriticalError): + message = "Tunnel connection dissapeared. VPN down?" + usermessage = "The Encrypted Connection was lost. Shutting down..." diff --git a/src/leap/baseapp/mainwindow.py b/src/leap/baseapp/mainwindow.py index e48666a4..fdbaf693 100644 --- a/src/leap/baseapp/mainwindow.py +++ b/src/leap/baseapp/mainwindow.py @@ -52,6 +52,8 @@ class LeapWindow(QtGui.QMainWindow, lambda status: self.onStatusChange(status)) self.timer.timeout.connect( lambda: self.onTimerTick()) + self.networkError.connect( + lambda exc: self.onNetworkError(exc)) # ... all ready. go! diff --git a/src/leap/baseapp/network.py b/src/leap/baseapp/network.py index fbf9376f..077d5164 100644 --- a/src/leap/baseapp/network.py +++ b/src/leap/baseapp/network.py @@ -1,10 +1,13 @@ from __future__ import print_function import logging + logger = logging.getLogger(name=__name__) +from PyQt4 import QtCore + +from leap.baseapp.dialogs import ErrorDialog from leap.base.network import NetworkCheckerThread -#from leap.baseapp.dialogs import ErrorDialog class NetworkCheckerAppMixin(object): @@ -15,11 +18,23 @@ class NetworkCheckerAppMixin(object): def __init__(self, *args, **kwargs): self.network_checker = NetworkCheckerThread( - # XXX watcher? remove ----- - watcher_cb=self.newLogLine.emit, - # XXX what callback? ------ - error_cb=None, + error_cb=self.networkError.emit, debug=self.debugmode) # XXX move run_checks to slot self.network_checker.run_checks() + + @QtCore.pyqtSlot(object) + def onNetworkError(self, exc): + """ + slot that receives a network exceptions + and raises a user error message + """ + logger.debug('handling network exception') + logger.error(exc.message) + dialog = ErrorDialog(parent=self) + + if exc.critical: + dialog.criticalMessage(exc.usermessage, "network error") + else: + dialog.warningMessage(exc.usermessage, "network error") diff --git a/src/leap/eip/checks.py b/src/leap/eip/checks.py index 9872f8d8..b68ee23a 100644 --- a/src/leap/eip/checks.py +++ b/src/leap/eip/checks.py @@ -1,12 +1,12 @@ import logging import ssl -import platform +#import platform import time import os from gnutls import crypto -import netifaces -import ping +#import netifaces +#import ping import requests from leap import __branding as BRANDING diff --git a/src/leap/eip/exceptions.py b/src/leap/eip/exceptions.py index 6b4ee6aa..24c9bfe8 100644 --- a/src/leap/eip/exceptions.py +++ b/src/leap/eip/exceptions.py @@ -28,7 +28,6 @@ TODO: * EIPClientError: Should inherit from LeapException - and move basic attrs there * gettext / i18n for user messages. diff --git a/src/leap/util/coroutines.py b/src/leap/util/coroutines.py index b9d0a98b..0657fc04 100644 --- a/src/leap/util/coroutines.py +++ b/src/leap/util/coroutines.py @@ -4,10 +4,13 @@ from __future__ import division, print_function +import logging from subprocess import PIPE, Popen import sys from threading import Thread +logger = logging.getLogger(__name__) + ON_POSIX = 'posix' in sys.builtin_module_names @@ -38,8 +41,7 @@ for each event if callable(callback): callback(m) else: - #XXX log instead - print('not a callable passed') + logger.debug('not a callable passed') except GeneratorExit: return |