From fdbafa4929cb9969e8f2ea3b256eb4bd9f99a7a7 Mon Sep 17 00:00:00 2001 From: Ivan Alejandro Date: Fri, 6 Jun 2014 12:10:08 -0300 Subject: Move quit callback to mainwindow. --- src/leap/bitmask/app.py | 7 ++----- src/leap/bitmask/gui/mainwindow.py | 10 +++------- src/leap/bitmask/gui/twisted_main.py | 5 +---- 3 files changed, 6 insertions(+), 16 deletions(-) (limited to 'src') diff --git a/src/leap/bitmask/app.py b/src/leap/bitmask/app.py index e965604a..1ed58701 100644 --- a/src/leap/bitmask/app.py +++ b/src/leap/bitmask/app.py @@ -170,7 +170,6 @@ def main(): # 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 @@ -231,10 +230,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) diff --git a/src/leap/bitmask/gui/mainwindow.py b/src/leap/bitmask/gui/mainwindow.py index c61b7dc9..71885a78 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 @@ -1817,4 +1813,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) -- cgit v1.2.3 From 89d01ea3a353e3a7d6f973847d02e16147781448 Mon Sep 17 00:00:00 2001 From: Ivan Alejandro Date: Fri, 6 Jun 2014 12:20:33 -0300 Subject: Remove code already used in mainwindow. --- src/leap/bitmask/app.py | 4 ---- 1 file changed, 4 deletions(-) (limited to 'src') diff --git a/src/leap/bitmask/app.py b/src/leap/bitmask/app.py index 1ed58701..1d2ecfc7 100644 --- a/src/leap/bitmask/app.py +++ b/src/leap/bitmask/app.py @@ -171,7 +171,6 @@ def main(): # I think it's safe to import at the top by now -- kali from leap.bitmask.gui import locale_rc 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 @@ -239,9 +238,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() -- cgit v1.2.3 From f2c94006877fef883cd34e9d6b3f3c329aa39ed1 Mon Sep 17 00:00:00 2001 From: Ivan Alejandro Date: Fri, 6 Jun 2014 12:21:23 -0300 Subject: Remove unused code. --- src/leap/bitmask/app.py | 5 ----- src/leap/bitmask/services/tx.py | 46 ----------------------------------------- 2 files changed, 51 deletions(-) delete mode 100644 src/leap/bitmask/services/tx.py (limited to 'src') diff --git a/src/leap/bitmask/app.py b/src/leap/bitmask/app.py index 1d2ecfc7..65978f72 100644 --- a/src/leap/bitmask/app.py +++ b/src/leap/bitmask/app.py @@ -238,11 +238,6 @@ def main(): # callable used in addSystemEventTrigger to handle SIGTERM sigterm_window = partial(sigterm_handler, window, logger=logger) - # 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/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 . -""" -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 -- cgit v1.2.3 From d2eb54c4789afa780d72e80d89eb0c738ed61a33 Mon Sep 17 00:00:00 2001 From: Ivan Alejandro Date: Fri, 6 Jun 2014 12:41:24 -0300 Subject: Move imports to the top. --- src/leap/bitmask/app.py | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) (limited to 'src') diff --git a/src/leap/bitmask/app.py b/src/leap/bitmask/app.py index 65978f72..8d4a12ba 100644 --- a/src/leap/bitmask/app.py +++ b/src/leap/bitmask/app.py @@ -48,9 +48,14 @@ 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.gui import locale_rc # noqa - silence pylint +from leap.bitmask.gui.mainwindow import MainWindow from leap.bitmask.logs.utils import get_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 @@ -167,16 +172,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.mainwindow import MainWindow - 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 -- cgit v1.2.3 From acac7e91124d59e6456d74118d144edb52675f95 Mon Sep 17 00:00:00 2001 From: Ivan Alejandro Date: Fri, 6 Jun 2014 12:49:31 -0300 Subject: Remove unused code and move imports to the top. --- src/leap/bitmask/app.py | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) (limited to 'src') diff --git a/src/leap/bitmask/app.py b/src/leap/bitmask/app.py index 8d4a12ba..e25ab753 100644 --- a/src/leap/bitmask/app.py +++ b/src/leap/bitmask/app.py @@ -48,6 +48,7 @@ from functools import partial from PySide import QtCore, QtGui from leap.bitmask import __version__ as VERSION +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 get_logger @@ -139,12 +140,6 @@ def main(): 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 @@ -155,8 +150,6 @@ def main(): flags.CA_CERT_FILE = opts.ca_cert_file - BaseConfig.standalone = standalone - # 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. do_mail_plumbing(opts) -- cgit v1.2.3 From 59fb00b65c1fa2813b0751865bd7789e2fbf54f8 Mon Sep 17 00:00:00 2001 From: Ivan Alejandro Date: Fri, 6 Jun 2014 13:00:50 -0300 Subject: Remove unused variables and reorder arg parsing. --- src/leap/bitmask/app.py | 31 +++++++++++++------------------ 1 file changed, 13 insertions(+), 18 deletions(-) (limited to 'src') diff --git a/src/leap/bitmask/app.py b/src/leap/bitmask/app.py index e25ab753..1f20d0d4 100644 --- a/src/leap/bitmask/app.py +++ b/src/leap/bitmask/app.py @@ -120,29 +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) - - 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,6 +137,14 @@ def main(): flags.CA_CERT_FILE = opts.ca_cert_file + 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(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. do_mail_plumbing(opts) -- cgit v1.2.3 From e02b98fbdb868111d20b7447a15f60ca494d27dc Mon Sep 17 00:00:00 2001 From: Ivan Alejandro Date: Fri, 6 Jun 2014 13:02:03 -0300 Subject: Use a more significative name for logger helper. --- src/leap/bitmask/app.py | 4 ++-- src/leap/bitmask/logs/utils.py | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/leap/bitmask/app.py b/src/leap/bitmask/app.py index 1f20d0d4..374c91d2 100644 --- a/src/leap/bitmask/app.py +++ b/src/leap/bitmask/app.py @@ -51,7 +51,7 @@ from leap.bitmask import __version__ as VERSION 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 get_logger +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 @@ -143,7 +143,7 @@ def main(): # this could be more generic with a Command class. replace_stdout = False - logger = get_logger(opts.debug, opts.log_file, replace_stdout) + 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. 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. -- cgit v1.2.3