mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
books_plugin_data API.
This commit is contained in:
parent
f69f6a3dae
commit
e1ff235aed
@ -6,7 +6,7 @@ __docformat__ = 'restructuredtext en'
|
|||||||
'''
|
'''
|
||||||
The database used to store ebook metadata
|
The database used to store ebook metadata
|
||||||
'''
|
'''
|
||||||
import os, sys, shutil, cStringIO, glob, time, functools, traceback, re
|
import os, sys, shutil, cStringIO, glob, time, functools, traceback, re, json
|
||||||
from itertools import repeat
|
from itertools import repeat
|
||||||
from math import ceil
|
from math import ceil
|
||||||
from Queue import Queue
|
from Queue import Queue
|
||||||
@ -32,7 +32,7 @@ from calibre.customize.ui import run_plugins_on_import
|
|||||||
from calibre import isbytestring
|
from calibre import isbytestring
|
||||||
from calibre.utils.filenames import ascii_filename
|
from calibre.utils.filenames import ascii_filename
|
||||||
from calibre.utils.date import utcnow, now as nowf, utcfromtimestamp
|
from calibre.utils.date import utcnow, now as nowf, utcfromtimestamp
|
||||||
from calibre.utils.config import prefs, tweaks
|
from calibre.utils.config import prefs, tweaks, from_json, to_json
|
||||||
from calibre.utils.icu import sort_key
|
from calibre.utils.icu import sort_key
|
||||||
from calibre.utils.search_query_parser import saved_searches, set_saved_searches
|
from calibre.utils.search_query_parser import saved_searches, set_saved_searches
|
||||||
from calibre.ebooks import BOOK_EXTENSIONS, check_ebook_format
|
from calibre.ebooks import BOOK_EXTENSIONS, check_ebook_format
|
||||||
@ -2700,6 +2700,34 @@ books_series_link feeds
|
|||||||
|
|
||||||
return duplicates
|
return duplicates
|
||||||
|
|
||||||
|
def add_custom_book_data(self, book_id, name, val):
|
||||||
|
x = self.conn.get('SELECT id FROM books WHERE ID=?', (book_id,), all=False)
|
||||||
|
if x is None:
|
||||||
|
raise ValueError('add_custom_book_data: no such book_id %d'%book_id)
|
||||||
|
# Do the json encode first, in case it throws an exception
|
||||||
|
s = json.dumps(val, default=to_json)
|
||||||
|
self.conn.execute('DELETE FROM books_plugin_data WHERE book=? AND name=?',
|
||||||
|
(book_id, name))
|
||||||
|
self.conn.execute('''INSERT INTO books_plugin_data(book, name, val)
|
||||||
|
VALUES(?, ?, ?)''', (book_id, name, s))
|
||||||
|
self.commit()
|
||||||
|
|
||||||
|
def get_custom_book_data(self, book_id, name, default=None):
|
||||||
|
try:
|
||||||
|
s = self.conn.get('''select val FROM books_plugin_data
|
||||||
|
WHERE book=? AND name=?''', (book_id, name), all=False)
|
||||||
|
if s is None:
|
||||||
|
return default
|
||||||
|
return json.loads(s, object_hook=from_json)
|
||||||
|
except:
|
||||||
|
pass
|
||||||
|
return default
|
||||||
|
|
||||||
|
def delete_custom_book_data(self, book_id, name):
|
||||||
|
self.conn.execute('DELETE FROM books_plugin_data WHERE book=? AND name=?',
|
||||||
|
(book_id, name))
|
||||||
|
self.commit()
|
||||||
|
|
||||||
def get_custom_recipes(self):
|
def get_custom_recipes(self):
|
||||||
for id, title, script in self.conn.get('SELECT id,title,script FROM feeds'):
|
for id, title, script in self.conn.get('SELECT id,title,script FROM feeds'):
|
||||||
yield id, title, script
|
yield id, title, script
|
||||||
|
@ -441,3 +441,31 @@ class SchemaUpgrade(object):
|
|||||||
WHERE id=NEW.id AND OLD.title <> NEW.title;
|
WHERE id=NEW.id AND OLD.title <> NEW.title;
|
||||||
END;
|
END;
|
||||||
''')
|
''')
|
||||||
|
|
||||||
|
def upgrade_version_17(self):
|
||||||
|
'custom book data table (for plugins)'
|
||||||
|
script = '''
|
||||||
|
DROP TABLE IF EXISTS books_plugin_data;
|
||||||
|
CREATE TABLE books_plugin_data(id INTEGER PRIMARY KEY,
|
||||||
|
book INTEGER NON NULL,
|
||||||
|
name TEXT NON NULL,
|
||||||
|
val TEXT NON NULL,
|
||||||
|
UNIQUE(book,name));
|
||||||
|
DROP TRIGGER IF EXISTS books_delete_trg;
|
||||||
|
CREATE TRIGGER books_delete_trg
|
||||||
|
AFTER DELETE ON books
|
||||||
|
BEGIN
|
||||||
|
DELETE FROM books_authors_link WHERE book=OLD.id;
|
||||||
|
DELETE FROM books_publishers_link WHERE book=OLD.id;
|
||||||
|
DELETE FROM books_ratings_link WHERE book=OLD.id;
|
||||||
|
DELETE FROM books_series_link WHERE book=OLD.id;
|
||||||
|
DELETE FROM books_tags_link WHERE book=OLD.id;
|
||||||
|
DELETE FROM data WHERE book=OLD.id;
|
||||||
|
DELETE FROM comments WHERE book=OLD.id;
|
||||||
|
DELETE FROM conversion_options WHERE book=OLD.id;
|
||||||
|
DELETE FROM books_plugin_data WHERE book=OLD.id;
|
||||||
|
END;
|
||||||
|
'''
|
||||||
|
self.conn.executescript(script)
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user