mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-08 10:44:09 -04:00
...
This commit is contained in:
parent
2ef59d81b2
commit
917c2ec205
@ -15,7 +15,7 @@ vipy.session.initialize(project_name='calibre', src_dir=src_dir,
|
|||||||
project_dir=project_dir, base_dir=base_dir)
|
project_dir=project_dir, base_dir=base_dir)
|
||||||
|
|
||||||
def recipe_title_callback(raw):
|
def recipe_title_callback(raw):
|
||||||
return eval(raw.decode('utf-8'))
|
return eval(raw.decode('utf-8')).replace(' ', '_')
|
||||||
|
|
||||||
vipy.session.add_content_browser('.r', ',r', 'Recipe',
|
vipy.session.add_content_browser('.r', ',r', 'Recipe',
|
||||||
vipy.session.glob_based_iterator(os.path.join(project_dir, 'recipes', '*.recipe')),
|
vipy.session.glob_based_iterator(os.path.join(project_dir, 'recipes', '*.recipe')),
|
||||||
|
@ -47,9 +47,6 @@ def check_for_python_errors(code_string, filename):
|
|||||||
# Okay, it's syntactically valid. Now check it.
|
# Okay, it's syntactically valid. Now check it.
|
||||||
w = checker.Checker(tree, filename)
|
w = checker.Checker(tree, filename)
|
||||||
w.messages.sort(lambda a, b: cmp(a.lineno, b.lineno))
|
w.messages.sort(lambda a, b: cmp(a.lineno, b.lineno))
|
||||||
for warning in w.messages:
|
|
||||||
print warning
|
|
||||||
print (dir(warning))
|
|
||||||
return [Message(x.filename, x.lineno, x.message%x.message_args) for x in
|
return [Message(x.filename, x.lineno, x.message%x.message_args) for x in
|
||||||
w.messages]
|
w.messages]
|
||||||
|
|
||||||
|
@ -62,6 +62,10 @@ class Cache(object):
|
|||||||
lock = self.read_lock if ira else self.write_lock
|
lock = self.read_lock if ira else self.write_lock
|
||||||
setattr(self, name, wrap_simple(lock, func))
|
setattr(self, name, wrap_simple(lock, func))
|
||||||
|
|
||||||
|
@property
|
||||||
|
def field_metadata(self):
|
||||||
|
return self.backend.field_metadata
|
||||||
|
|
||||||
def _format_abspath(self, book_id, fmt):
|
def _format_abspath(self, book_id, fmt):
|
||||||
'''
|
'''
|
||||||
Return absolute path to the ebook file of format `format`
|
Return absolute path to the ebook file of format `format`
|
||||||
@ -335,6 +339,43 @@ class Cache(object):
|
|||||||
return self.backend.cover(path, as_file=as_file, as_image=as_image,
|
return self.backend.cover(path, as_file=as_file, as_image=as_image,
|
||||||
as_path=as_path)
|
as_path=as_path)
|
||||||
|
|
||||||
|
@api
|
||||||
|
def sanitize_sort_field_name(self, field):
|
||||||
|
field = self.field_metadata.search_term_to_field_key(field.lower().strip())
|
||||||
|
# translate some fields to their hidden equivalent
|
||||||
|
field = {'title': 'sort', 'authors':'author_sort'}.get(field, field)
|
||||||
|
return field
|
||||||
|
|
||||||
|
@read_api
|
||||||
|
def sort(self, field, ascending, subsort=False):
|
||||||
|
self._multisort([(field, ascending)])
|
||||||
|
|
||||||
|
@read_api
|
||||||
|
def multisort(self, fields=[], subsort=False):
|
||||||
|
fields = [(self.sanitize_sort_field_name(x), bool(y)) for x, y in fields]
|
||||||
|
keys = self.field_metadata.sortable_field_keys()
|
||||||
|
fields = [x for x in fields if x[0] in keys]
|
||||||
|
if subsort and 'sort' not in [x[0] for x in fields]:
|
||||||
|
fields += [('sort', True)]
|
||||||
|
if not fields:
|
||||||
|
fields = [('timestamp', False)]
|
||||||
|
|
||||||
|
all_book_ids = frozenset(self._all_book_ids())
|
||||||
|
get_metadata = partial(self._get_metadata, get_user_categories=False)
|
||||||
|
|
||||||
|
book_lists = tuple(self.field[field].sort_books(get_metadata, all_book_ids,
|
||||||
|
ascending=ascending) for field, ascending in fields)
|
||||||
|
if len(book_lists) == 1:
|
||||||
|
return book_lists[0]
|
||||||
|
else:
|
||||||
|
book_maps = tuple({id_:idx for idx, id_ in enumerate(x)} for x in
|
||||||
|
book_lists)
|
||||||
|
|
||||||
|
def sort_key(book_id):
|
||||||
|
return tuple(d.get(book_id, -1) for d in book_maps)
|
||||||
|
|
||||||
|
return sorted(all_book_ids, key=sort_key)
|
||||||
|
|
||||||
# }}}
|
# }}}
|
||||||
|
|
||||||
# Testing {{{
|
# Testing {{{
|
||||||
|
Loading…
x
Reference in New Issue
Block a user