本文整理汇总了Python中calibre.db.view.View.iterall方法的典型用法代码示例。如果您正苦于以下问题:Python View.iterall方法的具体用法?Python View.iterall怎么用?Python View.iterall使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类calibre.db.view.View
的用法示例。
在下文中一共展示了View.iterall方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: LibraryDatabase
# 需要导入模块: from calibre.db.view import View [as 别名]
# 或者: from calibre.db.view.View import iterall [as 别名]
#.........这里部分代码省略.........
return self.data.cache.formatter_template_cache
def initialize_template_cache(self):
self.data.cache.initialize_template_cache()
def all_ids(self):
for book_id in self.data.cache.all_book_ids():
yield book_id
def refresh(self, field=None, ascending=True):
self.data.cache.refresh()
self.data.refresh(field=field, ascending=ascending)
def add_listener(self, listener):
'''
Add a listener. Will be called on change events with two arguments.
Event name and list of affected ids.
'''
self.listeners.add(listener)
def notify(self, event, ids=[]):
'Notify all listeners'
for listener in self.listeners:
try:
listener(event, ids)
except:
traceback.print_exc()
continue
# }}}
def path(self, index, index_is_id=False):
'Return the relative path to the directory containing this books files as a unicode string.'
book_id = index if index_is_id else self.data.index_to_id(index)
return self.new_api.field_for('path', book_id).replace('/', os.sep)
def abspath(self, index, index_is_id=False, create_dirs=True):
'Return the absolute path to the directory containing this books files as a unicode string.'
path = os.path.join(self.library_path, self.path(index, index_is_id=index_is_id))
if create_dirs and not os.path.exists(path):
os.makedirs(path)
return path
# Adding books {{{
def create_book_entry(self, mi, cover=None, add_duplicates=True, force_id=None):
return self.new_api.create_book_entry(mi, cover=cover, add_duplicates=add_duplicates, force_id=force_id)
def add_books(self, paths, formats, metadata, add_duplicates=True, return_ids=False):
books = [(mi, {fmt:path}) for mi, path, fmt in zip(metadata, paths, formats)]
book_ids, duplicates = self.new_api.add_books(books, add_duplicates=add_duplicates, dbapi=self)
if duplicates:
paths, formats, metadata = [], [], []
for mi, format_map in duplicates:
metadata.append(mi)
for fmt, path in format_map.iteritems():
formats.append(fmt)
paths.append(path)
duplicates = (paths, formats, metadata)
ids = book_ids if return_ids else len(book_ids)
return duplicates or None, ids
def import_book(self, mi, formats, notify=True, import_hooks=True, apply_import_tags=True, preserve_uuid=False):
format_map = {}
for path in formats:
ext = os.path.splitext(path)[1][1:].upper()
if ext == 'OPF':
continue
format_map[ext] = path
book_ids, duplicates = self.new_api.add_books(
[(mi, format_map)], add_duplicates=True, apply_import_tags=apply_import_tags, preserve_uuid=preserve_uuid, dbapi=self, run_hooks=import_hooks)
if notify:
self.notify('add', book_ids)
return book_ids[0]
def find_books_in_directory(self, dirpath, single_book_per_directory):
return find_books_in_directory(dirpath, single_book_per_directory)
def import_book_directory_multiple(self, dirpath, callback=None,
added_ids=None):
return import_book_directory_multiple(self, dirpath, callback=callback, added_ids=added_ids)
def import_book_directory(self, dirpath, callback=None, added_ids=None):
return import_book_directory(self, dirpath, callback=callback, added_ids=added_ids)
def recursive_import(self, root, single_book_per_directory=True,
callback=None, added_ids=None):
return recursive_import(self, root, single_book_per_directory=single_book_per_directory, callback=callback, added_ids=added_ids)
# }}}
# Private interface {{{
def __iter__(self):
for row in self.data.iterall():
yield row
def _get_next_series_num_for_list(self, series_indices):
return _get_next_series_num_for_list(series_indices)
def _get_series_values(self, val):
return _get_series_values(val)
示例2: LibraryDatabase
# 需要导入模块: from calibre.db.view import View [as 别名]
# 或者: from calibre.db.view.View import iterall [as 别名]
#.........这里部分代码省略.........
if data['datatype'] == 'enumeration' and (
val and val not in data['display']['enum_values']):
return set()
with self.new_api.write_lock:
if append and data['is_multiple']:
current = self.new_api._field_for(field, book_id)
existing = {icu_lower(x) for x in current}
val = current + tuple(x for x in self.new_api.fields[field].writer.adapter(val) if icu_lower(x) not in existing)
affected_books = self.new_api._set_field(field, {book_id:val}, allow_case_change=allow_case_change)
else:
affected_books = self.new_api._set_field(field, {book_id:val}, allow_case_change=allow_case_change)
if data['datatype'] == 'series':
s, sidx = get_series_values(val)
if sidx is None:
extra = 1.0 if extra is None else extra
self.new_api._set_field(field + '_index', {book_id:extra})
if notify and affected_books:
self.notify('metadata', list(affected_books))
return affected_books
def set_custom_bulk(self, ids, val, label=None, num=None,
append=False, notify=True, extras=None):
if extras is not None and len(extras) != len(ids):
raise ValueError('Length of ids and extras is not the same')
field = self.custom_field_name(label, num)
data = self.backend.custom_field_metadata(label, num)
if data['datatype'] == 'composite':
return set()
if data['datatype'] == 'enumeration' and (
val and val not in data['display']['enum_values']):
return
if not data['editable']:
raise ValueError('Column %r is not editable'%data['label'])
if append:
for book_id in ids:
self.set_custom(book_id, val, label=label, num=num, append=True, notify=False)
else:
with self.new_api.write_lock:
self.new_api._set_field(field, {book_id:val for book_id in ids}, allow_case_change=False)
if extras is not None:
self.new_api._set_field(field + '_index', {book_id:val for book_id, val in zip(ids, extras)})
if notify:
self.notify('metadata', list(ids))
def delete_custom_column(self, label=None, num=None):
self.new_api.delete_custom_column(label, num)
def create_custom_column(self, label, name, datatype, is_multiple, editable=True, display={}):
self.new_api.create_custom_column(label, name, datatype, is_multiple, editable=editable, display=display)
def set_custom_column_metadata(self, num, name=None, label=None, is_editable=None, display=None,
notify=True, update_last_modified=False):
changed = self.new_api.set_custom_column_metadata(num, name=name, label=label, is_editable=is_editable,
display=display, update_last_modified=update_last_modified)
if changed and notify:
self.notify('metadata', [])
def remove_cover(self, book_id, notify=True, commit=True):
self.new_api.set_cover({book_id:None})
if notify:
self.notify('cover', [book_id])
def set_cover(self, book_id, data, notify=True, commit=True):
self.new_api.set_cover({book_id:data})
if notify:
self.notify('cover', [book_id])
def original_fmt(self, book_id, fmt):
nfmt = ('ORIGINAL_%s'%fmt).upper()
return nfmt if self.new_api.has_format(book_id, nfmt) else fmt
def save_original_format(self, book_id, fmt, notify=True):
ret = self.new_api.save_original_format(book_id, fmt)
if ret and notify:
self.notify('metadata', [book_id])
return ret
def restore_original_format(self, book_id, original_fmt, notify=True):
ret = self.new_api.restore_original_format(book_id, original_fmt)
if ret and notify:
self.notify('metadata', [book_id])
return ret
def remove_format(self, index, fmt, index_is_id=False, notify=True, commit=True, db_only=False):
book_id = index if index_is_id else self.id(index)
self.new_api.remove_formats({book_id:(fmt,)}, db_only=db_only)
if notify:
self.notify('metadata', [book_id])
# Private interface {{{
def __iter__(self):
for row in self.data.iterall():
yield row
def _get_next_series_num_for_list(self, series_indices):
return _get_next_series_num_for_list(series_indices)
def _get_series_values(self, val):
return _get_series_values(val)
示例3: LibraryDatabase
# 需要导入模块: from calibre.db.view import View [as 别名]
# 或者: from calibre.db.view.View import iterall [as 别名]
#.........这里部分代码省略.........
self.backend
) = self.new_api = self.field_metadata = self.prefs = self.listeners = self.refresh_ondevice = None
# Library wide properties {{{
@property
def field_metadata(self):
return self.backend.field_metadata
@property
def user_version(self):
return self.backend.user_version
@property
def library_id(self):
return self.backend.library_id
@property
def library_path(self):
return self.backend.library_path
@property
def dbpath(self):
return self.backend.dbpath
def last_modified(self):
return self.backend.last_modified()
def check_if_modified(self):
if self.last_modified() > self.last_update_check:
self.refresh()
self.last_update_check = utcnow()
@property
def custom_column_num_map(self):
return self.backend.custom_column_num_map
@property
def custom_column_label_map(self):
return self.backend.custom_column_label_map
@property
def FIELD_MAP(self):
return self.backend.FIELD_MAP
@property
def formatter_template_cache(self):
return self.data.cache.formatter_template_cache
def initialize_template_cache(self):
self.data.cache.initialize_template_cache()
def all_ids(self):
for book_id in self.data.cache.all_book_ids():
yield book_id
def refresh(self, field=None, ascending=True):
self.data.cache.refresh()
self.data.refresh(field=field, ascending=ascending)
def add_listener(self, listener):
"""
Add a listener. Will be called on change events with two arguments.
Event name and list of affected ids.
"""
self.listeners.add(listener)
def notify(self, event, ids=[]):
"Notify all listeners"
for listener in self.listeners:
try:
listener(event, ids)
except:
traceback.print_exc()
continue
# }}}
def path(self, index, index_is_id=False):
"Return the relative path to the directory containing this books files as a unicode string."
book_id = index if index_is_id else self.data.index_to_id(index)
return self.data.cache.field_for("path", book_id).replace("/", os.sep)
def abspath(self, index, index_is_id=False, create_dirs=True):
"Return the absolute path to the directory containing this books files as a unicode string."
path = os.path.join(self.library_path, self.path(index, index_is_id=index_is_id))
if create_dirs and not os.path.exists(path):
os.makedirs(path)
return path
# Private interface {{{
def __iter__(self):
for row in self.data.iterall():
yield row
def _get_next_series_num_for_list(self, series_indices):
return _get_next_series_num_for_list(series_indices)
def _get_series_values(self, val):
return _get_series_values(val)