summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/leap/bitmask/__init__.py14
-rw-r--r--src/leap/bitmask/core/launcher.py23
-rw-r--r--src/leap/bitmask/gui/app.py21
-rw-r--r--src/leap/bitmask/util.py4
4 files changed, 46 insertions, 16 deletions
diff --git a/src/leap/bitmask/__init__.py b/src/leap/bitmask/__init__.py
index dba87b5..20719d4 100644
--- a/src/leap/bitmask/__init__.py
+++ b/src/leap/bitmask/__init__.py
@@ -1,12 +1,14 @@
+import sys
import pkg_resources
from ._version import get_versions
__version__ = get_versions()['version']
del get_versions
-# FIXME: HACK for https://github.com/pypa/pip/issues/3
-# Without this 'fix', there are resolution conflicts when pip installs at the
-# same time bitmask in develop mode and other package in the leap namespace
-# from pypi. For instance:
-# 'pip install -e .' and 'pip install leap.common'
-pkg_resources.get_distribution('leap.bitmask')
+if not getattr(sys, 'frozen', False):
+ # FIXME: HACK for https://github.com/pypa/pip/issues/3
+ # Without this 'fix', there are resolution conflicts when pip installs at
+ # the same time bitmask in develop mode and other package in the leap
+ # namespace from pypi. For instance:
+ # 'pip install -e .' and 'pip install leap.common'
+ pkg_resources.get_distribution('leap.bitmask')
diff --git a/src/leap/bitmask/core/launcher.py b/src/leap/bitmask/core/launcher.py
index 27e5a26..45acde2 100644
--- a/src/leap/bitmask/core/launcher.py
+++ b/src/leap/bitmask/core/launcher.py
@@ -17,12 +17,11 @@
"""
Run bitmask daemon.
"""
-from os.path import join, abspath
-from sys import argv
+from os.path import join, abspath, dirname
+import sys
from twisted.scripts.twistd import run
-from leap.bitmask.util import here
from leap.bitmask import core
from leap.bitmask.core import flags
from leap.common.config import get_path_prefix
@@ -30,13 +29,27 @@ from leap.common.config import get_path_prefix
pid = abspath(join(get_path_prefix(), 'leap', 'bitmaskd.pid'))
+STANDALONE = getattr(sys, 'frozen', False)
+
+
+def here(module=None):
+ if STANDALONE:
+ # we are running in a |PyInstaller| bundle
+ return sys._MEIPASS
+ else:
+ if module:
+ return dirname(module.__file__)
+ else:
+ return dirname(__file__)
+
+
def run_bitmaskd():
# TODO --- configure where to put the logs... (get --logfile, --logdir
# from the bitmask_cli
- for (index, arg) in enumerate(argv):
+ for (index, arg) in enumerate(sys.argv):
if arg == '--backend':
flags.BACKEND = argv[index + 1]
- argv[1:] = [
+ sys.argv[1:] = [
'-y', join(here(core), "bitmaskd.tac"),
'--pidfile', pid,
'--umask=0022',
diff --git a/src/leap/bitmask/gui/app.py b/src/leap/bitmask/gui/app.py
index fdddc89..c87ba88 100644
--- a/src/leap/bitmask/gui/app.py
+++ b/src/leap/bitmask/gui/app.py
@@ -21,16 +21,22 @@ It just launches a wekbit browser that runs the local web-ui served by bitmaskd
when the web service is running.
"""
+import os
+import signal
import sys
from PyQt5 import QtCore, QtGui, QtWidgets
from PyQt5 import QtWebKit, QtWebKitWidgets
-from bitmask.core.launcher import run_bitmaskd()
+from leap.bitmask.core.launcher import run_bitmaskd, pid
+
+from multiprocessing import Process
+
BITMASK_URI = 'http://localhost:7070'
qApp = None
+bitmaskd = None
class BrowserWindow(QtWidgets.QDialog):
@@ -46,7 +52,13 @@ class BrowserWindow(QtWidgets.QDialog):
self.view.load(QtCore.QUrl(BITMASK_URI))
def shutdown(self):
- print('[bitmask] shutting down...')
+ global bitmaskd
+ bitmaskd.join()
+ with open(pid) as f:
+ pidno = int(f.read())
+ print('[bitmask] terminating bitmaskd...')
+ os.kill(pidno, signal.SIGTERM)
+ print('[bitmask] shutting down gui...')
try:
self.view.stop()
QtCore.QTimer.singleShot(0, qApp.deleteLater)
@@ -59,9 +71,10 @@ class BrowserWindow(QtWidgets.QDialog):
def start_app():
global qApp
+ global bitmaskd
- # TODO should do it if no pid
- run_bitmaskd()
+ bitmaskd = Process(target=run_bitmaskd)
+ bitmaskd.start()
qApp = QtWidgets.QApplication([])
browser = BrowserWindow(None)
diff --git a/src/leap/bitmask/util.py b/src/leap/bitmask/util.py
index 3a99e13..9120fc4 100644
--- a/src/leap/bitmask/util.py
+++ b/src/leap/bitmask/util.py
@@ -25,11 +25,12 @@ from twisted.python import log
from leap.common.files import which
-
STANDALONE = getattr(sys, 'frozen', False)
def here(module=None):
+ global STANDALONE
+
if STANDALONE:
# we are running in a |PyInstaller| bundle
return sys._MEIPASS
@@ -48,6 +49,7 @@ def get_gpg_bin_path():
:returns: the gpg binary path
:rtype: str
"""
+ global STANDALONE
gpgbin = None
if STANDALONE: