mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Suggested content server plugboard implementation for Greg
This commit is contained in:
parent
4ea961ba62
commit
91c5356ac5
@ -582,7 +582,6 @@ from calibre.ebooks.snb.output import SNBOutput
|
||||
from calibre.customize.profiles import input_profiles, output_profiles
|
||||
|
||||
from calibre.devices.apple.driver import ITUNES
|
||||
from calibre.devices.content_server.driver import CONTENT_SERVER_FOR_CONFIG
|
||||
from calibre.devices.hanlin.driver import HANLINV3, HANLINV5, BOOX, SPECTRA
|
||||
from calibre.devices.blackberry.driver import BLACKBERRY
|
||||
from calibre.devices.cybook.driver import CYBOOK, ORIZON
|
||||
@ -754,7 +753,6 @@ plugins += [
|
||||
EEEREADER,
|
||||
NEXTBOOK,
|
||||
ITUNES,
|
||||
CONTENT_SERVER_FOR_CONFIG
|
||||
]
|
||||
|
||||
plugins += [x for x in list(locals().values()) if isinstance(x, type) and \
|
||||
|
@ -1,10 +0,0 @@
|
||||
#!/usr/bin/env python
|
||||
# vim:fileencoding=UTF-8:ts=4:sw=4:sta:et:sts=4:ai
|
||||
from __future__ import with_statement
|
||||
|
||||
__license__ = 'GPL v3'
|
||||
__copyright__ = '2009, Kovid Goyal <kovid@kovidgoyal.net>'
|
||||
__docformat__ = 'restructuredtext en'
|
||||
|
||||
|
||||
|
@ -1,74 +0,0 @@
|
||||
'''
|
||||
Created on 17 Apr 2011
|
||||
|
||||
@author: GRiker, modeled on charles's Folder Device
|
||||
|
||||
'''
|
||||
|
||||
from calibre.constants import DEBUG
|
||||
from calibre.devices.interface import DevicePlugin
|
||||
from calibre.devices.usbms.deviceconfig import DeviceConfig
|
||||
from calibre.devices.usbms.driver import USBMS, BookList
|
||||
|
||||
class DriverBase(DeviceConfig, DevicePlugin):
|
||||
# Reduce to just the formats eligible for plugboard xforms
|
||||
# These formats are shown in the customization dialog
|
||||
FORMATS = ['epub', 'mobi']
|
||||
USER_CAN_ADD_NEW_FORMATS = False
|
||||
|
||||
# Hide the standard customization widgets
|
||||
SUPPORTS_SUB_DIRS = False
|
||||
MUST_READ_METADATA = True
|
||||
SUPPORTS_USE_AUTHOR_SORT = False
|
||||
|
||||
|
||||
# This class is added to the standard device plugin chain, so that it can
|
||||
# be configured. It has invalid vendor_id etc, so it will never match a
|
||||
# device. The 'real' CONTENT_SERVER will use the config from it.
|
||||
class CONTENT_SERVER_FOR_CONFIG(USBMS):
|
||||
name = 'Content Server Interface'
|
||||
gui_name = 'Content Server'
|
||||
description = _('Enables metadata plugboards to be used with Content Server.')
|
||||
author = 'GRiker'
|
||||
supported_platforms = ['windows', 'osx', 'linux']
|
||||
|
||||
VENDOR_ID = [0xffff]
|
||||
PRODUCT_ID = [0xffff]
|
||||
BCD = [0xffff]
|
||||
DEVICE_PLUGBOARD_NAME = 'CONTENT_SERVER'
|
||||
|
||||
def config_widget(cls):
|
||||
'''
|
||||
Configure a minimal QWidget
|
||||
Better to simply disable the config_widget altogether
|
||||
'''
|
||||
cw = DriverBase.config_widget()
|
||||
# Turn off the Save template
|
||||
cw.opt_save_template.setVisible(False)
|
||||
cw.label.setVisible(False)
|
||||
# Hide the up/down arrows
|
||||
cw.column_up.setVisible(False)
|
||||
cw.column_down.setVisible(False)
|
||||
# Retitle
|
||||
cw.groupBox.setTitle(_("Enable metadata plugboards for the following formats:"))
|
||||
return cw
|
||||
|
||||
class CONTENT_SERVER(USBMS):
|
||||
|
||||
FORMATS = CONTENT_SERVER_FOR_CONFIG.FORMATS
|
||||
DEVICE_PLUGBOARD_NAME = 'CONTENT_SERVER'
|
||||
|
||||
def __init__(self):
|
||||
if DEBUG:
|
||||
print("CONTENT_SERVER.init()")
|
||||
pass
|
||||
|
||||
def set_plugboards(self, plugboards, pb_func):
|
||||
# This method is called with the plugboard that matches the format
|
||||
# declared in use_plugboard_ext and a device name of CONTENT_SERVER
|
||||
if DEBUG:
|
||||
print("CONTENT_SERVER.set_plugboards()")
|
||||
print(' using plugboard %s' % plugboards)
|
||||
self.plugboards = plugboards
|
||||
self.plugboard_func = pb_func
|
||||
|
@ -29,8 +29,7 @@ from calibre.ebooks.metadata.meta import set_metadata
|
||||
from calibre.constants import DEBUG
|
||||
from calibre.utils.config import prefs, tweaks
|
||||
from calibre.utils.magick.draw import thumbnail
|
||||
from calibre.library.save_to_disk import plugboard_any_device_value, \
|
||||
plugboard_any_format_value
|
||||
from calibre.library.save_to_disk import find_plugboard
|
||||
# }}}
|
||||
|
||||
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):
|
||||
if hasattr(device_class, 'DEVICE_PLUGBOARD_NAME'):
|
||||
return device_class.DEVICE_PLUGBOARD_NAME
|
||||
|
@ -15,6 +15,7 @@ from calibre.gui2.preferences.plugboard_ui import Ui_Form
|
||||
from calibre.customize.ui import metadata_writers, device_plugins
|
||||
from calibre.library.save_to_disk import plugboard_any_format_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
|
||||
|
||||
|
||||
@ -74,7 +75,8 @@ class ConfigWidget(ConfigWidgetBase, Ui_Form):
|
||||
self.devices.append(n)
|
||||
self.devices.sort(cmp=lambda x, y: cmp(x.lower(), y.lower()))
|
||||
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.formats = ['']
|
||||
|
@ -51,6 +51,23 @@ for x in FORMAT_ARG_DESCS:
|
||||
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):
|
||||
if defaults is None:
|
||||
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
|
||||
for fmt in formats:
|
||||
global plugboard_save_to_disk_value, plugboard_any_format_value
|
||||
dev_name = plugboard_save_to_disk_value
|
||||
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
|
||||
cpb = find_plugboard(plugboard_save_to_disk_value, fmt, plugboards)
|
||||
# Leave this here for a while, in case problems arise.
|
||||
if cpb is not None:
|
||||
prints('Save-to-disk using plugboard:', fmt, cpb)
|
||||
|
@ -12,9 +12,13 @@ import cherrypy
|
||||
from calibre import fit_image, guess_type
|
||||
from calibre.utils.date import fromtimestamp
|
||||
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, \
|
||||
thumbnail as generate_thumbnail
|
||||
|
||||
plugboard_content_server_value = 'content_server'
|
||||
|
||||
class CSSortKeyGenerator(SortKeyGenerator):
|
||||
|
||||
def __init__(self, fields, fm, db_prefs):
|
||||
@ -186,19 +190,12 @@ class ContentServer(object):
|
||||
# Get the original metadata
|
||||
mi = self.db.get_metadata(id, index_is_id=True)
|
||||
|
||||
# Instantiate the CONTENT_SERVER driver
|
||||
from calibre.devices.content_server.driver import CONTENT_SERVER
|
||||
cs = CONTENT_SERVER()
|
||||
|
||||
# Get any EPUB plugboards for the content server
|
||||
from calibre.gui2.device import find_plugboard, device_name_for_plugboards
|
||||
plugboards = self.db.prefs.get('plugboards', {})
|
||||
|
||||
# Transform the metadata via the plugboard
|
||||
if hasattr(cs, 'set_plugboards') and callable(cs.set_plugboards):
|
||||
cs.set_plugboards(plugboards, find_plugboard)
|
||||
cpb = find_plugboard(device_name_for_plugboards(cs), format.lower(), 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:
|
||||
|
Loading…
x
Reference in New Issue
Block a user