summaryrefslogtreecommitdiff
path: root/src/leap/bitmask/app.py
diff options
context:
space:
mode:
authorTomás Touceda <chiiph@leap.se>2014-07-18 11:22:47 -0300
committerTomás Touceda <chiiph@leap.se>2014-07-18 11:22:47 -0300
commit159dbe295148975bdfe9a50f871254aa9adf2328 (patch)
tree5b679b7f617c4bc09c25a4c369e77156f0ff3e2c /src/leap/bitmask/app.py
parent7858d83af4a09ab00f6ba33dd8dbcf07ade101ce (diff)
parent312746bc9b77f0f738ccf2192d81ab94fdf9d6ba (diff)
Merge branch 'release-0.6.0'0.6.0
Diffstat (limited to 'src/leap/bitmask/app.py')
-rw-r--r--src/leap/bitmask/app.py127
1 files changed, 42 insertions, 85 deletions
diff --git a/src/leap/bitmask/app.py b/src/leap/bitmask/app.py
index 6a7d6ff1..88f6bc15 100644
--- a/src/leap/bitmask/app.py
+++ b/src/leap/bitmask/app.py
@@ -39,56 +39,49 @@
# M:::::::::::~NMMM7???7MMMM:::::::::::::::::::::::NMMMI??I7MMMM:::::::::::::M
# M::::::::::::::7MMMMMMM+:::::::::::::::::::::::::::?MMMMMMMZ:::::::::::::::M
# (thanks to: http://www.glassgiant.com/ascii/)
-import signal
-import sys
+import multiprocessing
import os
+import sys
-from functools import partial
-from PySide import QtCore, QtGui
+from leap.bitmask.backend.utils import generate_certificates
from leap.bitmask import __version__ as VERSION
from leap.bitmask.config import flags
-from leap.bitmask.gui import locale_rc # noqa - silence pylint
-from leap.bitmask.gui.mainwindow import MainWindow
+from leap.bitmask.frontend_app import run_frontend
+from leap.bitmask.backend_app import run_backend
from leap.bitmask.logs.utils import create_logger
from leap.bitmask.platform_init.locks import we_are_the_one_and_only
from leap.bitmask.services.mail import plumber
-from leap.bitmask.util import leap_argparse
+from leap.bitmask.util import leap_argparse, flags_to_dict
from leap.bitmask.util.requirement_checker import check_requirements
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)
-
-def sigint_handler(*args, **kwargs):
- """
- Signal handler for SIGINT
- """
- logger = kwargs.get('logger', None)
- if logger:
- logger.debug("SIGINT catched. shutting down...")
- mainwindow = args[0]
- mainwindow.quit()
+import psutil
-def sigterm_handler(*args, **kwargs):
+def kill_the_children():
"""
- Signal handler for SIGTERM.
- This handler is actually passed to twisted reactor
+ Make sure no lingering subprocesses are left in case of a bad termination.
"""
- logger = kwargs.get('logger', None)
- if logger:
- logger.debug("SIGTERM catched. shutting down...")
- mainwindow = args[0]
- mainwindow.quit()
+ me = os.getpid()
+ parent = psutil.Process(me)
+ print "Killing all the children processes..."
+ for child in parent.get_children(recursive=True):
+ try:
+ child.terminate()
+ except Exception as exc:
+ print exc
+
+# XXX This is currently broken, but we need to fix it to avoid
+# orphaned processes in case of a crash.
+# atexit.register(kill_the_children)
def do_display_version(opts):
@@ -116,16 +109,22 @@ def do_mail_plumbing(opts):
# XXX catch when import is used w/o acct
-def main():
+def start_app():
"""
Starts the main event loop and launches the main window.
"""
+ # Ignore the signals since we handle them in the subprocesses
+ # signal.signal(signal.SIGINT, signal.SIG_IGN)
+
# Parse arguments and store them
opts = leap_argparse.get_options()
do_display_version(opts)
- bypass_checks = opts.danger
- start_hidden = opts.start_hidden
+ options = {
+ 'start_hidden': opts.start_hidden,
+ 'debug': opts.debug,
+ 'log_file': opts.log_file,
+ }
flags.STANDALONE = opts.standalone
flags.OFFLINE = opts.offline
@@ -177,59 +176,17 @@ def main():
logger.info('Starting app')
- # We force the style if on KDE so that it doesn't load all the kde
- # libs, which causes a compatibility issue in some systems.
- # For more info, see issue #3194
- if flags.STANDALONE and os.environ.get("KDE_SESSION_UID") is not None:
- sys.argv.append("-style")
- sys.argv.append("Cleanlooks")
-
- app = QtGui.QApplication(sys.argv)
-
- # To test:
- # $ LANG=es ./app.py
- locale = QtCore.QLocale.system().name()
- qtTranslator = QtCore.QTranslator()
- if qtTranslator.load("qt_%s" % locale, ":/translations"):
- app.installTranslator(qtTranslator)
- appTranslator = QtCore.QTranslator()
- if appTranslator.load("%s.qm" % locale[:2], ":/translations"):
- app.installTranslator(appTranslator)
-
- # Needed for initializing qsettings it will write
- # .config/leap/leap.conf top level app settings in a platform
- # independent way
- app.setOrganizationName("leap")
- app.setApplicationName("leap")
- app.setOrganizationDomain("leap.se")
-
- # XXX ---------------------------------------------------------
- # In quarantine, looks like we don't need it anymore.
- # This dummy timer ensures that control is given to the outside
- # loop, so we can hook our sigint handler.
- #timer = QtCore.QTimer()
- #timer.start(500)
- #timer.timeout.connect(lambda: None)
- # XXX ---------------------------------------------------------
-
- window = MainWindow(bypass_checks=bypass_checks,
- start_hidden=start_hidden)
-
- sigint_window = partial(sigint_handler, window, logger=logger)
- signal.signal(signal.SIGINT, sigint_window)
-
- # callable used in addSystemEventTrigger to handle SIGTERM
- sigterm_window = partial(sigterm_handler, window, logger=logger)
-
- l = LoopingCall(QtCore.QCoreApplication.processEvents, 0, 10)
- l.start(0.01)
-
- # SIGTERM can't be handled the same way SIGINT is, since it's
- # caught by twisted. See _handleSignals method in
- # twisted/internet/base.py#L1150. So, addSystemEventTrigger
- # reactor's method is used.
- reactor.addSystemEventTrigger('before', 'shutdown', sigterm_window)
- reactor.run()
+ generate_certificates()
+
+ flags_dict = flags_to_dict()
+
+ backend = lambda: run_backend(opts.danger, flags_dict)
+ backend_process = multiprocessing.Process(target=backend, name='Backend')
+ backend_process.daemon = True
+ backend_process.start()
+
+ run_frontend(options, flags_dict)
+
if __name__ == "__main__":
- main()
+ start_app()