mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Added callback method: sanitize_callback
This callback enables change sanitize behavior. Filename sanitization when sending to the device is not necessary for some devices. Official plugin should never override this callback this callback to pass the sanitization, but this is useful to override by the private driver plugin.
This commit is contained in:
parent
b8c52790bc
commit
54bfaede28
@ -1015,6 +1015,15 @@ class Device(DeviceConfig, DevicePlugin):
|
|||||||
|
|
||||||
return path
|
return path
|
||||||
|
|
||||||
|
def sanitize_callback(self, path):
|
||||||
|
'''
|
||||||
|
Callback to allow override the path sanitization
|
||||||
|
used by :meth:`create_upload_path`.
|
||||||
|
|
||||||
|
*CAUTION* Official plugin developer must not override this method to pass the sanitization
|
||||||
|
'''
|
||||||
|
return sanitize(path)
|
||||||
|
|
||||||
def filename_callback(self, default, mi):
|
def filename_callback(self, default, mi):
|
||||||
'''
|
'''
|
||||||
Callback to allow drivers to change the default file name
|
Callback to allow drivers to change the default file name
|
||||||
@ -1044,7 +1053,7 @@ class Device(DeviceConfig, DevicePlugin):
|
|||||||
def create_upload_path(self, path, mdata, fname, create_dirs=True):
|
def create_upload_path(self, path, mdata, fname, create_dirs=True):
|
||||||
from calibre.devices.utils import create_upload_path
|
from calibre.devices.utils import create_upload_path
|
||||||
settings = self.settings()
|
settings = self.settings()
|
||||||
filepath = create_upload_path(mdata, fname, self.save_template(), sanitize,
|
filepath = create_upload_path(mdata, fname, self.save_template(), sanitize=self.sanitize_callback,
|
||||||
prefix_path=os.path.abspath(path),
|
prefix_path=os.path.abspath(path),
|
||||||
maxlen=self.MAX_PATH_LEN,
|
maxlen=self.MAX_PATH_LEN,
|
||||||
use_subdirs = self.SUPPORTS_SUB_DIRS and settings.use_subdirs,
|
use_subdirs = self.SUPPORTS_SUB_DIRS and settings.use_subdirs,
|
||||||
|
@ -99,7 +99,8 @@ def create_upload_path(mdata, fname, template, sanitize,
|
|||||||
app_id = str(getattr(mdata, 'application_id', ''))
|
app_id = str(getattr(mdata, 'application_id', ''))
|
||||||
id_ = mdata.get('id', fname)
|
id_ = mdata.get('id', fname)
|
||||||
extra_components = get_components(template, mdata, id_,
|
extra_components = get_components(template, mdata, id_,
|
||||||
timefmt=opts.send_timefmt, length=maxlen-len(app_id)-1)
|
timefmt=opts.send_timefmt, length=maxlen-len(app_id)-1,
|
||||||
|
sanitize_func=sanitize)
|
||||||
if not extra_components:
|
if not extra_components:
|
||||||
extra_components.append(sanitize(filename_callback(fname,
|
extra_components.append(sanitize(filename_callback(fname,
|
||||||
mdata)))
|
mdata)))
|
||||||
|
Loading…
x
Reference in New Issue
Block a user