API for kiwidude

This commit is contained in:
Kovid Goyal 2012-06-30 21:18:31 +05:30
parent 39e8b5305c
commit d70cb9f6e2

View File

@ -1203,7 +1203,8 @@ class LibraryDatabase2(LibraryDatabase, SchemaUpgrade, CustomColumns):
if m: if m:
return m['mtime'] return m['mtime']
def format_metadata(self, id_, fmt, allow_cache=True): def format_metadata(self, id_, fmt, allow_cache=True, update_db=False,
commit=False):
if not fmt: if not fmt:
return {} return {}
fmt = fmt.upper() fmt = fmt.upper()
@ -1218,6 +1219,12 @@ class LibraryDatabase2(LibraryDatabase, SchemaUpgrade, CustomColumns):
ans['size'] = stat.st_size ans['size'] = stat.st_size
ans['mtime'] = utcfromtimestamp(stat.st_mtime) ans['mtime'] = utcfromtimestamp(stat.st_mtime)
self.format_metadata_cache[id_][fmt] = ans self.format_metadata_cache[id_][fmt] = ans
if update_db:
self.conn.execute(
'UPDATE data SET uncompressed_size=? WHERE format=? AND'
' book=?', (stat.st_size, fmt, id_))
if commit:
self.conn.commit()
return ans return ans
def format_hash(self, id_, fmt): def format_hash(self, id_, fmt):
@ -2564,7 +2571,7 @@ class LibraryDatabase2(LibraryDatabase, SchemaUpgrade, CustomColumns):
return [] return []
return result return result
def rename_series(self, old_id, new_name): def rename_series(self, old_id, new_name, change_index=True):
new_name = new_name.strip() new_name = new_name.strip()
new_id = self.conn.get( new_id = self.conn.get(
'''SELECT id from series '''SELECT id from series
@ -2577,6 +2584,7 @@ class LibraryDatabase2(LibraryDatabase, SchemaUpgrade, CustomColumns):
# New series exists. Must update the link, then assign a # New series exists. Must update the link, then assign a
# new series index to each of the books. # new series index to each of the books.
if change_index:
# Get the list of books where we must update the series index # Get the list of books where we must update the series index
books = self.conn.get('''SELECT books.id books = self.conn.get('''SELECT books.id
FROM books, books_series_link as lt FROM books, books_series_link as lt
@ -2586,6 +2594,7 @@ class LibraryDatabase2(LibraryDatabase, SchemaUpgrade, CustomColumns):
self.conn.execute('''UPDATE books_series_link self.conn.execute('''UPDATE books_series_link
SET series=? SET series=?
WHERE series=?''',(new_id, old_id,)) WHERE series=?''',(new_id, old_id,))
if change_index:
# Now set the indices # Now set the indices
for (book_id,) in books: for (book_id,) in books:
# Get the next series index # Get the next series index
@ -3684,4 +3693,12 @@ books_series_link feeds
s = self.conn.get('''SELECT book FROM books_plugin_data WHERE name=?''', (name,)) s = self.conn.get('''SELECT book FROM books_plugin_data WHERE name=?''', (name,))
return [x[0] for x in s] return [x[0] for x in s]
def get_usage_count_by_id(self, field):
fm = self.field_metadata[field]
if not fm.get('link_column', None):
raise ValueError('%s is not an is_multiple field')
return self.conn.get(
'SELECT {0}, count(*) FROM books_{1}_link GROUP BY {0}'.format(
fm['link_column'], fm['table']))