diff options
| -rw-r--r-- | src/leap/bitmask/app.py | 73 | ||||
| -rw-r--r-- | src/leap/bitmask/gui/mainwindow.py | 10 | ||||
| -rw-r--r-- | src/leap/bitmask/gui/twisted_main.py | 5 | ||||
| -rw-r--r-- | src/leap/bitmask/logs/utils.py | 2 | ||||
| -rw-r--r-- | src/leap/bitmask/services/tx.py | 46 | 
5 files changed, 27 insertions, 109 deletions
| diff --git a/src/leap/bitmask/app.py b/src/leap/bitmask/app.py index e965604a..374c91d2 100644 --- a/src/leap/bitmask/app.py +++ b/src/leap/bitmask/app.py @@ -48,9 +48,15 @@ from functools import partial  from PySide import QtCore, QtGui  from leap.bitmask import __version__ as VERSION -from leap.bitmask.util import leap_argparse -from leap.bitmask.logs.utils import get_logger +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.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.requirement_checker import check_requirements +  from leap.common.events import server as event_server  from leap.mail import __version__ as MAIL_VERSION @@ -114,35 +120,16 @@ def main():      """      Starts the main event loop and launches the main window.      """ -    # TODO move boilerplate outa here! +    # Parse arguments and store them      _, opts = leap_argparse.init_leapc_args()      do_display_version(opts) -    standalone = opts.standalone -    offline = opts.offline -    bypass_checks = getattr(opts, 'danger', False) -    debug = opts.debug -    logfile = opts.log_file -    mail_logfile = opts.mail_log_file +    bypass_checks = opts.danger      start_hidden = opts.start_hidden -    replace_stdout = True -    if opts.repair or opts.import_maildir: -        # We don't want too much clutter on the comand mode -        # this could be more generic with a Command class. -        replace_stdout = False - -    logger = get_logger(debug, logfile, replace_stdout) - -    ############################################################# -    # Given how paths and bundling works, we need to delay the imports -    # of certain parts that depend on this path settings. -    # So first we set all the places where standalone might be queried. -    from leap.bitmask.config import flags -    from leap.common.config.baseconfig import BaseConfig -    flags.STANDALONE = standalone -    flags.OFFLINE = offline -    flags.MAIL_LOGFILE = mail_logfile +    flags.STANDALONE = opts.standalone +    flags.OFFLINE = opts.offline +    flags.MAIL_LOGFILE = opts.mail_log_file      flags.APP_VERSION_CHECK = opts.app_version_check      flags.API_VERSION_CHECK = opts.api_version_check      flags.OPENVPN_VERBOSITY = opts.openvpn_verb @@ -150,7 +137,13 @@ def main():      flags.CA_CERT_FILE = opts.ca_cert_file -    BaseConfig.standalone = standalone +    replace_stdout = True +    if opts.repair or opts.import_maildir: +        # We don't want too much clutter on the comand mode +        # this could be more generic with a Command class. +        replace_stdout = False + +    logger = create_logger(opts.debug, opts.log_file, replace_stdout)      # ok, we got logging in place, we can satisfy mail plumbing requests      # and show logs there. it normally will exit there if we got that path. @@ -167,18 +160,6 @@ def main():          nice = os.nice(int(PLAY_NICE))          logger.info("Setting NICE: %s" % nice) -    # And then we import all the other stuff -    # I think it's safe to import at the top by now -- kali -    from leap.bitmask.gui import locale_rc -    from leap.bitmask.gui import twisted_main -    from leap.bitmask.gui.mainwindow import MainWindow -    from leap.bitmask.platform_init import IS_MAC -    from leap.bitmask.platform_init.locks import we_are_the_one_and_only -    from leap.bitmask.util.requirement_checker import check_requirements - -    # pylint: avoid unused import -    assert(locale_rc) -      # TODO move to a different module: commands?      if not we_are_the_one_and_only():          # Bitmask is already running @@ -231,10 +212,8 @@ def main():      #timer.timeout.connect(lambda: None)      # XXX --------------------------------------------------------- -    window = MainWindow( -        lambda: twisted_main.quit(app), -        bypass_checks=bypass_checks, -        start_hidden=start_hidden) +    window = MainWindow(bypass_checks=bypass_checks, +                        start_hidden=start_hidden)      sigint_window = partial(sigint_handler, window, logger=logger)      signal.signal(signal.SIGINT, sigint_window) @@ -242,14 +221,6 @@ def main():      # callable used in addSystemEventTrigger to handle SIGTERM      sigterm_window = partial(sigterm_handler, window, logger=logger) -    if IS_MAC: -        window.raise_() - -    # This was a good idea, but for this to work as intended we -    # should centralize the start of all services in there. -    #tx_app = leap_services() -    #assert(tx_app) -      l = LoopingCall(QtCore.QCoreApplication.processEvents, 0, 10)      l.start(0.01) diff --git a/src/leap/bitmask/gui/mainwindow.py b/src/leap/bitmask/gui/mainwindow.py index 3ef994b1..885cb792 100644 --- a/src/leap/bitmask/gui/mainwindow.py +++ b/src/leap/bitmask/gui/mainwindow.py @@ -39,6 +39,7 @@ from leap.bitmask.gui.mail_status import MailStatusWidget  from leap.bitmask.gui.preferenceswindow import PreferencesWindow  from leap.bitmask.gui.systray import SysTray  from leap.bitmask.gui.wizard import Wizard +from leap.bitmask.gui import twisted_main  from leap.bitmask.platform_init import IS_WIN, IS_MAC, IS_LINUX  from leap.bitmask.platform_init.initializers import init_platform @@ -91,14 +92,10 @@ class MainWindow(QtGui.QMainWindow):      # We give the services some time to a halt before forcing quit.      SERVICES_STOP_TIMEOUT = 20 -    def __init__(self, quit_callback, bypass_checks=False, start_hidden=False): +    def __init__(self, bypass_checks=False, start_hidden=False):          """          Constructor for the client main window -        :param quit_callback: Function to be called when closing -                              the application. -        :type quit_callback: callable -          :param bypass_checks: Set to true if the app should bypass first round                                of checks for CA certificates at bootstrap          :type bypass_checks: bool @@ -117,7 +114,6 @@ class MainWindow(QtGui.QMainWindow):                   reqcbk=lambda req, resp: None)  # make rpc call async          # end register leap events #################################### -        self._quit_callback = quit_callback          self._updates_content = ""          # setup UI @@ -1818,4 +1814,4 @@ class MainWindow(QtGui.QMainWindow):          self._backend.stop()          self.close() -        reactor.callLater(1, self._quit_callback) +        reactor.callLater(1, twisted_main.quit) diff --git a/src/leap/bitmask/gui/twisted_main.py b/src/leap/bitmask/gui/twisted_main.py index dfd69033..b1ce0ead 100644 --- a/src/leap/bitmask/gui/twisted_main.py +++ b/src/leap/bitmask/gui/twisted_main.py @@ -36,11 +36,8 @@ def stop():      logger.debug("Done stopping all the things.") -def quit(app): +def quit():      """      Stop the mainloop. - -    :param app: the main qt QApplication instance. -    :type app: QtCore.QApplication      """      reactor.callLater(0, stop) diff --git a/src/leap/bitmask/logs/utils.py b/src/leap/bitmask/logs/utils.py index 06959c45..8367937a 100644 --- a/src/leap/bitmask/logs/utils.py +++ b/src/leap/bitmask/logs/utils.py @@ -8,7 +8,7 @@ from leap.bitmask.logs.streamtologger import StreamToLogger  from leap.bitmask.platform_init import IS_WIN -def get_logger(debug=False, logfile=None, replace_stdout=True): +def create_logger(debug=False, logfile=None, replace_stdout=True):      """      Create the logger and attach the handlers. diff --git a/src/leap/bitmask/services/tx.py b/src/leap/bitmask/services/tx.py deleted file mode 100644 index adc6fcea..00000000 --- a/src/leap/bitmask/services/tx.py +++ /dev/null @@ -1,46 +0,0 @@ -# -*- coding: utf-8 -*- -# twisted.py -# Copyright (C) 2013 LEAP -# -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program.  If not, see <http://www.gnu.org/licenses/>. -""" -Twisted services launched by the client -""" -import logging - -from twisted.application.service import Application -#from twisted.internet.task import LoopingCall - -logger = logging.getLogger(__name__) - - -def task(): -    """ -    stub periodic task, mainly for tests. -    DELETE-ME when there's real meat here :) -    """ -    from datetime import datetime -    logger.debug("hi there %s", datetime.now()) - - -def leap_services(): -    """ -    Check which twisted services are enabled and -    register them. -    """ -    logger.debug('starting leap services') -    application = Application("Bitmask Local Services") -    #lc = LoopingCall(task) -    #lc.start(5) -    return application | 
