コード例 #1
0
ファイル: base.py プロジェクト: tokot/calibre
 def init_cache(self, library_path=None):
     from calibre.db.backend import DB
     from calibre.db.cache import Cache
     backend = DB(library_path or self.library_path)
     cache = Cache(backend)
     cache.init()
     return cache
コード例 #2
0
ファイル: base.py プロジェクト: BobPyron/calibre
 def init_cache(self, library_path=None):
     from calibre.db.backend import DB
     from calibre.db.cache import Cache
     backend = DB(library_path or self.library_path)
     cache = Cache(backend)
     cache.init()
     return cache
コード例 #3
0
 def __init__(self, library_path, default_prefs=None, restore_all_prefs=False, progress_callback=lambda x, y:True):
     backend = DB(library_path, default_prefs=default_prefs, restore_all_prefs=restore_all_prefs, progress_callback=progress_callback)
     Cache.__init__(self, backend)
     for x in ('update_path', 'mark_as_dirty'):
         setattr(self, x, self.no_op)
         setattr(self, '_' + x, self.no_op)
     self.init()
コード例 #4
0
ファイル: restore.py プロジェクト: Hainish/calibre
 def __init__(self, library_path, default_prefs=None, restore_all_prefs=False, progress_callback=lambda x, y:True):
     backend = DB(library_path, default_prefs=default_prefs, restore_all_prefs=restore_all_prefs, progress_callback=progress_callback)
     Cache.__init__(self, backend)
     for x in ('update_path', 'mark_as_dirty'):
         setattr(self, x, self.no_op)
         setattr(self, '_' + x, self.no_op)
     self.init()
コード例 #5
0
ファイル: exim.py プロジェクト: onyx-Sean/calibre
def export(destdir, library_paths=None, dbmap=None, progress1=None, progress2=None, abort=None):
    from calibre.db.cache import Cache
    from calibre.db.backend import DB
    if library_paths is None:
        library_paths = all_known_libraries()
    dbmap = dbmap or {}
    dbmap = {os.path.normcase(os.path.abspath(k)):v for k, v in iteritems(dbmap)}
    exporter = Exporter(destdir)
    exporter.metadata['libraries'] = libraries = {}
    total = len(library_paths) + 1
    for i, (lpath, count) in enumerate(iteritems(library_paths)):
        if abort is not None and abort.is_set():
            return
        if progress1 is not None:
            progress1(lpath, i, total)
        key = os.path.normcase(os.path.abspath(lpath))
        db, closedb = dbmap.get(lpath), False
        if db is None:
            db = Cache(DB(lpath, load_user_formatter_functions=False))
            db.init()
            closedb = True
        else:
            db = db.new_api
        db.export_library(key, exporter, progress=progress2, abort=abort)
        if closedb:
            db.close()
        libraries[key] = count
    if progress1 is not None:
        progress1(_('Settings and plugins'), total-1, total)
    if abort is not None and abort.is_set():
        return
    exporter.export_dir(config_dir, 'config_dir')
    exporter.commit()
    if progress1 is not None:
        progress1(_('Completed'), total, total)
コード例 #6
0
ファイル: legacy.py プロジェクト: T30rGRB7/calibre-python3
    def __init__(self,
                 library_path,
                 default_prefs=None,
                 read_only=False,
                 is_second_db=False,
                 progress_callback=lambda x, y: True,
                 restore_all_prefs=False):

        self.is_second_db = is_second_db
        self.listeners = set()

        backend = self.backend = create_backend(
            library_path,
            default_prefs=default_prefs,
            read_only=read_only,
            restore_all_prefs=restore_all_prefs,
            progress_callback=progress_callback,
            load_user_formatter_functions=not is_second_db)
        cache = self.new_api = Cache(backend)
        cache.init()
        self.data = View(cache)
        self.id = self.data.index_to_id
        self.row = self.data.id_to_index
        for x in ('get_property', 'count', 'refresh_ids', 'set_marked_ids',
                  'multisort', 'search', 'search_getting_ids'):
            setattr(self, x, getattr(self.data, x))

        self.is_case_sensitive = getattr(backend, 'is_case_sensitive', False)
        self.custom_field_name = backend.custom_field_name

        self.last_update_check = self.last_modified()

        if not self.is_second_db:
            set_saved_searches(self, 'saved_searches')
コード例 #7
0
ファイル: legacy.py プロジェクト: kobolabs/calibre
    def __init__(self, library_path,
            default_prefs=None, read_only=False, is_second_db=False,
            progress_callback=lambda x, y:True, restore_all_prefs=False):

        self.is_second_db = is_second_db  # TODO: Use is_second_db
        self.listeners = set([])

        backend = self.backend = DB(library_path, default_prefs=default_prefs,
                     read_only=read_only, restore_all_prefs=restore_all_prefs,
                     progress_callback=progress_callback)
        cache = self.new_api = Cache(backend)
        cache.init()
        self.data = View(cache)

        self.get_property = self.data.get_property

        for prop in (
                'author_sort', 'authors', 'comment', 'comments',
                'publisher', 'rating', 'series', 'series_index', 'tags',
                'title', 'timestamp', 'uuid', 'pubdate', 'ondevice',
                'metadata_last_modified', 'languages',
                ):
            fm = {'comment':'comments', 'metadata_last_modified':
                  'last_modified', 'title_sort':'sort'}.get(prop, prop)
            setattr(self, prop, partial(self.get_property,
                    loc=self.FIELD_MAP[fm]))

        self.last_update_check = self.last_modified()
コード例 #8
0
ファイル: exim.py プロジェクト: Coi-l/calibre
def export(destdir, library_paths=None, dbmap=None, progress1=None, progress2=None, abort=None):
    from calibre.db.cache import Cache
    from calibre.db.backend import DB
    if library_paths is None:
        library_paths = all_known_libraries()
    dbmap = dbmap or {}
    dbmap = {os.path.normcase(os.path.abspath(k)):v for k, v in dbmap.iteritems()}
    exporter = Exporter(destdir)
    exporter.metadata['libraries'] = libraries = {}
    total = len(library_paths) + 1
    for i, (lpath, count) in enumerate(library_paths.iteritems()):
        if abort is not None and abort.is_set():
            return
        if progress1 is not None:
            progress1(lpath, i, total)
        key = os.path.normcase(os.path.abspath(lpath))
        db, closedb = dbmap.get(lpath), False
        if db is None:
            db = Cache(DB(lpath, load_user_formatter_functions=False))
            db.init()
            closedb = True
        else:
            db = db.new_api
        db.export_library(key, exporter, progress=progress2, abort=abort)
        if closedb:
            db.close()
        libraries[key] = count
    if progress1 is not None:
        progress1(_('Settings and plugins'), total-1, total)
    if abort is not None and abort.is_set():
        return
    exporter.export_dir(config_dir, 'config_dir')
    exporter.commit()
    if progress1 is not None:
        progress1(_('Completed'), total, total)
コード例 #9
0
ファイル: handler.py プロジェクト: KyoYang/calibre
def init_library(library_path):
    db = Cache(create_backend(library_path))
    db.init()
    return db
コード例 #10
0
ファイル: base.py プロジェクト: PERCE-NEIGE/Calibribook
 def create_db(self, library_path):
     from calibre.db.legacy import create_backend
     from calibre.db.cache import Cache
     d = os.path.dirname
     src = os.path.join(d(d(d(os.path.abspath(__file__)))), 'db', 'tests',
                        'metadata.db')
     dest = os.path.join(library_path, 'metadata.db')
     shutil.copy2(src, dest)
     db = Cache(create_backend(library_path))
     db.init()
     db.set_cover({
         1: I('lt.png', data=True),
         2: I('polish.png', data=True)
     })
     db.add_format(1, 'FMT1', BytesIO(b'book1fmt1'), run_hooks=False)
     db.add_format(1,
                   'EPUB',
                   open(P('quick_start/eng.epub'), 'rb'),
                   run_hooks=False)
     db.add_format(1, 'FMT2', BytesIO(b'book1fmt2'), run_hooks=False)
     db.add_format(2, 'FMT1', BytesIO(b'book2fmt1'), run_hooks=False)
     db.backend.conn.close()
     return dest
コード例 #11
0
def init_library(library_path, is_default_library):
    db = Cache(
        create_backend(library_path,
                       load_user_formatter_functions=is_default_library))
    db.init()
    return db
コード例 #12
0
ファイル: handler.py プロジェクト: kerasking/calibre
def init_library(library_path):
    db = Cache(create_backend(library_path))
    db.init()
    return db
コード例 #13
0
ファイル: base.py プロジェクト: KyoYang/calibre
 def create_db(self, library_path):
     from calibre.db.legacy import create_backend
     from calibre.db.cache import Cache
     d = os.path.dirname
     src = os.path.join(d(d(d(os.path.abspath(__file__)))), 'db', 'tests', 'metadata.db')
     dest = os.path.join(library_path, 'metadata.db')
     shutil.copy2(src, dest)
     db = Cache(create_backend(library_path))
     db.init()
     db.set_cover({1:I('lt.png', data=True), 2:I('polish.png', data=True)})
     db.add_format(1, 'FMT1', BytesIO(b'book1fmt1'), run_hooks=False)
     db.add_format(1, 'EPUB', open(P('quick_start/eng.epub'), 'rb'), run_hooks=False)
     db.add_format(1, 'FMT2', BytesIO(b'book1fmt2'), run_hooks=False)
     db.add_format(2, 'FMT1', BytesIO(b'book2fmt1'), run_hooks=False)
     db.backend.conn.close()
     return dest
コード例 #14
0
ファイル: library_broker.py プロジェクト: bwhitenb5e/calibre
def init_library(library_path, is_default_library):
    db = Cache(
        create_backend(
            library_path, load_user_formatter_functions=is_default_library))
    db.init()
    return db