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)
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)
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
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
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
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
def init_library(library_path): db = Cache(create_backend(library_path)) db.init() return db
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
def init_library(library_path): db = Cache(create_backend(library_path)) db.init() return db
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