max_size()

This commit is contained in:
Kovid Goyal 2013-07-17 18:11:06 +05:30
parent a7ca60b0e9
commit 0ab4ebbfbd
3 changed files with 6 additions and 3 deletions

View File

@ -680,12 +680,12 @@ class LibraryDatabase(object):
MT = lambda func: types.MethodType(func, None, LibraryDatabase)
# Legacy getter API {{{
for prop in ('author_sort', 'authors', 'comment', 'comments', 'publisher',
for prop in ('author_sort', 'authors', 'comment', 'comments', 'publisher', 'max_size',
'rating', 'series', 'series_index', 'tags', 'title', 'title_sort',
'timestamp', 'uuid', 'pubdate', 'ondevice', 'metadata_last_modified', 'languages',):
def getter(prop):
fm = {'comment':'comments', 'metadata_last_modified':
'last_modified', 'title_sort':'sort'}.get(prop, prop)
'last_modified', 'title_sort':'sort', 'max_size':'size'}.get(prop, prop)
def func(self, index, index_is_id=False):
return self.get_property(index, index_is_id=index_is_id, loc=self.FIELD_MAP[fm])
return func

View File

@ -15,6 +15,7 @@ from operator import itemgetter
from calibre.db.tests.base import BaseTest
# Utils {{{
class ET(object):
def __init__(self, func_name, args, kwargs={}, old=None, legacy=None):
@ -58,6 +59,7 @@ def run_funcs(self, db, ndb, funcs):
meth = meth[1:]
res1, res2 = fmt(getattr(db, meth)(*args)), fmt(getattr(ndb, meth)(*args))
self.assertEqual(res1, res2, 'The method: %s() returned different results for argument %s' % (meth, args))
# }}}
class LegacyTest(BaseTest):
@ -179,6 +181,7 @@ class LegacyTest(BaseTest):
'sizeof_format':[(1, 'FMT1', True), (2, 'FMT1', True), (0, 'xxxxxx')],
'@format_files':[(0,),(1,),(2,)],
'formats':[(0,),(1,),(2,)],
'max_size':[(0,),(1,),(2,)],
'format_hash':[(1, 'FMT1'),(1, 'FMT2'), (2, 'FMT1')],
'author_sort_from_authors': [(['Author One', 'Author Two', 'Unknown'],)],
'has_book':[(Metadata('title one'),), (Metadata('xxxx1111'),)],

View File

@ -959,7 +959,7 @@ ALTER TABLE books ADD COLUMN isbn TEXT DEFAULT "" COLLATE NOCASE;
def max_size(self, index, index_is_id=False):
if index_is_id:
return self.conn.get('SELECT size FROM meta WHERE id=?', (index,), all=False)
return self.data[index][6]
return self.data[index][4]
def cover(self, index, index_is_id=False):
'''Cover as a data string or None'''