diff options
-rw-r--r-- | .gitignore | 2 | ||||
-rw-r--r-- | Makefile | 14 | ||||
-rw-r--r-- | changes/better-soledad-retry | 1 | ||||
-rw-r--r-- | changes/bug_5153-select-domain-in-eip-preferences | 1 | ||||
-rw-r--r-- | changes/feature_nice-process | 1 | ||||
-rw-r--r-- | changes/feature_remove_qtreactor | 1 | ||||
-rw-r--r-- | pkg/requirements.pip | 1 | ||||
-rwxr-xr-x | pkg/scripts/monitor_resource.zsh | 26 | ||||
-rw-r--r-- | src/leap/bitmask/app.py | 22 | ||||
-rw-r--r-- | src/leap/bitmask/gui/eip_preferenceswindow.py | 21 | ||||
-rw-r--r-- | src/leap/bitmask/gui/mail_status.py | 2 | ||||
-rw-r--r-- | src/leap/bitmask/gui/mainwindow.py | 33 | ||||
-rw-r--r-- | src/leap/bitmask/gui/twisted_main.py | 18 |
13 files changed, 89 insertions, 54 deletions
@@ -4,6 +4,7 @@ *.log *.lprof *.pstats +*.data *.*~ .* *_rc.py @@ -33,3 +34,4 @@ config/* CHANGELOG~ data/bitmask.pro +bitmask-resources.png @@ -43,6 +43,10 @@ ifndef EDITOR export EDITOR=vim endif +ifndef RESOURCE_TIME + export RESOURCE_TIME=10 +endif + # all : resources ui @@ -72,10 +76,18 @@ mailprofile: gprof2dot -f pstats /tmp/leap_mail_profile.pstats -n 0.2 -e 0.2 | dot -Tpdf -o /tmp/leap_mail_profile.pdf do_lineprof: - LEAP_PROFILE_IMAPCMD=1 LEAP_MAIL_MANHOLE=1 kernprof.py -l src/leap/bitmask/app.py --offline --debug + LEAP_PROFILE_IMAPCMD=1 LEAP_MAIL_MANHOLE=1 kernprof.py -l src/leap/bitmask/app.py --debug + +do_lineprof_offline: + LEAP_PROFILE_IMAPCMD=1 LEAP_MAIL_MANHOLE=1 kernprof.py -l src/leap/bitmask/app.py --offline --debug -N view_lineprof: @python -m line_profiler app.py.lprof | $(EDITOR) - +resource_graph: + #./pkg/scripts/monitor_resource.zsh `ps aux | grep app.py | head -1 | awk '{print $$2}'` $(RESOURCE_TIME) + ./pkg/scripts/monitor_resource.zsh `pgrep bitmask` $(RESOURCE_TIME) + display bitmask-resources.png + clean : $(RM) $(COMPILED_UI) $(COMPILED_RESOURCES) $(COMPILED_UI:.py=.pyc) $(COMPILED_RESOURCES:.py=.pyc) diff --git a/changes/better-soledad-retry b/changes/better-soledad-retry new file mode 100644 index 00000000..ac21f76c --- /dev/null +++ b/changes/better-soledad-retry @@ -0,0 +1 @@ +In case of soledad bootstrap error (e.g.: network failure), re run all the setup process. diff --git a/changes/bug_5153-select-domain-in-eip-preferences b/changes/bug_5153-select-domain-in-eip-preferences new file mode 100644 index 00000000..2c00c745 --- /dev/null +++ b/changes/bug_5153-select-domain-in-eip-preferences @@ -0,0 +1 @@ +Set as selected default for the eip preferences window the item selented in the bitmask main window. Closes #5153. diff --git a/changes/feature_nice-process b/changes/feature_nice-process new file mode 100644 index 00000000..3de26e75 --- /dev/null +++ b/changes/feature_nice-process @@ -0,0 +1 @@ +- Add ability to nice application via environment variable. diff --git a/changes/feature_remove_qtreactor b/changes/feature_remove_qtreactor new file mode 100644 index 00000000..5cf3a854 --- /dev/null +++ b/changes/feature_remove_qtreactor @@ -0,0 +1 @@ +- Remove qt4reactor as a dependency.
\ No newline at end of file diff --git a/pkg/requirements.pip b/pkg/requirements.pip index 04cd33de..c8f6b101 100644 --- a/pkg/requirements.pip +++ b/pkg/requirements.pip @@ -13,7 +13,6 @@ python-dateutil psutil ipaddr twisted -qt4reactor python-daemon # this should not be needed for Windows. keyring zope.proxy diff --git a/pkg/scripts/monitor_resource.zsh b/pkg/scripts/monitor_resource.zsh new file mode 100755 index 00000000..ac468e34 --- /dev/null +++ b/pkg/scripts/monitor_resource.zsh @@ -0,0 +1,26 @@ +#!/bin/zsh +if (( ! $# )); then + echo "Usage: $0:t <PID> <minutes to monitor>" >&2 + return 1; +fi + +OUT="$1-usage.data" +GRAPH="bitmask-resources.png" +MAX=150 +let "ticks=$2*60/3" +echo "cpu mem" >> $OUT +for i in {1..$ticks}; do; + cpu=$(ps -p $1 -o pcpu | grep -v %) + mem=$(ps wuh -p $1 | awk '{print $4}') + echo "$cpu $mem" >> $OUT; + sleep 3; + echo $i / $ticks; +done; + +gnuplot -e "set term dumb; \ +set key outside; set yrange [0:$MAX]; \ +plot for [col=1:2] '$OUT' using 0:col title columnheader s c" + +gnuplot -e "set term png; set output '$GRAPH'; \ +set key outside; set yrange [0:$MAX]; \ +plot for [col=1:2] '$OUT' using 0:col with lines title columnheader" diff --git a/src/leap/bitmask/app.py b/src/leap/bitmask/app.py index 1146d1d0..124671b3 100644 --- a/src/leap/bitmask/app.py +++ b/src/leap/bitmask/app.py @@ -58,6 +58,9 @@ from leap.bitmask.services.mail import plumber from leap.common.events import server as event_server from leap.mail import __version__ as MAIL_VERSION +from twisted.internet import reactor +from twisted.internet.task import LoopingCall + import codecs codecs.register(lambda name: codecs.lookup('utf-8') if name == 'cp65001' else None) @@ -74,12 +77,6 @@ def sigint_handler(*args, **kwargs): mainwindow.quit() -def install_qtreactor(logger): - import qt4reactor - qt4reactor.install() - logger.debug("Qt4 reactor installed") - - def add_logger_handlers(debug=False, logfile=None, replace_stdout=True): """ Create the logger and attach the handlers. @@ -236,6 +233,11 @@ def main(): # We don't even have logger configured in here print "Could not ensure server: %r" % (e,) + PLAY_NICE = os.environ.get("LEAP_NICE") + if PLAY_NICE and PLAY_NICE.isdigit(): + nice = os.nice(int(PLAY_NICE)) + logger.info("Setting NICE: %s" % nice) + # And then we import all the other stuff # I think it's safe to import at the top by now -- kali from leap.bitmask.gui import locale_rc @@ -274,9 +276,6 @@ def main(): app = QtGui.QApplication(sys.argv) - # install the qt4reactor. - install_qtreactor(logger) - # To test: # $ LANG=es ./app.py locale = QtCore.QLocale.system().name() @@ -319,8 +318,9 @@ def main(): #tx_app = leap_services() #assert(tx_app) - # Run main loop - twisted_main.start(app) + l = LoopingCall(QtCore.QCoreApplication.processEvents, 0, 10) + l.start(0.01) + reactor.run() if __name__ == "__main__": main() diff --git a/src/leap/bitmask/gui/eip_preferenceswindow.py b/src/leap/bitmask/gui/eip_preferenceswindow.py index 504d1cf1..dcaa8b1e 100644 --- a/src/leap/bitmask/gui/eip_preferenceswindow.py +++ b/src/leap/bitmask/gui/eip_preferenceswindow.py @@ -22,7 +22,7 @@ import os import logging from functools import partial -from PySide import QtGui +from PySide import QtCore, QtGui from leap.bitmask.config.leapsettings import LeapSettings from leap.bitmask.config.providerconfig import ProviderConfig @@ -37,10 +37,12 @@ class EIPPreferencesWindow(QtGui.QDialog): """ Window that displays the EIP preferences. """ - def __init__(self, parent): + def __init__(self, parent, domain): """ :param parent: parent object of the EIPPreferencesWindow. - :parent type: QWidget + :type parent: QWidget + :param domain: the selected by default domain. + :type domain: unicode """ QtGui.QDialog.__init__(self, parent) self.AUTOMATIC_GATEWAY_LABEL = self.tr("Automatic") @@ -59,7 +61,7 @@ class EIPPreferencesWindow(QtGui.QDialog): self.ui.cbGateways.currentIndexChanged[unicode].connect( lambda x: self.ui.lblProvidersGatewayStatus.setVisible(False)) - self._add_configured_providers() + self._add_configured_providers(domain) def _set_providers_gateway_status(self, status, success=False, error=False): @@ -83,9 +85,12 @@ class EIPPreferencesWindow(QtGui.QDialog): self.ui.lblProvidersGatewayStatus.setVisible(True) self.ui.lblProvidersGatewayStatus.setText(status) - def _add_configured_providers(self): + def _add_configured_providers(self, domain=None): """ Add the client's configured providers to the providers combo boxes. + + :param domain: the domain to be selected by default. + :type domain: unicode """ self.ui.cbProvidersGateway.clear() providers = self._settings.get_configured_providers() @@ -100,6 +105,12 @@ class EIPPreferencesWindow(QtGui.QDialog): label = provider + self.tr(" (uninitialized)") self.ui.cbProvidersGateway.addItem(label, userData=provider) + # Select provider by name + if domain is not None: + provider_index = self.ui.cbProvidersGateway.findText( + domain, QtCore.Qt.MatchStartsWith) + self.ui.cbProvidersGateway.setCurrentIndex(provider_index) + def _save_selected_gateway(self, provider): """ SLOT diff --git a/src/leap/bitmask/gui/mail_status.py b/src/leap/bitmask/gui/mail_status.py index 1d5ff319..8da26f6d 100644 --- a/src/leap/bitmask/gui/mail_status.py +++ b/src/leap/bitmask/gui/mail_status.py @@ -213,7 +213,7 @@ class MailStatusWidget(QtGui.QWidget): self._service_name)) elif ready == 1: icon = self.CONNECTING_ICON - self._mx_status = self.tr('Starting..') + self._mx_status = self.tr('Starting…') tray_status = self.tr('Mail is starting') elif ready >= 2: icon = self.CONNECTED_ICON diff --git a/src/leap/bitmask/gui/mainwindow.py b/src/leap/bitmask/gui/mainwindow.py index eeab7e2b..004d135b 100644 --- a/src/leap/bitmask/gui/mainwindow.py +++ b/src/leap/bitmask/gui/mainwindow.py @@ -134,6 +134,7 @@ class MainWindow(QtGui.QMainWindow): :type bypass_checks: bool """ QtGui.QMainWindow.__init__(self) + self.menuBar().setNativeMenuBar(False) # register leap events ######################################## register(signal=proto.UPDATER_NEW_UPDATES, @@ -587,7 +588,8 @@ class MainWindow(QtGui.QMainWindow): Displays the EIP preferences window. """ - EIPPreferencesWindow(self).show() + domain = self._login_widget.get_selected_provider() + EIPPreferencesWindow(self, domain).show() # # updates @@ -1065,16 +1067,24 @@ class MainWindow(QtGui.QMainWindow): Stops the login sequence. """ - logger.debug("Cancelling setup provider defer.") + logger.debug("Cancelling log in.") + self._cancel_ongoing_defers() + + def _cancel_ongoing_defers(self): + """ + Cancel the running defers to avoid app blocking. + """ self._backend.cancel_setup_provider() if self._login_defer is not None: logger.debug("Cancelling login defer.") self._login_defer.cancel() + self._login_defer = None if self._soledad_defer is not None: logger.debug("Cancelling soledad defer.") self._soledad_defer.cancel() + self._soledad_defer = None def _set_login_cancelled(self): """ @@ -1247,8 +1257,7 @@ class MainWindow(QtGui.QMainWindow): self._soledad_bootstrapper.increment_retries_count() # XXX should cancel the existing socket --- this # is avoiding a clean termination. - threads.deferToThread( - self._soledad_bootstrapper.load_and_sync_soledad) + self._maybe_run_soledad_setup_checks() else: logger.warning("Max number of soledad initialization " "retries reached.") @@ -1811,9 +1820,8 @@ class MainWindow(QtGui.QMainWindow): """ self._soledad_bootstrapper.cancel_bootstrap() setProxiedObject(self._soledad, None) - if self._soledad_defer is not None: - logger.debug("Cancelling soledad defer.") - self._soledad_defer.cancel() + + self._cancel_ongoing_defers() # reset soledad status flag self._already_started_soledad = False @@ -1930,16 +1938,7 @@ class MainWindow(QtGui.QMainWindow): logger.debug('Terminating vpn') self._vpn.terminate(shutdown=True) - if self._login_defer: - logger.debug("Cancelling login defer.") - self._login_defer.cancel() - - logger.debug("Cancelling setup provider defer.") - self._backend.cancel_setup_provider() - - if self._soledad_defer is not None: - logger.debug("Cancelling soledad defer.") - self._soledad_defer.cancel() + self._cancel_ongoing_defers() # TODO missing any more cancels? diff --git a/src/leap/bitmask/gui/twisted_main.py b/src/leap/bitmask/gui/twisted_main.py index e11af7bd..1e876c57 100644 --- a/src/leap/bitmask/gui/twisted_main.py +++ b/src/leap/bitmask/gui/twisted_main.py @@ -27,24 +27,6 @@ from twisted.internet import error logger = logging.getLogger(__name__) -def start(app): - """ - Start the mainloop. - - :param app: the main qt QApplication instance. - :type app: QtCore.QApplication - """ - from twisted.internet import reactor - logger.debug('starting twisted reactor') - - # this seems to be troublesome under some - # unidentified settings. - #reactor.run() - - reactor.runReturn() - app.exec_() - - def quit(app): """ Stop the mainloop. |