mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Changes for content server implementation
This commit is contained in:
commit
cdd1f4ff49
@ -753,7 +753,8 @@ plugins += [
|
|||||||
EEEREADER,
|
EEEREADER,
|
||||||
NEXTBOOK,
|
NEXTBOOK,
|
||||||
ITUNES,
|
ITUNES,
|
||||||
]
|
]
|
||||||
|
|
||||||
plugins += [x for x in list(locals().values()) if isinstance(x, type) and \
|
plugins += [x for x in list(locals().values()) if isinstance(x, type) and \
|
||||||
x.__name__.endswith('MetadataReader')]
|
x.__name__.endswith('MetadataReader')]
|
||||||
plugins += [x for x in list(locals().values()) if isinstance(x, type) and \
|
plugins += [x for x in list(locals().values()) if isinstance(x, type) and \
|
||||||
|
@ -29,8 +29,7 @@ from calibre.ebooks.metadata.meta import set_metadata
|
|||||||
from calibre.constants import DEBUG
|
from calibre.constants import DEBUG
|
||||||
from calibre.utils.config import prefs, tweaks
|
from calibre.utils.config import prefs, tweaks
|
||||||
from calibre.utils.magick.draw import thumbnail
|
from calibre.utils.magick.draw import thumbnail
|
||||||
from calibre.library.save_to_disk import plugboard_any_device_value, \
|
from calibre.library.save_to_disk import find_plugboard
|
||||||
plugboard_any_format_value
|
|
||||||
# }}}
|
# }}}
|
||||||
|
|
||||||
class DeviceJob(BaseJob): # {{{
|
class DeviceJob(BaseJob): # {{{
|
||||||
@ -93,23 +92,6 @@ class DeviceJob(BaseJob): # {{{
|
|||||||
|
|
||||||
# }}}
|
# }}}
|
||||||
|
|
||||||
def find_plugboard(device_name, format, plugboards):
|
|
||||||
cpb = None
|
|
||||||
if format in plugboards:
|
|
||||||
cpb = plugboards[format]
|
|
||||||
elif plugboard_any_format_value in plugboards:
|
|
||||||
cpb = plugboards[plugboard_any_format_value]
|
|
||||||
if cpb is not None:
|
|
||||||
if device_name in cpb:
|
|
||||||
cpb = cpb[device_name]
|
|
||||||
elif plugboard_any_device_value in cpb:
|
|
||||||
cpb = cpb[plugboard_any_device_value]
|
|
||||||
else:
|
|
||||||
cpb = None
|
|
||||||
if DEBUG:
|
|
||||||
prints('Device using plugboard', format, device_name, cpb)
|
|
||||||
return cpb
|
|
||||||
|
|
||||||
def device_name_for_plugboards(device_class):
|
def device_name_for_plugboards(device_class):
|
||||||
if hasattr(device_class, 'DEVICE_PLUGBOARD_NAME'):
|
if hasattr(device_class, 'DEVICE_PLUGBOARD_NAME'):
|
||||||
return device_class.DEVICE_PLUGBOARD_NAME
|
return device_class.DEVICE_PLUGBOARD_NAME
|
||||||
@ -892,7 +874,7 @@ class DeviceMixin(object): # {{{
|
|||||||
sub_dest_parts.append('')
|
sub_dest_parts.append('')
|
||||||
to = sub_dest_parts[0]
|
to = sub_dest_parts[0]
|
||||||
fmts = sub_dest_parts[1]
|
fmts = sub_dest_parts[1]
|
||||||
subject = ';'.join(sub_dest_parts[2:])
|
subject = ';'.join(sub_dest_parts[2:])
|
||||||
fmts = [x.strip().lower() for x in fmts.split(',')]
|
fmts = [x.strip().lower() for x in fmts.split(',')]
|
||||||
self.send_by_mail(to, fmts, delete, subject=subject)
|
self.send_by_mail(to, fmts, delete, subject=subject)
|
||||||
|
|
||||||
|
@ -15,6 +15,7 @@ from calibre.gui2.preferences.plugboard_ui import Ui_Form
|
|||||||
from calibre.customize.ui import metadata_writers, device_plugins
|
from calibre.customize.ui import metadata_writers, device_plugins
|
||||||
from calibre.library.save_to_disk import plugboard_any_format_value, \
|
from calibre.library.save_to_disk import plugboard_any_format_value, \
|
||||||
plugboard_any_device_value, plugboard_save_to_disk_value
|
plugboard_any_device_value, plugboard_save_to_disk_value
|
||||||
|
from calibre.library.server.content import plugboard_content_server_value
|
||||||
from calibre.utils.formatter import validation_formatter
|
from calibre.utils.formatter import validation_formatter
|
||||||
|
|
||||||
|
|
||||||
@ -74,7 +75,8 @@ class ConfigWidget(ConfigWidgetBase, Ui_Form):
|
|||||||
self.devices.append(n)
|
self.devices.append(n)
|
||||||
self.devices.sort(cmp=lambda x, y: cmp(x.lower(), y.lower()))
|
self.devices.sort(cmp=lambda x, y: cmp(x.lower(), y.lower()))
|
||||||
self.devices.insert(1, plugboard_save_to_disk_value)
|
self.devices.insert(1, plugboard_save_to_disk_value)
|
||||||
self.devices.insert(2, plugboard_any_device_value)
|
self.devices.insert(1, plugboard_content_server_value)
|
||||||
|
self.devices.insert(1, plugboard_any_device_value)
|
||||||
self.new_device.addItems(self.devices)
|
self.new_device.addItems(self.devices)
|
||||||
|
|
||||||
self.formats = ['']
|
self.formats = ['']
|
||||||
|
@ -51,6 +51,23 @@ for x in FORMAT_ARG_DESCS:
|
|||||||
FORMAT_ARGS[x] = ''
|
FORMAT_ARGS[x] = ''
|
||||||
|
|
||||||
|
|
||||||
|
def find_plugboard(device_name, format, plugboards):
|
||||||
|
cpb = None
|
||||||
|
if format in plugboards:
|
||||||
|
cpb = plugboards[format]
|
||||||
|
elif plugboard_any_format_value in plugboards:
|
||||||
|
cpb = plugboards[plugboard_any_format_value]
|
||||||
|
if cpb is not None:
|
||||||
|
if device_name in cpb:
|
||||||
|
cpb = cpb[device_name]
|
||||||
|
elif plugboard_any_device_value in cpb:
|
||||||
|
cpb = cpb[plugboard_any_device_value]
|
||||||
|
else:
|
||||||
|
cpb = None
|
||||||
|
if DEBUG:
|
||||||
|
prints('Device using plugboard', format, device_name, cpb)
|
||||||
|
return cpb
|
||||||
|
|
||||||
def config(defaults=None):
|
def config(defaults=None):
|
||||||
if defaults is None:
|
if defaults is None:
|
||||||
c = Config('save_to_disk', _('Options to control saving to disk'))
|
c = Config('save_to_disk', _('Options to control saving to disk'))
|
||||||
@ -279,20 +296,7 @@ def do_save_book_to_disk(id_, mi, cover, plugboards,
|
|||||||
written = False
|
written = False
|
||||||
for fmt in formats:
|
for fmt in formats:
|
||||||
global plugboard_save_to_disk_value, plugboard_any_format_value
|
global plugboard_save_to_disk_value, plugboard_any_format_value
|
||||||
dev_name = plugboard_save_to_disk_value
|
cpb = find_plugboard(plugboard_save_to_disk_value, fmt, plugboards)
|
||||||
cpb = None
|
|
||||||
if fmt in plugboards:
|
|
||||||
cpb = plugboards[fmt]
|
|
||||||
if dev_name in cpb:
|
|
||||||
cpb = cpb[dev_name]
|
|
||||||
else:
|
|
||||||
cpb = None
|
|
||||||
if cpb is None and plugboard_any_format_value in plugboards:
|
|
||||||
cpb = plugboards[plugboard_any_format_value]
|
|
||||||
if dev_name in cpb:
|
|
||||||
cpb = cpb[dev_name]
|
|
||||||
else:
|
|
||||||
cpb = None
|
|
||||||
# Leave this here for a while, in case problems arise.
|
# Leave this here for a while, in case problems arise.
|
||||||
if cpb is not None:
|
if cpb is not None:
|
||||||
prints('Save-to-disk using plugboard:', fmt, cpb)
|
prints('Save-to-disk using plugboard:', fmt, cpb)
|
||||||
|
@ -12,9 +12,13 @@ import cherrypy
|
|||||||
from calibre import fit_image, guess_type
|
from calibre import fit_image, guess_type
|
||||||
from calibre.utils.date import fromtimestamp
|
from calibre.utils.date import fromtimestamp
|
||||||
from calibre.library.caches import SortKeyGenerator
|
from calibre.library.caches import SortKeyGenerator
|
||||||
|
from calibre.library.save_to_disk import find_plugboard
|
||||||
|
|
||||||
from calibre.utils.magick.draw import save_cover_data_to, Image, \
|
from calibre.utils.magick.draw import save_cover_data_to, Image, \
|
||||||
thumbnail as generate_thumbnail
|
thumbnail as generate_thumbnail
|
||||||
|
|
||||||
|
plugboard_content_server_value = 'content_server'
|
||||||
|
|
||||||
class CSSortKeyGenerator(SortKeyGenerator):
|
class CSSortKeyGenerator(SortKeyGenerator):
|
||||||
|
|
||||||
def __init__(self, fields, fm, db_prefs):
|
def __init__(self, fields, fm, db_prefs):
|
||||||
@ -183,16 +187,30 @@ class ContentServer(object):
|
|||||||
if fmt is None:
|
if fmt is None:
|
||||||
raise cherrypy.HTTPError(404, 'book: %d does not have format: %s'%(id, format))
|
raise cherrypy.HTTPError(404, 'book: %d does not have format: %s'%(id, format))
|
||||||
if format == 'EPUB':
|
if format == 'EPUB':
|
||||||
|
# Get the original metadata
|
||||||
|
mi = self.db.get_metadata(id, index_is_id=True)
|
||||||
|
|
||||||
|
# Get any EPUB plugboards for the content server
|
||||||
|
plugboards = self.db.prefs.get('plugboards', {})
|
||||||
|
cpb = find_plugboard(plugboard_content_server_value,
|
||||||
|
'epub', plugboards)
|
||||||
|
if cpb:
|
||||||
|
# Transform the metadata via the plugboard
|
||||||
|
newmi = mi.deepcopy_metadata()
|
||||||
|
newmi.template_to_attribute(mi, cpb)
|
||||||
|
else:
|
||||||
|
newmi = mi
|
||||||
|
|
||||||
|
# Write the updated file
|
||||||
from tempfile import TemporaryFile
|
from tempfile import TemporaryFile
|
||||||
from calibre.ebooks.metadata.meta import set_metadata
|
from calibre.ebooks.metadata.meta import set_metadata
|
||||||
raw = fmt.read()
|
raw = fmt.read()
|
||||||
fmt = TemporaryFile()
|
fmt = TemporaryFile()
|
||||||
fmt.write(raw)
|
fmt.write(raw)
|
||||||
fmt.seek(0)
|
fmt.seek(0)
|
||||||
set_metadata(fmt, self.db.get_metadata(id, index_is_id=True,
|
set_metadata(fmt, newmi, 'epub')
|
||||||
get_cover=True),
|
|
||||||
'epub')
|
|
||||||
fmt.seek(0)
|
fmt.seek(0)
|
||||||
|
|
||||||
mt = guess_type('dummy.'+format.lower())[0]
|
mt = guess_type('dummy.'+format.lower())[0]
|
||||||
if mt is None:
|
if mt is None:
|
||||||
mt = 'application/octet-stream'
|
mt = 'application/octet-stream'
|
||||||
|
Loading…
x
Reference in New Issue
Block a user