diff options
author | Ivan Alejandro <ivanalejandro0@gmail.com> | 2015-05-07 11:21:02 -0300 |
---|---|---|
committer | Ivan Alejandro <ivanalejandro0@gmail.com> | 2015-05-27 12:04:29 -0300 |
commit | 5a0de9fd25d783039345674680c67a2bd91815a5 (patch) | |
tree | ec1f07453effdd27b825510a9782c6de11f241ae /src/leap/bitmask | |
parent | 9515c944279e08221de1852ab373d24232dccbf1 (diff) |
[feat] adapt to new events api on common
- Related: #6359
Diffstat (limited to 'src/leap/bitmask')
-rw-r--r-- | src/leap/bitmask/app.py | 2 | ||||
-rw-r--r-- | src/leap/bitmask/crypto/srpauth.py | 13 | ||||
-rw-r--r-- | src/leap/bitmask/gui/mail_status.py | 170 | ||||
-rw-r--r-- | src/leap/bitmask/gui/mainwindow.py | 37 | ||||
-rw-r--r-- | src/leap/bitmask/platform_init/locks.py | 7 | ||||
-rw-r--r-- | src/leap/bitmask/services/mail/conductor.py | 53 |
6 files changed, 140 insertions, 142 deletions
diff --git a/src/leap/bitmask/app.py b/src/leap/bitmask/app.py index 0517a071..db390a63 100644 --- a/src/leap/bitmask/app.py +++ b/src/leap/bitmask/app.py @@ -154,7 +154,7 @@ def start_app(): # do_mail_plumbing(opts) try: - event_server.ensure_server(event_server.SERVER_PORT) + event_server.ensure_server() except Exception as e: # We don't even have logger configured in here print "Could not ensure server: %r" % (e,) diff --git a/src/leap/bitmask/crypto/srpauth.py b/src/leap/bitmask/crypto/srpauth.py index fe177e5a..1e96030e 100644 --- a/src/leap/bitmask/crypto/srpauth.py +++ b/src/leap/bitmask/crypto/srpauth.py @@ -37,8 +37,8 @@ from leap.bitmask.util import request_helpers as reqhelper from leap.bitmask.util.compat import requests_has_max_retries from leap.bitmask.util.constants import REQUEST_TIMEOUT from leap.common.check import leap_assert -from leap.common.events import signal as events_signal -from leap.common.events import events_pb2 as proto +from leap.common.events import emit, catalog + logger = logging.getLogger(__name__) @@ -395,9 +395,7 @@ class SRPAuthImpl(object): (json_content,)) raise SRPAuthBadDataFromServer() - events_signal( - proto.CLIENT_UID, content=uuid, - reqcbk=lambda req, res: None) # make the rpc call async + emit(catalog.CLIENT_UID, uuid) # make the rpc call async return M2 @@ -433,9 +431,8 @@ class SRPAuthImpl(object): logger.error("Bad cookie from server (missing _session_id)") raise SRPAuthNoSessionId() - events_signal( - proto.CLIENT_SESSION_ID, content=session_id, - reqcbk=lambda req, res: None) # make the rpc call asynch + # make the rpc call async + emit(catalog.CLIENT_SESSION_ID, session_id) self.set_session_id(session_id) logger.debug("SUCCESS LOGIN") diff --git a/src/leap/bitmask/gui/mail_status.py b/src/leap/bitmask/gui/mail_status.py index bbfbafb5..a3a1be37 100644 --- a/src/leap/bitmask/gui/mail_status.py +++ b/src/leap/bitmask/gui/mail_status.py @@ -25,7 +25,7 @@ from leap.bitmask.platform_init import IS_LINUX from leap.bitmask.services import get_service_display_name, MX_SERVICE from leap.common.check import leap_assert, leap_assert_type from leap.common.events import register -from leap.common.events import events_pb2 as proto +from leap.common.events import catalog from ui_mail_status import Ui_MailStatusWidget @@ -38,7 +38,7 @@ class MailStatusWidget(QtGui.QWidget): """ _soledad_event = QtCore.Signal(object) _smtp_event = QtCore.Signal(object) - _imap_event = QtCore.Signal(object) + _imap_event = QtCore.Signal(object, object) _keymanager_event = QtCore.Signal(object) def __init__(self, parent=None): @@ -70,51 +70,39 @@ class MailStatusWidget(QtGui.QWidget): self.ERROR_ICON_TRAY = None self._set_mail_icons() - register(signal=proto.KEYMANAGER_LOOKING_FOR_KEY, - callback=self._mail_handle_keymanager_events, - reqcbk=lambda req, resp: None) + register(event=catalog.KEYMANAGER_LOOKING_FOR_KEY, + callback=self._mail_handle_keymanager_events) - register(signal=proto.KEYMANAGER_KEY_FOUND, - callback=self._mail_handle_keymanager_events, - reqcbk=lambda req, resp: None) + register(event=catalog.KEYMANAGER_KEY_FOUND, + callback=self._mail_handle_keymanager_events) - # register(signal=proto.KEYMANAGER_KEY_NOT_FOUND, - # callback=self._mail_handle_keymanager_events, - # reqcbk=lambda req, resp: None) + # register(event=catalog.KEYMANAGER_KEY_NOT_FOUND, + # callback=self._mail_handle_keymanager_events) - register(signal=proto.KEYMANAGER_STARTED_KEY_GENERATION, - callback=self._mail_handle_keymanager_events, - reqcbk=lambda req, resp: None) + register(event=catalog.KEYMANAGER_STARTED_KEY_GENERATION, + callback=self._mail_handle_keymanager_events) - register(signal=proto.KEYMANAGER_FINISHED_KEY_GENERATION, - callback=self._mail_handle_keymanager_events, - reqcbk=lambda req, resp: None) + register(event=catalog.KEYMANAGER_FINISHED_KEY_GENERATION, + callback=self._mail_handle_keymanager_events) - register(signal=proto.KEYMANAGER_DONE_UPLOADING_KEYS, - callback=self._mail_handle_keymanager_events, - reqcbk=lambda req, resp: None) + register(event=catalog.KEYMANAGER_DONE_UPLOADING_KEYS, + callback=self._mail_handle_keymanager_events) - register(signal=proto.SOLEDAD_DONE_DOWNLOADING_KEYS, - callback=self._mail_handle_soledad_events, - reqcbk=lambda req, resp: None) + register(event=catalog.SOLEDAD_DONE_DOWNLOADING_KEYS, + callback=self._mail_handle_soledad_events) - register(signal=proto.SOLEDAD_DONE_UPLOADING_KEYS, - callback=self._mail_handle_soledad_events, - reqcbk=lambda req, resp: None) + register(event=catalog.SOLEDAD_DONE_UPLOADING_KEYS, + callback=self._mail_handle_soledad_events) - register(signal=proto.IMAP_UNREAD_MAIL, - callback=self._mail_handle_imap_events, - reqcbk=lambda req, resp: None) - register(signal=proto.IMAP_SERVICE_STARTED, - callback=self._mail_handle_imap_events, - reqcbk=lambda req, resp: None) - register(signal=proto.SMTP_SERVICE_STARTED, - callback=self._mail_handle_imap_events, - reqcbk=lambda req, resp: None) + register(event=catalog.MAIL_UNREAD_MESSAGES, + callback=self._mail_handle_imap_events) + register(event=catalog.IMAP_SERVICE_STARTED, + callback=self._mail_handle_imap_events) + register(event=catalog.SMTP_SERVICE_STARTED, + callback=self._mail_handle_imap_events) - register(signal=proto.SOLEDAD_INVALID_AUTH_TOKEN, - callback=self.set_soledad_invalid_auth_token, - reqcbk=lambda req, resp: None) + register(event=catalog.SOLEDAD_INVALID_AUTH_TOKEN, + callback=self.set_soledad_invalid_auth_token) self._soledad_event.connect( self._mail_handle_soledad_events_slot) @@ -194,12 +182,14 @@ class MailStatusWidget(QtGui.QWidget): msg = self.tr("There was an unexpected problem with Soledad.") self._set_mail_status(msg, ready=-1) - def set_soledad_invalid_auth_token(self): + def set_soledad_invalid_auth_token(self, event, content): """ - TRIGGERS: - SoledadBootstrapper.soledad_invalid_token - This method is called when the auth token is invalid + + :param event: The event that triggered the callback. + :type event: str + :param content: The content of the event. + :type content: list """ msg = self.tr("Invalid auth token, try logging in again.") self._set_mail_status(msg, ready=-1) @@ -239,58 +229,62 @@ class MailStatusWidget(QtGui.QWidget): self._action_mail_status.setText(tray_status) self._update_systray_tooltip() - def _mail_handle_soledad_events(self, req): + def _mail_handle_soledad_events(self, event, content): """ Callback for handling events that are emitted from Soledad - :param req: Request type - :type req: leap.common.events.events_pb2.SignalRequest + :param event: The event that triggered the callback. + :type event: str + :param content: The content of the event. + :type content: list """ - self._soledad_event.emit(req) + self._soledad_event.emit(event) - def _mail_handle_soledad_events_slot(self, req): + def _mail_handle_soledad_events_slot(self, event): """ TRIGGERS: _mail_handle_soledad_events Reacts to an Soledad event - :param req: Request type - :type req: leap.common.events.events_pb2.SignalRequest + :param event: The event that triggered the callback. + :type event: str """ self._set_mail_status(self.tr("Starting..."), ready=1) ext_status = "" - if req.event == proto.SOLEDAD_DONE_UPLOADING_KEYS: + if event == catalog.SOLEDAD_DONE_UPLOADING_KEYS: ext_status = self.tr("Soledad has started...") - elif req.event == proto.SOLEDAD_DONE_DOWNLOADING_KEYS: + elif event == catalog.SOLEDAD_DONE_DOWNLOADING_KEYS: ext_status = self.tr("Soledad is starting, please wait...") else: leap_assert(False, "Don't know how to handle this state: %s" - % (req.event)) + % (event)) self._set_mail_status(ext_status, ready=1) - def _mail_handle_keymanager_events(self, req): + def _mail_handle_keymanager_events(self, event, content): """ Callback for the KeyManager events - :param req: Request type - :type req: leap.common.events.events_pb2.SignalRequest + :param event: The event that triggered the callback. + :type event: str + :param content: The content of the event. + :type content: list """ - self._keymanager_event.emit(req) + self._keymanager_event.emit(event) - def _mail_handle_keymanager_events_slot(self, req): + def _mail_handle_keymanager_events_slot(self, event): """ TRIGGERS: _mail_handle_keymanager_events Reacts to an KeyManager event - :param req: Request type - :type req: leap.common.events.events_pb2.SignalRequest + :param event: The event that triggered the callback. + :type event: str """ # We want to ignore this kind of events once everything has # started @@ -299,88 +293,92 @@ class MailStatusWidget(QtGui.QWidget): ext_status = "" - if req.event == proto.KEYMANAGER_LOOKING_FOR_KEY: + if event == catalog.KEYMANAGER_LOOKING_FOR_KEY: ext_status = self.tr("Initial sync in progress, please wait...") - elif req.event == proto.KEYMANAGER_KEY_FOUND: + elif event == catalog.KEYMANAGER_KEY_FOUND: ext_status = self.tr("Found key! Starting mail...") - # elif req.event == proto.KEYMANAGER_KEY_NOT_FOUND: + # elif event == catalog.KEYMANAGER_KEY_NOT_FOUND: # ext_status = self.tr("Key not found!") - elif req.event == proto.KEYMANAGER_STARTED_KEY_GENERATION: + elif event == catalog.KEYMANAGER_STARTED_KEY_GENERATION: ext_status = self.tr( "Generating new key, this may take a few minutes.") - elif req.event == proto.KEYMANAGER_FINISHED_KEY_GENERATION: + elif event == catalog.KEYMANAGER_FINISHED_KEY_GENERATION: ext_status = self.tr("Finished generating key!") - elif req.event == proto.KEYMANAGER_DONE_UPLOADING_KEYS: + elif event == catalog.KEYMANAGER_DONE_UPLOADING_KEYS: ext_status = self.tr("Starting mail...") else: leap_assert(False, "Don't know how to handle this state: %s" - % (req.event)) + % (event)) self._set_mail_status(ext_status, ready=1) - def _mail_handle_smtp_events(self, req): + def _mail_handle_smtp_events(self, event): """ Callback for the SMTP events - :param req: Request type - :type req: leap.common.events.events_pb2.SignalRequest + :param event: The event that triggered the callback. + :type event: str """ - self._smtp_event.emit(req) + self._smtp_event.emit(event) - def _mail_handle_smtp_events_slot(self, req): + def _mail_handle_smtp_events_slot(self, event): """ TRIGGERS: _mail_handle_smtp_events Reacts to an SMTP event - :param req: Request type - :type req: leap.common.events.events_pb2.SignalRequest + :param event: The event that triggered the callback. + :type event: str """ ext_status = "" - if req.event == proto.SMTP_SERVICE_STARTED: + if event == catalog.SMTP_SERVICE_STARTED: self._smtp_started = True - elif req.event == proto.SMTP_SERVICE_FAILED_TO_START: + elif event == catalog.SMTP_SERVICE_FAILED_TO_START: ext_status = self.tr("SMTP failed to start, check the logs.") else: leap_assert(False, "Don't know how to handle this state: %s" - % (req.event)) + % (event)) self._set_mail_status(ext_status, ready=2) # ----- XXX deprecate (move to mail conductor) - def _mail_handle_imap_events(self, req): + def _mail_handle_imap_events(self, event, content): """ Callback for the IMAP events - :param req: Request type - :type req: leap.common.events.events_pb2.SignalRequest + :param event: The event that triggered the callback. + :type event: str + :param content: The content of the event. + :type content: list """ - self._imap_event.emit(req) + self._imap_event.emit(event, content) - def _mail_handle_imap_events_slot(self, req): + def _mail_handle_imap_events_slot(self, event, content): """ TRIGGERS: _mail_handle_imap_events Reacts to an IMAP event - :param req: Request type - :type req: leap.common.events.events_pb2.SignalRequest + :param event: The event that triggered the callback. + :type event: str + :param content: The content of the event. + :type content: list """ ext_status = None - if req.event == proto.IMAP_UNREAD_MAIL: + if event == catalog.MAIL_UNREAD_MESSAGES: # By now, the semantics of the UNREAD_MAIL event are # limited to mails with the Unread flag *in the Inbox". # We could make this configurable to include all unread mail # or all unread mail in subscribed folders. if self._started: - count = req.content + count = content if count != "0": status = self.tr("{0} Unread Emails " "in your Inbox").format(count) @@ -390,7 +388,7 @@ class MailStatusWidget(QtGui.QWidget): self._set_mail_status(status, ready=2) else: self._set_mail_status("", ready=2) - elif req.event == proto.IMAP_SERVICE_STARTED: + elif event == catalog.IMAP_SERVICE_STARTED: self._imap_started = True if ext_status is not None: self._set_mail_status(ext_status, ready=1) diff --git a/src/leap/bitmask/gui/mainwindow.py b/src/leap/bitmask/gui/mainwindow.py index 4b665337..0df6ef84 100644 --- a/src/leap/bitmask/gui/mainwindow.py +++ b/src/leap/bitmask/gui/mainwindow.py @@ -63,7 +63,7 @@ from leap.bitmask.util.keyring_helpers import has_keyring from leap.bitmask.logs.leap_log_handler import LeapLogHandler from leap.common.events import register -from leap.common.events import events_pb2 as proto +from leap.common.events import catalog from leap.mail.imap.service.imap import IMAP_PORT @@ -107,12 +107,10 @@ class MainWindow(QtGui.QMainWindow, SignalTracker): autostart.set_autostart(True) # register leap events ######################################## - register(signal=proto.UPDATER_NEW_UPDATES, - callback=self._new_updates_available, - reqcbk=lambda req, resp: None) # make rpc call async - register(signal=proto.RAISE_WINDOW, - callback=self._on_raise_window_event, - reqcbk=lambda req, resp: None) # make rpc call async + register(event=catalog.UPDATER_NEW_UPDATES, + callback=self._new_updates_available) # make rpc call async + register(event=catalog.RAISE_WINDOW, + callback=self._on_raise_window_event) # make rpc call async # end register leap events #################################### self._updates_content = "" @@ -682,29 +680,31 @@ class MainWindow(QtGui.QMainWindow, SignalTracker): # updates # - def _new_updates_available(self, req): + def _new_updates_available(self, event, content): """ Callback for the new updates event - :param req: Request type - :type req: leap.common.events.events_pb2.SignalRequest + :param event: The event that triggered the callback. + :type event: str + :param content: The content of the event. + :type content: list """ - self.new_updates.emit(req) + self.new_updates.emit(content) - def _react_to_new_updates(self, req): + def _react_to_new_updates(self, content): """ TRIGGERS: self.new_updates Display the new updates label and sets the updates_content - :param req: Request type - :type req: leap.common.events.events_pb2.SignalRequest + :param content: The content of the event. + :type content: list """ self.moveToThread(QtCore.QCoreApplication.instance().thread()) self.ui.lblNewUpdates.setVisible(True) self.ui.btnMore.setVisible(True) - self._updates_content = req.content + self._updates_content = content def _updates_details(self): """ @@ -1570,9 +1570,14 @@ class MainWindow(QtGui.QMainWindow, SignalTracker): # window handling methods # - def _on_raise_window_event(self, req): + def _on_raise_window_event(self, event, content): """ Callback for the raise window event + + :param event: The event that triggered the callback. + :type event: str + :param content: The content of the event. + :type content: list """ if IS_WIN: locks.raise_window_ack() diff --git a/src/leap/bitmask/platform_init/locks.py b/src/leap/bitmask/platform_init/locks.py index ac45a5ce..eff900fa 100644 --- a/src/leap/bitmask/platform_init/locks.py +++ b/src/leap/bitmask/platform_init/locks.py @@ -23,8 +23,7 @@ import os import platform from leap.bitmask.platform_init import IS_WIN, IS_UNIX -from leap.common.events import signal as signal_event -from leap.common.events import events_pb2 as proto +from leap.common.events import emit, catalog if IS_UNIX: from fcntl import flock, LOCK_EX, LOCK_NB @@ -364,7 +363,7 @@ def we_are_the_one_and_only(): locker.get_lock() we_are_the_one = locker.locked_by_us if not we_are_the_one: - signal_event(proto.RAISE_WINDOW) + emit(catalog.RAISE_WINDOW) return we_are_the_one elif IS_WIN: @@ -385,7 +384,7 @@ def we_are_the_one_and_only(): # let's assume it's a stalled lock we_are_the_one = True - signal_event(proto.RAISE_WINDOW) + emit(catalog.RAISE_WINDOW) while check_interval(): if get_modification_ts(lock_path) > ts: diff --git a/src/leap/bitmask/services/mail/conductor.py b/src/leap/bitmask/services/mail/conductor.py index 42bdd032..b76ce436 100644 --- a/src/leap/bitmask/services/mail/conductor.py +++ b/src/leap/bitmask/services/mail/conductor.py @@ -24,7 +24,7 @@ from leap.bitmask.gui import statemachines from leap.bitmask.services.mail import connection as mail_connection from leap.bitmask.services.mail.emailfirewall import get_email_firewall -from leap.common.events import events_pb2 as leap_events +from leap.common.events import catalog from leap.common.events import register as leap_register @@ -42,15 +42,12 @@ class IMAPControl(object): self.imap_machine = None self.imap_connection = None - leap_register(signal=leap_events.IMAP_SERVICE_STARTED, - callback=self._handle_imap_events, - reqcbk=lambda req, resp: None) - leap_register(signal=leap_events.IMAP_SERVICE_FAILED_TO_START, - callback=self._handle_imap_events, - reqcbk=lambda req, resp: None) - leap_register(signal=leap_events.IMAP_CLIENT_LOGIN, - callback=self._handle_imap_events, - reqcbk=lambda req, resp: None) + leap_register(event=catalog.IMAP_SERVICE_STARTED, + callback=self._handle_imap_events) + leap_register(event=catalog.IMAP_SERVICE_FAILED_TO_START, + callback=self._handle_imap_events) + leap_register(event=catalog.IMAP_CLIENT_LOGIN, + callback=self._handle_imap_events) def set_imap_connection(self, imap_connection): """ @@ -77,18 +74,20 @@ class IMAPControl(object): self._backend.imap_stop_service() - def _handle_imap_events(self, req): + def _handle_imap_events(self, event, content): """ Callback handler for the IMAP events - :param req: Request type - :type req: leap.common.events.events_pb2.SignalRequest + :param event: The event that triggered the callback. + :type event: str + :param content: The content of the event. + :type content: list """ - if req.event == leap_events.IMAP_SERVICE_STARTED: + if event == catalog.IMAP_SERVICE_STARTED: self._on_imap_connected() - elif req.event == leap_events.IMAP_SERVICE_FAILED_TO_START: + elif event == catalog.IMAP_SERVICE_FAILED_TO_START: self._on_imap_failed() - elif req.event == leap_events.IMAP_CLIENT_LOGIN: + elif event == catalog.IMAP_CLIENT_LOGIN: self._on_mail_client_logged_in() def _on_mail_client_logged_in(self): @@ -124,12 +123,10 @@ class SMTPControl(object): self.smtp_connection = None self.smtp_machine = None - leap_register(signal=leap_events.SMTP_SERVICE_STARTED, - callback=self._handle_smtp_events, - reqcbk=lambda req, resp: None) - leap_register(signal=leap_events.SMTP_SERVICE_FAILED_TO_START, - callback=self._handle_smtp_events, - reqcbk=lambda req, resp: None) + leap_register(event=catalog.SMTP_SERVICE_STARTED, + callback=self._handle_smtp_events) + leap_register(event=catalog.SMTP_SERVICE_FAILED_TO_START, + callback=self._handle_smtp_events) def set_smtp_connection(self, smtp_connection): """ @@ -158,16 +155,18 @@ class SMTPControl(object): self.smtp_connection.qtsigs.disconnecting_signal.emit() self._backend.smtp_stop_service() - def _handle_smtp_events(self, req): + def _handle_smtp_events(self, event, content): """ Callback handler for the SMTP events. - :param req: Request type - :type req: leap.common.events.events_pb2.SignalRequest + :param event: The event that triggered the callback. + :type event: str + :param content: The content of the event. + :type content: list """ - if req.event == leap_events.SMTP_SERVICE_STARTED: + if event == catalog.SMTP_SERVICE_STARTED: self.on_smtp_connected() - elif req.event == leap_events.SMTP_SERVICE_FAILED_TO_START: + elif event == catalog.SMTP_SERVICE_FAILED_TO_START: self.on_smtp_failed() def on_smtp_connecting(self): |