Ejemplo n.º 1
0
def shutdown_other():
    if send_message('shutdown:'):
        print(_('Shutdown command sent, waiting for shutdown...'), flush=True)
        for i in range(50):
            with SingleInstance(singleinstance_name) as si:
                if si:
                    return
            time.sleep(0.1)
        raise SystemExit(_('Failed to shutdown running calibre instance'))
Ejemplo n.º 2
0
def main(args=sys.argv):
    # Ensure viewer can continue to function if GUI is closed
    os.environ.pop('CALIBRE_WORKER_TEMP_DIR', None)
    reset_base_dir()
    scheme = QWebEngineUrlScheme(FAKE_PROTOCOL.encode('ascii'))
    scheme.setSyntax(QWebEngineUrlScheme.Syntax.Host)
    scheme.setFlags(QWebEngineUrlScheme.Flag.SecureScheme)
    QWebEngineUrlScheme.registerScheme(scheme)
    override = 'calibre-ebook-viewer' if islinux else None
    processed_args = []
    internal_book_data = internal_book_data_path = None
    for arg in args:
        if arg.startswith('--internal-book-data='):
            internal_book_data_path = arg.split('=', 1)[1]
            continue
        processed_args.append(arg)
    if internal_book_data_path:
        try:
            with lopen(internal_book_data_path, 'rb') as f:
                internal_book_data = json.load(f)
        finally:
            try:
                os.remove(internal_book_data_path)
            except OSError:
                pass
    args = processed_args
    app = Application(args, override_program_name=override, windows_app_uid=VIEWER_APP_UID)

    parser = option_parser()
    opts, args = parser.parse_args(args)
    oat = opts.open_at
    if oat and not (
            oat.startswith('toc:') or oat.startswith('toc-href:') or oat.startswith('toc-href-contains:') or
            oat.startswith('epubcfi(/') or is_float(oat) or oat.startswith('ref:')):
        raise SystemExit('Not a valid --open-at value: {}'.format(opts.open_at))

    if get_session_pref('singleinstance', False):
        from calibre.utils.lock import SingleInstance
        from calibre.gui2.listener import Listener
        with SingleInstance(singleinstance_name) as si:
            if si:
                try:
                    listener = Listener(address=viewer_socket_address(), parent=app)
                    listener.start_listening()
                except Exception as err:
                    error_dialog(None, _('Failed to start listener'), _(
                        'Could not start the listener used for single instance viewers. Try rebooting your computer.'),
                                        det_msg=str(err), show=True)
                else:
                    with closing(listener):
                        run_gui(app, opts, args, internal_book_data, listener=listener)
            else:
                send_message_to_viewer_instance(args, opts.open_at)
    else:
        run_gui(app, opts, args, internal_book_data)
Ejemplo n.º 3
0
def run_gui(opts, args, app, gui_debug=None):
    with SingleInstance('db') as si:
        if not si:
            ext = '.exe' if iswindows else ''
            error_dialog(None, _('Cannot start calibre'), _(
                'Another calibre program that can modify calibre libraries, such as,'
                ' {0} or {1} is already running. You must first shut it down, before'
                ' starting the main calibre program. If you are sure no such'
                ' program is running, try restarting your computer.').format(
                    'calibre-server' + ext, 'calibredb' + ext), show=True)
            return 1
        run_gui_(opts, args, app, gui_debug)
Ejemplo n.º 4
0
def shutdown_other(rc=None):
    if rc is None:
        rc = build_pipe(print_error=False)
        if rc.conn is None:
            prints(_('No running calibre found'))
            return  # No running instance found
    rc.conn.send(b'shutdown:')
    prints(_('Shutdown command sent, waiting for shutdown...'))
    for i in range(50):
        with SingleInstance(singleinstance_name) as si:
            if si:
                return
        time.sleep(0.1)
    prints(_('Failed to shutdown running calibre instance'))
    raise SystemExit(1)
Ejemplo n.º 5
0
def main(args=sys.argv):
    if iswindows and 'CALIBRE_REPAIR_CORRUPTED_DB' in os.environ:
        windows_repair()
        return 0
    gui_debug = None
    if args[0] == '__CALIBRE_GUI_DEBUG__':
        gui_debug = args[1]
        args = ['calibre']

    try:
        app, opts, args = init_qt(args)
    except AbortInit:
        return 1
    with SingleInstance(singleinstance_name) as si:
        if si and opts.shutdown_running_calibre:
            return 0
        run_main(app, opts, args, gui_debug, si)
    if after_quit_actions['restart_after_quit']:
        restart_after_quit()