mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
1)Don't try to convert the database to a LibraryDatabase instance in metadata.py
2) Change formatter functions to use the new_api where possible. Also fix a bug where the wrong exception was raised attempting to get a database object from the weak reference. These were tested using the command line content server.
This commit is contained in:
parent
3bc202ba7e
commit
df10de2a0b
@ -560,12 +560,6 @@ def iternode_descendants(node):
|
|||||||
|
|
||||||
|
|
||||||
def fillout_tree(root, items, node_id_map, category_nodes, category_data, field_metadata, opts, book_rating_map, db):
|
def fillout_tree(root, items, node_id_map, category_nodes, category_data, field_metadata, opts, book_rating_map, db):
|
||||||
# Convert the DB to an old DB if needed, which it seems to be
|
|
||||||
wr = db.new_api.library_database_instance
|
|
||||||
if wr is not None:
|
|
||||||
db = wr()
|
|
||||||
else: # This shouldn't happen, but
|
|
||||||
db = None
|
|
||||||
eval_formatter = EvalFormatter()
|
eval_formatter = EvalFormatter()
|
||||||
tag_map, hierarchical_tags, node_to_tag_map = {}, set(), {}
|
tag_map, hierarchical_tags, node_to_tag_map = {}, set(), {}
|
||||||
first, later, collapse_nodes, intermediate_nodes, hierarchical_items = [], [], [], {}, set()
|
first, later, collapse_nodes, intermediate_nodes, hierarchical_items = [], [], [], {}, set()
|
||||||
|
@ -214,7 +214,7 @@ def get_database(mi, name):
|
|||||||
wr = getattr(cache, 'library_database_instance', None)
|
wr = getattr(cache, 'library_database_instance', None)
|
||||||
if wr is None:
|
if wr is None:
|
||||||
if name is not None:
|
if name is not None:
|
||||||
only_in_gui_error()
|
only_in_gui_error(name)
|
||||||
return None
|
return None
|
||||||
db = wr()
|
db = wr()
|
||||||
if db is None:
|
if db is None:
|
||||||
@ -2347,7 +2347,8 @@ r'''
|
|||||||
contain this book.[/] This function works only in the GUI. If you want to use these
|
contain this book.[/] This function works only in the GUI. If you want to use these
|
||||||
values in save-to-disk or send-to-device templates then you must make a custom
|
values in save-to-disk or send-to-device templates then you must make a custom
|
||||||
"Column built from other columns", use the function in that column's template,
|
"Column built from other columns", use the function in that column's template,
|
||||||
and use that column's value in your save/send templates.
|
and use that column's value in your save/send templates. This function works
|
||||||
|
only in the GUI.
|
||||||
''')
|
''')
|
||||||
|
|
||||||
def evaluate(self, formatter, kwargs, mi, locals_):
|
def evaluate(self, formatter, kwargs, mi, locals_):
|
||||||
@ -2443,6 +2444,7 @@ program:
|
|||||||
ans
|
ans
|
||||||
[/CODE]
|
[/CODE]
|
||||||
[/LIST]
|
[/LIST]
|
||||||
|
This function works only in the GUI.
|
||||||
''')
|
''')
|
||||||
|
|
||||||
def evaluate(self, formatter, kwargs, mi, locals, field_name, field_value):
|
def evaluate(self, formatter, kwargs, mi, locals, field_name, field_value):
|
||||||
@ -2863,6 +2865,7 @@ Using a stored template instead of putting the template into the search
|
|||||||
eliminates problems caused by the requirement to escape quotes in search
|
eliminates problems caused by the requirement to escape quotes in search
|
||||||
expressions.
|
expressions.
|
||||||
[/LIST]
|
[/LIST]
|
||||||
|
This function can be used only in the GUI.
|
||||||
''')
|
''')
|
||||||
|
|
||||||
def evaluate(self, formatter, kwargs, mi, locals, query, use_vl):
|
def evaluate(self, formatter, kwargs, mi, locals, query, use_vl):
|
||||||
@ -2872,8 +2875,13 @@ expressions.
|
|||||||
raise ValueError(_('The book_count() function cannot be used in a composite column'))
|
raise ValueError(_('The book_count() function cannot be used in a composite column'))
|
||||||
db = self.get_database(mi, formatter=formatter)
|
db = self.get_database(mi, formatter=formatter)
|
||||||
try:
|
try:
|
||||||
ids = db.search_getting_ids(query, None, use_virtual_library=use_vl != '0')
|
if use_vl == '0':
|
||||||
return len(ids)
|
# use the new_api search that doesn't use virtual libraries to let
|
||||||
|
# the function work in content server icon rules.
|
||||||
|
ids = db.new_api.search(query, None)
|
||||||
|
else:
|
||||||
|
ids = db.search_getting_ids(query, None, use_virtual_library=True)
|
||||||
|
return str(len(ids))
|
||||||
except Exception:
|
except Exception:
|
||||||
traceback.print_exc()
|
traceback.print_exc()
|
||||||
|
|
||||||
@ -2891,8 +2899,8 @@ then virtual libraries are ignored. This function and its companion
|
|||||||
``book_count()`` are particularly useful in template searches, supporting
|
``book_count()`` are particularly useful in template searches, supporting
|
||||||
searches that combine information from many books such as looking for series
|
searches that combine information from many books such as looking for series
|
||||||
with only one book. It cannot be used in composite columns unless the tweak
|
with only one book. It cannot be used in composite columns unless the tweak
|
||||||
``allow_template_database_functions_in_composites`` is set to True. It can be
|
``allow_template_database_functions_in_composites`` is set to True. This function
|
||||||
used only in the GUI.
|
can be used only in the GUI.
|
||||||
''')
|
''')
|
||||||
|
|
||||||
def evaluate(self, formatter, kwargs, mi, locals, column, query, sep, use_vl):
|
def evaluate(self, formatter, kwargs, mi, locals, column, query, sep, use_vl):
|
||||||
@ -2904,7 +2912,10 @@ used only in the GUI.
|
|||||||
if column not in db.field_metadata:
|
if column not in db.field_metadata:
|
||||||
raise ValueError(_("The column {} doesn't exist").format(column))
|
raise ValueError(_("The column {} doesn't exist").format(column))
|
||||||
try:
|
try:
|
||||||
ids = db.search_getting_ids(query, None, use_virtual_library=use_vl != '0')
|
if use_vl == '0':
|
||||||
|
ids = db.new_api.search(query, None)
|
||||||
|
else:
|
||||||
|
ids = db.search_getting_ids(query, None, use_virtual_library=True)
|
||||||
s = set()
|
s = set()
|
||||||
for id_ in ids:
|
for id_ in ids:
|
||||||
f = db.new_api.get_proxy_metadata(id_).get(column, None)
|
f = db.new_api.get_proxy_metadata(id_).get(column, None)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user