当前位置: 首页>>代码示例>>Python>>正文


Python legacy.LibraryDatabase类代码示例

本文整理汇总了Python中calibre.db.legacy.LibraryDatabase的典型用法代码示例。如果您正苦于以下问题:Python LibraryDatabase类的具体用法?Python LibraryDatabase怎么用?Python LibraryDatabase使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了LibraryDatabase类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: doit

 def doit(self):
     from calibre.db.legacy import LibraryDatabase
     newdb = LibraryDatabase(self.loc, is_second_db=True)
     with closing(newdb):
         self._doit(newdb)
     newdb.break_cycles()
     del newdb
开发者ID:pselle,项目名称:calibre,代码行数:7,代码来源:copy_to_library.py

示例2: doit

 def doit(self):
     from calibre.db.legacy import LibraryDatabase
     newdb = LibraryDatabase(self.loc, is_second_db=True)
     with closing(newdb):
         if self.check_for_duplicates:
             self.find_identical_books_data = newdb.new_api.data_for_find_identical_books()
         self._doit(newdb)
     newdb.break_cycles()
     del newdb
开发者ID:davidfor,项目名称:calibre,代码行数:9,代码来源:copy_to_library.py

示例3: __init__

 def __init__(self, libraries):
     self.lock = Lock()
     self.lmap = OrderedDict()
     self.library_name_map = {}
     self.original_path_map = {}
     seen = set()
     for original_path in libraries:
         path = canonicalize_path(original_path)
         if path in seen:
             continue
         is_samefile = False
         for s in seen:
             if samefile(s, path):
                 is_samefile = True
                 break
         seen.add(path)
         if is_samefile or not LibraryDatabase.exists_at(path):
             continue
         library_id = library_id_from_path(original_path, self.lmap)
         self.lmap[library_id] = path
         self.library_name_map[library_id] = basename(original_path)
         self.original_path_map[path] = original_path
     self.loaded_dbs = {}
     self.category_caches, self.search_caches, self.tag_browser_caches = (
         defaultdict(OrderedDict), defaultdict(OrderedDict),
         defaultdict(OrderedDict))
开发者ID:bwhitenb5e,项目名称:calibre,代码行数:26,代码来源:library_broker.py

示例4: main

def main(args=sys.argv):
    opts, args = create_option_parser().parse_args(args)
    if opts.auto_reload:
        if getattr(opts, 'daemonize', False):
            raise SystemExit(
                'Cannot specify --auto-reload and --daemonize at the same time')
        from calibre.srv.auto_reload import auto_reload, NoAutoReload
        try:
            from calibre.utils.logging import default_log
            return auto_reload(default_log, listen_on=opts.listen_on)
        except NoAutoReload as e:
            raise SystemExit(error_message(e))

    ensure_single_instance()
    if opts.userdb:
        opts.userdb = os.path.abspath(os.path.expandvars(os.path.expanduser(opts.userdb)))
        connect(opts.userdb, exc_class=SystemExit).close()
    if opts.manage_users:
        try:
            manage_users_cli(opts.userdb)
        except (KeyboardInterrupt, EOFError):
            raise SystemExit(_('Interrupted by user'))
        raise SystemExit(0)

    libraries = args[1:]
    for lib in libraries:
        if not lib or not LibraryDatabase.exists_at(lib):
            raise SystemExit(_('There is no calibre library at: %s') % lib)
    libraries = libraries or load_gui_libraries()
    if not libraries:
        if not prefs['library_path']:
            raise SystemExit(_('You must specify at least one calibre library'))
        libraries = [prefs['library_path']]

    opts.auto_reload_port = int(os.environ.get('CALIBRE_AUTORELOAD_PORT', 0))
    opts.allow_console_print = 'CALIBRE_ALLOW_CONSOLE_PRINT' in os.environ
    if opts.log and os.path.isdir(opts.log):
        raise SystemExit('The --log option must point to a file, not a directory')
    if opts.access_log and os.path.isdir(opts.access_log):
        raise SystemExit('The --access-log option must point to a file, not a directory')
    server = Server(libraries, opts)
    if getattr(opts, 'daemonize', False):
        if not opts.log and not iswindows:
            raise SystemExit(
                'In order to daemonize you must specify a log file, you can use /dev/stdout to log to screen even as a daemon'
            )
        daemonize()
    if opts.pidfile:
        with lopen(opts.pidfile, 'wb') as f:
            f.write(unicode_type(os.getpid()).encode('ascii'))
    signal.signal(signal.SIGTERM, lambda s, f: server.stop())
    if not getattr(opts, 'daemonize', False) and not iswindows:
        signal.signal(signal.SIGHUP, lambda s, f: server.stop())
    # Needed for dynamic cover generation, which uses Qt for drawing
    from calibre.gui2 import ensure_app, load_builtin_fonts
    ensure_app(), load_builtin_fonts()
    try:
        server.serve_forever()
    finally:
        shutdown_delete_service()
开发者ID:j-howell,项目名称:calibre,代码行数:60,代码来源:standalone.py

示例5: main

def main(args=sys.argv):
    opts, args = create_option_parser().parse_args(args)
    libraries = args[1:]
    for lib in libraries:
        if not lib or not LibraryDatabase.exists_at(lib):
            raise SystemExit(_('There is no calibre library at: %s') % lib)
    if not libraries:
        if not prefs['library_path']:
            raise SystemExit(_('You must specify at least one calibre library'))
        libraries = [prefs['library_path']]

    if opts.auto_reload:
        if opts.daemonize:
            raise SystemExit('Cannot specify --auto-reload and --daemonize at the same time')
        from calibre.srv.auto_reload import auto_reload, NoAutoReload
        try:
            from calibre.utils.logging import default_log
            return auto_reload(default_log)
        except NoAutoReload as e:
            raise SystemExit(e.message)
    server = Server(libraries, opts)
    if opts.daemonize:
        if not opts.log and not iswindows:
            raise SystemExit('In order to daemonize you must specify a log file, you can use /dev/stdout to log to screen even as a daemon')
        daemonize()
    if opts.pidfile:
        with lopen(opts.pidfile, 'wb') as f:
            f.write(str(os.getpid()))
    signal.signal(signal.SIGTERM, lambda s,f: server.stop())
    if not opts.daemonize and not iswindows:
        signal.signal(signal.SIGHUP, lambda s,f: server.stop())
    server.serve_forever()
开发者ID:bartoreebbo,项目名称:calibre,代码行数:32,代码来源:standalone.py

示例6: move_library

def move_library(oldloc, newloc, parent, callback_on_complete):
    from calibre.db.legacy import LibraryDatabase
    callback = Callback(callback_on_complete)
    try:
        if not os.path.exists(os.path.join(newloc, 'metadata.db')):
            if oldloc and os.access(os.path.join(oldloc, 'metadata.db'), os.R_OK):
                # Move old library to new location
                try:
                    db = LibraryDatabase(oldloc)
                except:
                    return move_library(None, newloc, parent,
                        callback)
                else:
                    rq = Queue()
                    m = MoveLibrary(oldloc, newloc,
                            len(db.get_top_level_move_items()[0]), rq)
                    global _mm
                    _mm = MoveMonitor(m, rq, callback, parent)
                    return
            else:
                # Create new library at new location
                db = LibraryDatabase(newloc)
                callback(newloc)
                return

        # Try to load existing library at new location
        try:
            LibraryDatabase(newloc)
        except Exception as err:
            det = traceback.format_exc()
            error_dialog(parent, _('Invalid database'),
                _('<p>An invalid library already exists at '
                    '%(loc)s, delete it before trying to move the '
                    'existing library.<br>Error: %(err)s')%dict(loc=newloc,
                        err=str(err)), det, show=True)
            callback(None)
            return
        else:
            callback(newloc)
            return
    except Exception as err:
        det = traceback.format_exc()
        error_dialog(parent, _('Could not move library'),
                unicode(err), det, show=True)
    callback(None)
开发者ID:GRiker,项目名称:calibre,代码行数:45,代码来源:__init__.py

示例7: update_all_by_isbn

def update_all_by_isbn(library_path):
    def do_book_update(id):
        book_id = int(id)
        mi = db.get_metadata(book_id, index_is_id=True)
        douban_mi = douban.get_douban_metadata(mi)
        if not douban_mi:
            logging.error("-- erro %d" % book_id)
            raise
        if mi.cover_data[0]:
            douban_mi.cover_data = None
        mi.smart_update(douban_mi, replace_metadata=True)
        db.set_metadata(book_id, mi)
        logging.error("** done %d" % book_id)

    db = LibraryDatabase(os.path.expanduser(library_path))
    ids = db.search_getting_ids('', None)
    for i in ids:
        if i < 2837: continue
        try: do_book_update(i)
        except: pass
    return 0
开发者ID:nozuono,项目名称:calibre-webserver,代码行数:21,代码来源:tools.py

示例8: main

def main(args=sys.argv):
    opts, args = create_option_parser().parse_args(args)
    if opts.manage_users:
        try:
            manage_users(opts.userdb)
        except (KeyboardInterrupt, EOFError):
            raise SystemExit(_("Interrupted by user"))
        raise SystemExit(0)

    libraries = args[1:]
    for lib in libraries:
        if not lib or not LibraryDatabase.exists_at(lib):
            raise SystemExit(_("There is no calibre library at: %s") % lib)
    if not libraries:
        if not prefs["library_path"]:
            raise SystemExit(_("You must specify at least one calibre library"))
        libraries = [prefs["library_path"]]

    if opts.auto_reload:
        if opts.daemonize:
            raise SystemExit("Cannot specify --auto-reload and --daemonize at the same time")
        from calibre.srv.auto_reload import auto_reload, NoAutoReload

        try:
            from calibre.utils.logging import default_log

            return auto_reload(default_log)
        except NoAutoReload as e:
            raise SystemExit(e.message)
    opts.auto_reload_port = int(os.environ.get("CALIBRE_AUTORELOAD_PORT", 0))
    try:
        server = Server(libraries, opts)
    except InvalidCredentials as e:
        raise SystemExit(e.message)
    if opts.daemonize:
        if not opts.log and not iswindows:
            raise SystemExit(
                "In order to daemonize you must specify a log file, you can use /dev/stdout to log to screen even as a daemon"
            )
        daemonize()
    if opts.pidfile:
        with lopen(opts.pidfile, "wb") as f:
            f.write(str(os.getpid()))
    signal.signal(signal.SIGTERM, lambda s, f: server.stop())
    if not opts.daemonize and not iswindows:
        signal.signal(signal.SIGHUP, lambda s, f: server.stop())
    server.serve_forever()
开发者ID:nospy,项目名称:calibre,代码行数:47,代码来源:standalone.py

示例9: main

def main(args=sys.argv):
    opts, args=create_option_parser().parse_args(args)
    if opts.manage_users:
        try:
            manage_users(opts.userdb)
        except (KeyboardInterrupt, EOFError):
            raise SystemExit(_('Interrupted by user'))
        raise SystemExit(0)

    libraries=args[1:]
    for lib in libraries:
        if not lib or not LibraryDatabase.exists_at(lib):
            raise SystemExit(_('There is no calibre library at: %s') % lib)
    if not libraries:
        if not prefs['library_path']:
            raise SystemExit(_('You must specify at least one calibre library'))
        libraries=[prefs['library_path']]

    if opts.auto_reload:
        if opts.daemonize:
            raise SystemExit('Cannot specify --auto-reload and --daemonize at the same time')
        from calibre.srv.auto_reload import auto_reload, NoAutoReload
        try:
            from calibre.utils.logging import default_log
            return auto_reload(default_log, listen_on=opts.listen_on)
        except NoAutoReload as e:
            raise SystemExit(e.message)
    opts.auto_reload_port=int(os.environ.get('CALIBRE_AUTORELOAD_PORT', 0))
    opts.allow_console_print = 'CALIBRE_ALLOW_CONSOLE_PRINT' in os.environ
    server=Server(libraries, opts)
    if opts.daemonize:
        if not opts.log and not iswindows:
            raise SystemExit('In order to daemonize you must specify a log file, you can use /dev/stdout to log to screen even as a daemon')
        daemonize()
    if opts.pidfile:
        with lopen(opts.pidfile, 'wb') as f:
            f.write(str(os.getpid()))
    signal.signal(signal.SIGTERM, lambda s,f: server.stop())
    if not opts.daemonize and not iswindows:
        signal.signal(signal.SIGHUP, lambda s,f: server.stop())
    # Needed for dynamic cover generation, which uses Qt for drawing
    from calibre.gui2 import ensure_app, load_builtin_fonts
    ensure_app(), load_builtin_fonts()
    server.serve_forever()
开发者ID:Mymei2,项目名称:calibre,代码行数:44,代码来源:standalone.py

示例10: __init__

 def __init__(self, libraries):
     self.lock = Lock()
     self.lmap = {}
     seen = set()
     for i, path in enumerate(os.path.abspath(p) for p in libraries):
         if path in seen:
             continue
         seen.add(path)
         if not LibraryDatabase.exists_at(path):
             continue
         bname = library_id = hexlify(os.path.basename(path).encode('utf-8')).decode('ascii')
         c = 0
         while library_id in self.lmap:
             c += 1
             library_id = bname + '%d' % c
         if i == 0:
             self.default_library = library_id
         self.lmap[library_id] = path
     self.category_caches = {lid:OrderedDict() for lid in self.lmap}
     self.search_caches = {lid:OrderedDict() for lid in self.lmap}
开发者ID:KyoYang,项目名称:calibre,代码行数:20,代码来源:handler.py

示例11: __init__

 def __init__(self, libraries):
     self.lock = Lock()
     self.lmap = {}
     seen = set()
     for i, path in enumerate(os.path.abspath(p) for p in libraries):
         if path in seen:
             continue
         seen.add(path)
         if not LibraryDatabase.exists_at(path):
             continue
         bname = library_id = force_unicode(os.path.basename(path), filesystem_encoding).replace(' ', '_')
         c = 0
         while library_id in self.lmap:
             c += 1
             library_id = bname + '%d' % c
         if i == 0:
             self.default_library = library_id
         self.lmap[library_id] = path
     self.category_caches = {lid:OrderedDict() for lid in self.lmap}
     self.search_caches = {lid:OrderedDict() for lid in self.lmap}
     self.tag_browser_caches = {lid:OrderedDict() for lid in self.lmap}
开发者ID:Britlantine,项目名称:calibre,代码行数:21,代码来源:handler.py

示例12: main

def main(opts, args, dbctx):
    if opts.report is None:
        checks = CHECKS
    else:
        checks = []
        for r in opts.report.split(','):
            found = False
            for c in CHECKS:
                if c[0] == r:
                    checks.append(c)
                    found = True
                    break
            if not found:
                prints(_('Unknown report check'), r)
                return 1

    if opts.names is None:
        names = []
    else:
        names = [f.strip() for f in opts.names.split(',') if f.strip()]
    if opts.exts is None:
        exts = []
    else:
        exts = [f.strip() for f in opts.exts.split(',') if f.strip()]

    if not LibraryDatabase.exists_at(dbctx.library_path):
        prints('No library found at', dbctx.library_path, file=sys.stderr)
        raise SystemExit(1)

    db = LibraryDatabase(dbctx.library_path)
    prints(_('Vacuuming database...'))
    db.new_api.vacuum()
    checker = CheckLibrary(dbctx.library_path, db)
    checker.scan_library(names, exts)
    for check in checks:
        _print_check_library_results(checker, check, as_csv=opts.csv)

    return 0
开发者ID:JimmXinu,项目名称:calibre,代码行数:38,代码来源:cmd_check_library.py

示例13: library_moved

    def library_moved(self, newloc, copy_structure=False, call_close=True,
            allow_rebuild=False):
        if newloc is None:
            return
        default_prefs = None
        try:
            olddb = self.library_view.model().db
            if copy_structure:
                default_prefs = olddb.prefs

            from calibre.utils.formatter_functions import unload_user_template_functions
            unload_user_template_functions(olddb.library_id)
        except:
            olddb = None
        try:
            db = LibraryDatabase(newloc, default_prefs=default_prefs)
        except apsw.Error:
            if not allow_rebuild:
                raise
            import traceback
            repair = question_dialog(self, _('Corrupted database'),
                    _('The library database at %s appears to be corrupted. Do '
                    'you want calibre to try and rebuild it automatically? '
                    'The rebuild may not be completely successful.')
                    % force_unicode(newloc, filesystem_encoding),
                    det_msg=traceback.format_exc()
                    )
            if repair:
                from calibre.gui2.dialogs.restore_library import repair_library_at
                if repair_library_at(newloc, parent=self):
                    db = LibraryDatabase(newloc, default_prefs=default_prefs)
                else:
                    return
            else:
                return
        if self.content_server is not None:
            self.content_server.set_database(db)
        self.library_path = newloc
        prefs['library_path'] = self.library_path
        self.book_on_device(None, reset=True)
        db.set_book_on_device_func(self.book_on_device)
        self.library_view.set_database(db)
        self.tags_view.set_database(db, self.alter_tb)
        self.library_view.model().set_book_on_device_func(self.book_on_device)
        self.status_bar.clear_message()
        self.search.clear()
        self.saved_search.clear()
        self.book_details.reset_info()
        # self.library_view.model().count_changed()
        db = self.library_view.model().db
        self.iactions['Choose Library'].count_changed(db.count())
        self.set_window_title()
        self.apply_named_search_restriction('')  # reset restriction to null
        self.saved_searches_changed(recount=False)  # reload the search restrictions combo box
        if db.prefs['virtual_lib_on_startup']:
            self.apply_virtual_library(db.prefs['virtual_lib_on_startup'])
        self.rebuild_vl_tabs()
        for action in self.iactions.values():
            action.library_changed(db)
        if olddb is not None:
            try:
                if call_close:
                    olddb.close()
            except:
                import traceback
                traceback.print_exc()
            olddb.break_cycles()
        if self.device_connected:
            self.set_books_in_library(self.booklists(), reset=True)
            self.refresh_ondevice()
            self.memory_view.reset()
            self.card_a_view.reset()
            self.card_b_view.reset()
        self.set_current_library_information(current_library_name(), db.library_id,
                                             db.field_metadata)
        self.library_view.set_current_row(0)
        # Run a garbage collection now so that it does not freeze the
        # interface later
        gc.collect()
开发者ID:KyoYang,项目名称:calibre,代码行数:79,代码来源:ui.py

示例14: move_library

def move_library(from_, to, notification=lambda x:x):
    from calibre.db.legacy import LibraryDatabase
    time.sleep(1)
    old = LibraryDatabase(from_)
    old.move_library_to(to, notification)
    return True
开发者ID:Aliminator666,项目名称:calibre,代码行数:6,代码来源:move.py

示例15: is_library_dir_suitable

 def is_library_dir_suitable(self, x):
     try:
         return LibraryDatabase.exists_at(x) or not os.listdir(x)
     except:
         return False
开发者ID:azmrv,项目名称:calibre,代码行数:5,代码来源:__init__.py


注:本文中的calibre.db.legacy.LibraryDatabase类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。