Exemplo n.º 1
0
def run(args):
    """Initialize everthing and run the application."""
    # pylint: disable=too-many-statements
    if args.version:
        print(version.version())
        print()
        print()
        print(qutebrowser.__copyright__)
        print()
        print(version.GPL_BOILERPLATE.strip())
        sys.exit(0)

    quitter = Quitter(args)
    objreg.register('quitter', quitter)

    global qApp
    qApp = Application(args)
    qApp.lastWindowClosed.connect(quitter.on_last_window_closed)

    crash_handler = crashsignal.CrashHandler(app=qApp,
                                             quitter=quitter,
                                             args=args,
                                             parent=qApp)
    crash_handler.activate()
    objreg.register('crash-handler', crash_handler)

    signal_handler = crashsignal.SignalHandler(app=qApp,
                                               quitter=quitter,
                                               parent=qApp)
    signal_handler.activate()
    objreg.register('signal-handler', signal_handler)

    try:
        sent = ipc.send_to_running_instance(args.command)
        if sent:
            sys.exit(0)
        log.init.debug("Starting IPC server...")
        server = ipc.IPCServer(qApp)
        objreg.register('ipc-server', server)
        server.got_args.connect(
            lambda args, cwd: process_pos_args(args, cwd=cwd, via_ipc=True))
    except ipc.AddressInUseError as e:
        # This could be a race condition...
        log.init.debug("Got AddressInUseError, trying again.")
        time.sleep(500)
        sent = ipc.send_to_running_instance(args.command)
        if sent:
            sys.exit(0)
        else:
            ipc.display_error(e)
            sys.exit(1)
    except ipc.Error as e:
        ipc.display_error(e)
        # We didn't really initialize much so far, so we just quit hard.
        sys.exit(1)

    init(args, crash_handler)
    ret = qt_mainloop()
    return ret
Exemplo n.º 2
0
def ipc_server(qapp, qtbot):
    server = ipc.IPCServer('qute-test')
    yield server
    if (server._socket is not None
            and server._socket.state() != QLocalSocket.UnconnectedState):
        with qtbot.waitSignal(server._socket.disconnected, raising=False):
            server._socket.abort()
    try:
        server.shutdown()
    except ipc.Error:
        pass
Exemplo n.º 3
0
def test_long_username(monkeypatch):
    """See https://github.com/qutebrowser/qutebrowser/issues/888."""
    username = '******'
    basedir = '/this_is_a_long_basedir'
    monkeypatch.setattr('getpass.getuser', lambda: username)
    name = ipc._get_socketname(basedir=basedir)
    server = ipc.IPCServer(name)
    expected_md5 = md5('{}-{}'.format(username, basedir))
    assert expected_md5 in server._socketname
    try:
        server.listen()
    finally:
        server.shutdown()
Exemplo n.º 4
0
 def legacy_server(self, args):
     legacy_name = ipc._get_socketname(args.basedir, legacy=True)
     legacy_server = ipc.IPCServer(legacy_name)
     legacy_server.listen()
     yield legacy_server
     legacy_server.shutdown()