summaryrefslogtreecommitdiff
path: root/src/leap/bitmask/app.py
diff options
context:
space:
mode:
authorTomás Touceda <chiiph@leap.se>2014-07-16 16:42:03 -0300
committerTomás Touceda <chiiph@leap.se>2014-07-16 16:42:03 -0300
commit34457adc72a4a4c0b4bff4791f4329bca66162c1 (patch)
tree279542ab3ce460d1f0bcd7943352c3e792c9f2c6 /src/leap/bitmask/app.py
parent4f946ea2189e78da0488a28b3bb8a8aed997a1c5 (diff)
parent3d6629348aedf2a6863d242d96d64b3492e86f9a (diff)
Merge remote-tracking branch 'refs/remotes/ivan/feature/new-frontend-backend' into develop
Diffstat (limited to 'src/leap/bitmask/app.py')
-rw-r--r--src/leap/bitmask/app.py118
1 files changed, 28 insertions, 90 deletions
diff --git a/src/leap/bitmask/app.py b/src/leap/bitmask/app.py
index d0906b7c..88f6bc15 100644
--- a/src/leap/bitmask/app.py
+++ b/src/leap/bitmask/app.py
@@ -39,29 +39,26 @@
# 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.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)
@@ -84,36 +81,7 @@ def kill_the_children():
# 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 sigint_handler(*args, **kwargs):
- """
- Signal handler for SIGINT
- """
- logger = kwargs.get('logger', None)
- parentpid = kwargs.get('parentpid', None)
- pid = os.getpid()
- if parentpid == pid:
- if logger:
- logger.debug("SIGINT catched. shutting down...")
- mainwindow = args[0]
- mainwindow.quit()
-
-
-def sigterm_handler(*args, **kwargs):
- """
- Signal handler for SIGTERM.
- This handler is actually passed to twisted reactor
- """
- logger = kwargs.get('logger', None)
- parentpid = kwargs.get('parentpid', None)
- pid = os.getpid()
- if parentpid == pid:
- if logger:
- logger.debug("SIGTERM catched. shutting down...")
- mainwindow = args[0]
- mainwindow.quit()
+# atexit.register(kill_the_children)
def do_display_version(opts):
@@ -141,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
@@ -202,53 +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")
-
- window = MainWindow(bypass_checks=bypass_checks,
- start_hidden=start_hidden)
-
- mainpid = os.getpid()
- sigint_window = partial(sigint_handler, window,
- logger=logger, parentpid=mainpid)
- signal.signal(signal.SIGINT, sigint_window)
-
- # callable used in addSystemEventTrigger to handle SIGTERM
- sigterm_window = partial(sigterm_handler, window,
- logger=logger, parentpid=mainpid)
- # 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)
-
- l = LoopingCall(QtCore.QCoreApplication.processEvents, 0, 10)
- l.start(0.01)
-
- 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()