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()
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__(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 = 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.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')
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()
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 create_backend( library_path, default_prefs=None, read_only=False, progress_callback=lambda x, y:True, restore_all_prefs=False, load_user_formatter_functions=True): return DB(library_path, default_prefs=default_prefs, read_only=read_only, restore_all_prefs=restore_all_prefs, progress_callback=progress_callback, load_user_formatter_functions=load_user_formatter_functions)
def create_backend(library_path, default_prefs=None, read_only=False, progress_callback=lambda x, y: True, restore_all_prefs=False): return DB(library_path, default_prefs=default_prefs, read_only=read_only, restore_all_prefs=restore_all_prefs, progress_callback=progress_callback)