summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIvan Alejandro <ivanalejandro0@gmail.com>2014-07-02 12:52:31 -0300
committerIvan Alejandro <ivanalejandro0@gmail.com>2014-07-14 12:14:20 -0300
commit0cab909f9518273d95e371e5fb1061fb9b0a92fd (patch)
tree62d1bd0ea280fa1889a6f84b41cc46a232d2918e
parent13c0b7cac822a33f7395e3f099a2d37251e2c759 (diff)
Send the flag module values to the processes.
Add serialize/deserialize to dict helper.
-rw-r--r--src/leap/bitmask/app.py8
-rw-r--r--src/leap/bitmask/backend_app.py13
-rw-r--r--src/leap/bitmask/frontend_app.py7
-rw-r--r--src/leap/bitmask/util/__init__.py25
4 files changed, 48 insertions, 5 deletions
diff --git a/src/leap/bitmask/app.py b/src/leap/bitmask/app.py
index 43dabad3..d1a2a111 100644
--- a/src/leap/bitmask/app.py
+++ b/src/leap/bitmask/app.py
@@ -53,7 +53,7 @@ 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
@@ -178,11 +178,13 @@ def start_app():
generate_certificates()
- app = lambda: run_frontend(options=options)
+ flags_dict = flags_to_dict()
+
+ app = lambda: run_frontend(options, flags_dict)
gui_process = multiprocessing.Process(target=app)
gui_process.start()
- backend = lambda: run_backend(bypass_checks=opts.danger)
+ backend = lambda: run_backend(opts.danger, flags_dict)
backend_process = multiprocessing.Process(target=backend)
backend_process.start()
diff --git a/src/leap/bitmask/backend_app.py b/src/leap/bitmask/backend_app.py
index bd3b8a1f..d4815d82 100644
--- a/src/leap/bitmask/backend_app.py
+++ b/src/leap/bitmask/backend_app.py
@@ -17,11 +17,22 @@
import signal
from leap.bitmask.backend.leapbackend import LeapBackend
+from leap.bitmask.util import dict_to_flags
-def run_backend(bypass_checks=False):
+def run_backend(bypass_checks, flags_dict):
+ """
+ Run the backend for the application.
+
+ :param bypass_checks: whether we should bypass the checks or not
+ :type bypass_checks: bool
+ :param flags_dict: a dict containing the flag values set on app start.
+ :type flags_dict: dict
+ """
# Ensure that the application quits using CTRL-C
signal.signal(signal.SIGINT, signal.SIG_DFL)
+ dict_to_flags(flags_dict)
+
backend = LeapBackend(bypass_checks=bypass_checks)
backend.run()
diff --git a/src/leap/bitmask/frontend_app.py b/src/leap/bitmask/frontend_app.py
index 60f20e3c..1fe4cd0a 100644
--- a/src/leap/bitmask/frontend_app.py
+++ b/src/leap/bitmask/frontend_app.py
@@ -23,6 +23,7 @@ from PySide import QtCore, QtGui
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.util import dict_to_flags
import logging
logger = logging.getLogger(__name__)
@@ -39,13 +40,17 @@ def sigint_handler(*args, **kwargs):
mainwindow.quit()
-def run_frontend(options):
+def run_frontend(options, flags_dict):
"""
Run the GUI for the application.
:param options: a dict of options parsed from the command line.
:type options: dict
+ :param flags_dict: a dict containing the flag values set on app start.
+ :type flags_dict: dict
"""
+ dict_to_flags(flags_dict)
+
start_hidden = options["start_hidden"]
# We force the style if on KDE so that it doesn't load all the kde
diff --git a/src/leap/bitmask/util/__init__.py b/src/leap/bitmask/util/__init__.py
index 25b86874..caa94ec7 100644
--- a/src/leap/bitmask/util/__init__.py
+++ b/src/leap/bitmask/util/__init__.py
@@ -129,3 +129,28 @@ def force_eval(items):
return map(do_eval, items)
else:
return do_eval(items)
+
+
+def dict_to_flags(values):
+ """
+ Set the flags values given in the values dict.
+ If a value isn't provided then use the already existing one.
+
+ :param values: the values to set.
+ :type values: dict.
+ """
+ for k, v in values.items():
+ setattr(flags, k, v)
+
+
+def flags_to_dict():
+ """
+ Get the flags values in a dict.
+
+ :return: the values of flags into a dict.
+ :rtype: dict.
+ """
+ items = [i for i in dir(flags) if i[0] != '_']
+ values = {i: getattr(flags, i) for i in items}
+
+ return values