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 run(args):
    """Initialize everything and run the application."""
    if args.temp_basedir:
        args.basedir = tempfile.mkdtemp(prefix='qutebrowser-basedir-')

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

    log.init.debug("Initializing directories...")
    standarddir.init(args)
    utils.preload_resources()

    log.init.debug("Initializing config...")
    configinit.early_init(args)

    global qApp
    qApp = Application(args)
    qApp.setOrganizationName("qutebrowser")
    qApp.setApplicationName("qutebrowser")
    qApp.setDesktopFileName("qutebrowser")
    qApp.setApplicationVersion(qutebrowser.__version__)
    qApp.lastWindowClosed.connect(quitter.on_last_window_closed)

    if args.version:
        print(version.version())
        sys.exit(usertypes.Exit.ok)

    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:
        server = ipc.send_or_listen(args)
    except ipc.Error:
        # ipc.send_or_listen already displays the error message for us.
        # We didn't really initialize much so far, so we just quit hard.
        sys.exit(usertypes.Exit.err_ipc)

    if server is None:
        if args.backend is not None:
            log.init.warning("Backend from the running instance will be used")
        sys.exit(usertypes.Exit.ok)
    else:
        server.got_args.connect(lambda args, target_arg, cwd: process_pos_args(
            args, cwd=cwd, via_ipc=True, target_arg=target_arg))

    init(args, crash_handler)
    ret = qt_mainloop()
    return ret
Exemplo n.º 3
0
def run(args):
    """Initialize everything and run the application."""
    # pylint: disable=too-many-statements
    if args.version:
        print(version.version(short=True))
        print()
        print()
        print(qutebrowser.__copyright__)
        print()
        print(version.GPL_BOILERPLATE.strip())
        sys.exit(usertypes.Exit.ok)

    if args.temp_basedir:
        args.basedir = tempfile.mkdtemp(prefix='qutebrowser-basedir-')

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

    global qApp
    qApp = Application(args)
    qApp.setOrganizationName("qutebrowser")
    qApp.setApplicationName("qutebrowser")
    qApp.setApplicationVersion(qutebrowser.__version__)
    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:
        server = ipc.send_or_listen(args)
    except ipc.Error:
        # ipc.send_or_listen already displays the error message for us.
        # We didn't really initialize much so far, so we just quit hard.
        sys.exit(usertypes.Exit.err_ipc)

    if server is None:
        sys.exit(usertypes.Exit.ok)
    else:
        server.got_args.connect(lambda args, target_arg, cwd: process_pos_args(
            args, cwd=cwd, via_ipc=True, target_arg=target_arg))

    init(args, crash_handler)
    ret = qt_mainloop()
    return ret