From 4f4520d938f726b344e1a71949f83aa385d92acd Mon Sep 17 00:00:00 2001 From: Ivan Alejandro Date: Mon, 1 Sep 2014 18:31:36 -0300 Subject: Don't defer action to thread here. We already are running the methods in a thread from the backend. --- src/leap/bitmask/backend/components.py | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/src/leap/bitmask/backend/components.py b/src/leap/bitmask/backend/components.py index 89f3c5a6..d4f6d176 100644 --- a/src/leap/bitmask/backend/components.py +++ b/src/leap/bitmask/backend/components.py @@ -452,20 +452,14 @@ class EIP(object): else: logger.debug('EIP: no errors') - def _do_stop(self, shutdown=False, restart=False): + def stop(self, shutdown=False, restart=False): """ - Stop the service. This is run in a thread to avoid blocking. + Stop the service. """ self._vpn.terminate(shutdown, restart) if IS_LINUX: self._wait_for_firewall_down() - def stop(self, shutdown=False, restart=False): - """ - Stop the service. - """ - return threads.deferToThread(self._do_stop, shutdown, restart) - def _wait_for_firewall_down(self): """ Wait for the firewall to come down. -- cgit v1.2.3 From 59ae590f4126b3e5635467e05b9985dabc80a2f9 Mon Sep 17 00:00:00 2001 From: Ivan Alejandro Date: Mon, 1 Sep 2014 18:33:10 -0300 Subject: Move reactor import to the top. --- src/leap/bitmask/services/eip/vpnprocess.py | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) diff --git a/src/leap/bitmask/services/eip/vpnprocess.py b/src/leap/bitmask/services/eip/vpnprocess.py index c7159a93..40aad257 100644 --- a/src/leap/bitmask/services/eip/vpnprocess.py +++ b/src/leap/bitmask/services/eip/vpnprocess.py @@ -50,8 +50,7 @@ from leap.common.check import leap_assert, leap_assert_type logger = logging.getLogger(__name__) vpnlog = logging.getLogger('leap.openvpn') -from twisted.internet import protocol -from twisted.internet import defer +from twisted.internet import defer, protocol, reactor from twisted.internet import error as internet_error from twisted.internet.task import LoopingCall @@ -157,10 +156,8 @@ class VPN(object): of a QObject containing the QSignals that we will pass along to the VPNManager. """ - from twisted.internet import reactor self._vpnproc = None self._pollers = [] - self._reactor = reactor self._signaler = kwargs['signaler'] self._openvpn_verb = flags.OPENVPN_VERBOSITY @@ -224,7 +221,7 @@ class VPN(object): for key, val in vpnproc.vpn_env.items(): env[key] = val - self._reactor.spawnProcess(vpnproc, cmd[0], cmd, env) + reactor.spawnProcess(vpnproc, cmd[0], cmd, env) self._vpnproc = vpnproc # add pollers for status and state @@ -300,7 +297,6 @@ class VPN(object): :param tries: counter of tries, used in recursion :type tries: int """ - from twisted.internet import reactor while tries < self.TERMINATE_MAXTRIES: if self._vpnproc.transport.pid is None: logger.debug("Process has been happily terminated.") @@ -351,7 +347,6 @@ class VPN(object): :param restart: whether this stop is part of a hard restart. :type restart: bool """ - from twisted.internet import reactor self._stop_pollers() # First we try to be polite and send a SIGTERM... @@ -424,8 +419,6 @@ class VPNManager(object): backend :type signaler: backend.Signaler """ - from twisted.internet import reactor - self._reactor = reactor self._tn = None self._signaler = signaler self._aborted = False @@ -602,7 +595,7 @@ class VPNManager(object): logger.debug('trying to connect to management') if not self.aborted and not self.is_connected(): self.connect_to_management(self._socket_host, self._socket_port) - self._reactor.callLater( + reactor.callLater( self.CONNECTION_RETRY_TIME, self.try_to_connect_to_management, retry + 1) -- cgit v1.2.3 From d65ecea2d6a943d6805284390e0361ae0ff00718 Mon Sep 17 00:00:00 2001 From: Ivan Alejandro Date: Mon, 1 Sep 2014 19:03:26 -0300 Subject: Remove unused defers. Also, we no longer return defers for those actions. --- src/leap/bitmask/gui/wizard.py | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/src/leap/bitmask/gui/wizard.py b/src/leap/bitmask/gui/wizard.py index 0223c053..498e8501 100644 --- a/src/leap/bitmask/gui/wizard.py +++ b/src/leap/bitmask/gui/wizard.py @@ -96,11 +96,6 @@ class Wizard(QtGui.QWizard): # this details are set when the provider download is complete. self._provider_details = None - # We will store a reference to the defers for eventual use - # (eg, to cancel them) but not doing anything with them right now. - self._provider_select_defer = None - self._provider_setup_defer = None - self._connect_and_track(self.currentIdChanged, self._current_id_changed) @@ -479,8 +474,7 @@ class Wizard(QtGui.QWizard): self.button(QtGui.QWizard.BackButton).clearFocus() self.ui.lblNameResolution.setPixmap(self.QUESTION_ICON) - self._provider_select_defer = self._backend.\ - provider_setup(provider=self._domain) + self._backend.provider_setup(provider=self._domain) @QtCore.Slot(bool) def _skip_provider_checks(self, skip): @@ -724,8 +718,7 @@ class Wizard(QtGui.QWizard): if not self._provider_setup_ok: self._reset_provider_setup() self.ui.lblDownloadCaCert.setPixmap(self.QUESTION_ICON) - self._provider_setup_defer = self._backend.\ - provider_bootstrap(provider=self._domain) + self._backend.provider_bootstrap(provider=self._domain) if pageId == self.PRESENT_PROVIDER_PAGE: details = self._provider_details -- cgit v1.2.3 From de2f0e13a5a48e86b75eb54a56fe9f88b720193f Mon Sep 17 00:00:00 2001 From: Ivan Alejandro Date: Wed, 3 Sep 2014 14:50:46 -0300 Subject: Better logging output for missing files and error. --- src/leap/bitmask/platform_init/initializers.py | 13 ++++++++----- src/leap/bitmask/services/eip/vpnprocess.py | 5 +++-- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/src/leap/bitmask/platform_init/initializers.py b/src/leap/bitmask/platform_init/initializers.py index 6c62734c..70d787dd 100644 --- a/src/leap/bitmask/platform_init/initializers.py +++ b/src/leap/bitmask/platform_init/initializers.py @@ -127,12 +127,15 @@ def check_missing(): complain_missing = True launcher = get_vpn_launcher() - missing_scripts = launcher.missing_updown_scripts - missing_other = launcher.missing_other_files + missing_scripts = launcher.missing_updown_scripts() + missing_other = launcher.missing_other_files() - logger.debug("MISSING OTHER: %s" % (str(missing_other()))) + if missing_scripts: + logger.warning("Missing scripts: %s" % (missing_scripts)) + if missing_other: + logger.warning("Missing other files: %s" % (missing_other)) - missing_some = missing_scripts() or missing_other() + missing_some = missing_scripts or missing_other if alert_missing and missing_some: msg = get_missing_helpers_dialog() ret = msg.exec_() @@ -168,7 +171,7 @@ def check_missing(): config.set_alert_missing_scripts(False) if complain_missing and missing_some: - missing = missing_scripts() + missing_other() + missing = missing_scripts + missing_other msg = _get_missing_complain_dialog(missing) ret = msg.exec_() diff --git a/src/leap/bitmask/services/eip/vpnprocess.py b/src/leap/bitmask/services/eip/vpnprocess.py index 40aad257..d41064ec 100644 --- a/src/leap/bitmask/services/eip/vpnprocess.py +++ b/src/leap/bitmask/services/eip/vpnprocess.py @@ -214,9 +214,10 @@ class VPN(object): # and abstract us away from anything else. try: cmd = vpnproc.getCommand() - except Exception: - logger.error("Error while getting vpn command...") + except Exception as e: + logger.error("Error while getting vpn command... {0!r}".format(e)) raise + env = os.environ for key, val in vpnproc.vpn_env.items(): env[key] = val -- cgit v1.2.3 From e6fae0977015919282971dbe8a00938415c1233b Mon Sep 17 00:00:00 2001 From: Ivan Alejandro Date: Mon, 1 Sep 2014 19:03:46 -0300 Subject: Code cleanup and logging improvements. --- changes/code-and-logging-cleanup | 1 + src/leap/bitmask/gui/mainwindow.py | 18 ++++++++---------- src/leap/bitmask/gui/wizard.py | 5 +++-- src/leap/bitmask/services/eip/vpnprocess.py | 2 ++ src/leap/bitmask/services/mail/smtpbootstrapper.py | 2 ++ 5 files changed, 16 insertions(+), 12 deletions(-) create mode 100644 changes/code-and-logging-cleanup diff --git a/changes/code-and-logging-cleanup b/changes/code-and-logging-cleanup new file mode 100644 index 00000000..3a381e68 --- /dev/null +++ b/changes/code-and-logging-cleanup @@ -0,0 +1 @@ +- Code cleanup and logging improvements. diff --git a/src/leap/bitmask/gui/mainwindow.py b/src/leap/bitmask/gui/mainwindow.py index 653ebc35..8127c1f6 100644 --- a/src/leap/bitmask/gui/mainwindow.py +++ b/src/leap/bitmask/gui/mainwindow.py @@ -206,6 +206,9 @@ class MainWindow(QtGui.QMainWindow): self._finally_quitting = False self._system_quit = False + # Used to differentiate between a real quit and a close to tray + self._close_to_tray = True + self._backend_connected_signals = [] self._backend_connect() @@ -229,9 +232,6 @@ class MainWindow(QtGui.QMainWindow): self.raise_window.connect(self._do_raise_mainwindow) - # Used to differentiate between real quits and close to tray - self._really_quit = False - self._systray = None # XXX separate actions into a different module. @@ -1144,7 +1144,7 @@ class MainWindow(QtGui.QMainWindow): return if QtGui.QSystemTrayIcon.isSystemTrayAvailable() and \ - not self._really_quit: + self._close_to_tray: self._ensure_invisible() e.ignore() return @@ -1889,10 +1889,9 @@ class MainWindow(QtGui.QMainWindow): """ Stop services and cancel ongoing actions (if any). """ - logger.debug('About to quit, doing cleanup.') + logger.debug('Stopping services...') self._cancel_ongoing_defers() - self._services_being_stopped = set(('imap', 'eip')) imap_stopped = lambda: self._remove_service('imap') @@ -1921,9 +1920,10 @@ class MainWindow(QtGui.QMainWindow): if self._quitting: return - autostart.set_autostart(False) - self._quitting = True + self._close_to_tray = False + logger.debug('Quitting...') + autostart.set_autostart(False) # first thing to do quitting, hide the mainwindow and show tooltip. self.hide() @@ -1942,8 +1942,6 @@ class MainWindow(QtGui.QMainWindow): # Set this in case that the app is hidden QtGui.QApplication.setQuitOnLastWindowClosed(True) - self._really_quit = True - if not self._backend.online: self.final_quit() return diff --git a/src/leap/bitmask/gui/wizard.py b/src/leap/bitmask/gui/wizard.py index 498e8501..8182228d 100644 --- a/src/leap/bitmask/gui/wizard.py +++ b/src/leap/bitmask/gui/wizard.py @@ -672,8 +672,9 @@ class Wizard(QtGui.QWizard): Loads the services that the provider provides into the UI for the user to enable or disable. """ - self.ui.grpServices.setTitle( - self.tr("Services by {0}").format(self._provider_details['domain'])) + title = self.tr("Services by {0}").format( + self._provider_details['domain']) + self.ui.grpServices.setTitle(title) services = get_supported(self._provider_details['services']) diff --git a/src/leap/bitmask/services/eip/vpnprocess.py b/src/leap/bitmask/services/eip/vpnprocess.py index d41064ec..8dc6021f 100644 --- a/src/leap/bitmask/services/eip/vpnprocess.py +++ b/src/leap/bitmask/services/eip/vpnprocess.py @@ -371,6 +371,8 @@ class VPN(object): logger.debug("Firewall down") else: logger.warning("Could not tear firewall down") + else: + logger.debug("VPN is not running.") def _start_pollers(self): """ diff --git a/src/leap/bitmask/services/mail/smtpbootstrapper.py b/src/leap/bitmask/services/mail/smtpbootstrapper.py index 3ef755e8..9dd61488 100644 --- a/src/leap/bitmask/services/mail/smtpbootstrapper.py +++ b/src/leap/bitmask/services/mail/smtpbootstrapper.py @@ -173,3 +173,5 @@ class SMTPBootstrapper(AbstractBootstrapper): logger.debug('Stopping SMTP service.') self._smtp_port.stopListening() self._smtp_service.doStop() + else: + logger.debug('SMTP service not running.') -- cgit v1.2.3