summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKali Kaneko <kali@leap.se>2017-08-10 12:55:26 -0400
committerKali Kaneko <kali@leap.se>2017-08-10 15:24:24 -0400
commitc3ee473837be32cd01f222e0609af36f919a90d3 (patch)
tree342064902b8d220898ec20044bb82cd44c8ec64e
parent63b3413ced33d7b63cf1a9a5d37070ec81f627c8 (diff)
[refactor] fail gracefully if some modules not present
this allows for better modularization in, for instance, the debian package. we should be able to install just the submodules for the vpn service, or the mail service. a better modularization needs the mail_services under core to be moved to bitmask.mail, and do the switch in the main service module for bitmask daemon.
-rw-r--r--src/leap/bitmask/cli/keys.py7
-rw-r--r--src/leap/bitmask/core/mail_services.py42
-rw-r--r--src/leap/bitmask/core/service.py10
3 files changed, 44 insertions, 15 deletions
diff --git a/src/leap/bitmask/cli/keys.py b/src/leap/bitmask/cli/keys.py
index 12191a5d..82de3868 100644
--- a/src/leap/bitmask/cli/keys.py
+++ b/src/leap/bitmask/cli/keys.py
@@ -23,7 +23,12 @@ import sys
from colorama import Fore
from leap.bitmask.cli import command
-from leap.bitmask.keymanager.validation import ValidationLevels
+
+try:
+ from leap.bitmask.keymanager.validation import ValidationLevels
+ HAS_KM = True
+except ImportError:
+ HAS_KM = False
class Keys(command.Command):
diff --git a/src/leap/bitmask/core/mail_services.py b/src/leap/bitmask/core/mail_services.py
index 9c34c120..20d6a342 100644
--- a/src/leap/bitmask/core/mail_services.py
+++ b/src/leap/bitmask/core/mail_services.py
@@ -33,19 +33,31 @@ from twisted.logger import Logger
from leap.common.events import catalog, emit_async
from leap.common.files import check_and_fix_urw_only
-from leap.bitmask.mua import pixelizer
-from leap.bitmask.hooks import HookableService
+
from leap.bitmask.bonafide import config
-from leap.bitmask.keymanager import KeyManager
-from leap.bitmask.keymanager.errors import KeyNotFound
-from leap.bitmask.keymanager.validation import ValidationLevels
-from leap.bitmask.mail.constants import INBOX_NAME
-from leap.bitmask.mail.mail import Account
-from leap.bitmask.mail.imap import service as imap_service
-from leap.bitmask.mail.smtp import service as smtp_service
-from leap.bitmask.mail.incoming.service import IncomingMail
-from leap.bitmask.mail.incoming.service import INCOMING_CHECK_PERIOD
+from leap.bitmask.hooks import HookableService
from leap.bitmask.util import get_gpg_bin_path, merge_status
+
+try:
+ from leap.bitmask.keymanager import KeyManager
+ from leap.bitmask.keymanager.errors import KeyNotFound
+ from leap.bitmask.keymanager.validation import ValidationLevels
+ from leap.bitmask.mail.constants import INBOX_NAME
+ from leap.bitmask.mail.mail import Account
+ from leap.bitmask.mail.imap import service as imap_service
+ from leap.bitmask.mail.smtp import service as smtp_service
+ from leap.bitmask.mail.incoming.service import IncomingMail
+ from leap.bitmask.mail.incoming.service import INCOMING_CHECK_PERIOD
+ HAS_MAIL = True
+except ImportError:
+ HAS_MAIL = False
+
+try:
+ from leap.bitmask.mua import pixelizer
+ HAS_MUA = True
+except ImportError:
+ HAS_MUA = False
+
from leap.soledad.client.api import Soledad
from leap.bitmask.core.uuid_map import UserMap
@@ -628,7 +640,7 @@ class StandardMailService(service.MultiService, HookableService):
def _maybe_start_pixelated(self, passthrough, userid, soledad, keymanager):
incoming = self.getServiceNamed('incoming_mail')
account = incoming.getServiceNamed(userid).account
- if pixelizer.HAS_PIXELATED:
+ if HAS_MUA and pixelizer.HAS_PIXELATED:
pixelizer.start_pixelated_user_agent(
userid, soledad, keymanager, account)
return passthrough
@@ -646,6 +658,9 @@ class IMAPService(service.Service):
super(IMAPService, self).__init__()
def startService(self):
+ if not HAS_MAIL:
+ self.log.info('Mail module not found')
+ return
self.log.info('Starting IMAP Service')
port, factory = imap_service.run_service(
self._soledad_sessions, factory=self._factory)
@@ -686,6 +701,9 @@ class SMTPService(service.Service):
super(SMTPService, self).__init__()
def startService(self):
+ if not HAS_MAIL:
+ self.log.info('Mail module not found')
+ return
self.log.info('starting smtp service')
port, factory = smtp_service.run_service(
self._soledad_sessions,
diff --git a/src/leap/bitmask/core/service.py b/src/leap/bitmask/core/service.py
index 6244b17e..ec3536f2 100644
--- a/src/leap/bitmask/core/service.py
+++ b/src/leap/bitmask/core/service.py
@@ -35,8 +35,13 @@ from leap.bitmask.core import flags
from leap.bitmask.core import _zmq
from leap.bitmask.core import _session
from leap.bitmask.core.web.service import HTTPDispatcherService
-from leap.bitmask.vpn.service import VPNService
from leap.common.events import server as event_server
+try:
+ from leap.bitmask.vpn.service import VPNService
+ HAS_VPN = True
+except ImportError:
+ HAS_VPN = False
+
backend = flags.BACKEND
@@ -201,7 +206,8 @@ class BitmaskBackend(configurable.ConfigurableService):
self._maybe_init_service('mail', service, self.basedir)
def _init_vpn(self):
- self._maybe_init_service('vpn', VPNService)
+ if HAS_VPN:
+ self._maybe_init_service('vpn', VPNService)
def _init_zmq(self):
zs = _zmq.ZMQServerService(self)