mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
...
This commit is contained in:
parent
b562f0324c
commit
f4ade0dc3b
@ -123,8 +123,6 @@ def create_upload_path(mdata, fname, template, sanitize,
|
||||
return ans
|
||||
|
||||
extra_components = list(map(remove_trailing_periods, extra_components))
|
||||
if prefix_path:
|
||||
prefix_path = path_type.abspath(prefix_path)
|
||||
components = shorten_components_to(maxlen - len(prefix_path), extra_components)
|
||||
components = sanitize_path_components(components)
|
||||
if prefix_path:
|
||||
|
@ -61,11 +61,15 @@ class MTPDeviceBase(DevicePlugin):
|
||||
|
||||
def build_template_regexp(self):
|
||||
from calibre.devices import build_template_regexp
|
||||
# TODO: Use the device specific template here
|
||||
return build_template_regexp(self.default_save_template)
|
||||
return build_template_regexp(self.save_template)
|
||||
|
||||
@property
|
||||
def default_save_template(cls):
|
||||
from calibre.library.save_to_disk import config
|
||||
return config().parse().send_template
|
||||
|
||||
@property
|
||||
def save_template(self):
|
||||
# TODO: Use the device specific template here
|
||||
return self.default_save_template
|
||||
|
||||
|
@ -7,7 +7,7 @@ __license__ = 'GPL v3'
|
||||
__copyright__ = '2012, Kovid Goyal <kovid at kovidgoyal.net>'
|
||||
__docformat__ = 'restructuredtext en'
|
||||
|
||||
import json, pprint, traceback
|
||||
import json, pprint, traceback, posixpath
|
||||
from io import BytesIO
|
||||
|
||||
from calibre import prints
|
||||
@ -29,6 +29,8 @@ class MTP_DEVICE(BASE):
|
||||
METADATA_CACHE = 'metadata.calibre'
|
||||
DRIVEINFO = 'driveinfo.calibre'
|
||||
CAN_SET_METADATA = []
|
||||
NEWS_IN_FOLDER = True
|
||||
MAX_PATH_LEN = 230
|
||||
|
||||
def open(self, devices, library_uuid):
|
||||
self.current_library_uuid = library_uuid
|
||||
@ -181,6 +183,18 @@ class MTP_DEVICE(BASE):
|
||||
self.put_file(storage, self.METADATA_CACHE, stream, size)
|
||||
# }}}
|
||||
|
||||
def create_upload_path(self, path, mdata, fname):
|
||||
from calibre.devices import create_upload_path
|
||||
from calibre.utils.filenames import ascii_filename as sanitize
|
||||
filepath = create_upload_path(mdata, fname, self.save_template, sanitize,
|
||||
prefix_path=path,
|
||||
path_type=posixpath,
|
||||
maxlen=self.MAX_PATH_LEN,
|
||||
use_subdirs = True,
|
||||
news_in_folder = self.NEWS_IN_FOLDER,
|
||||
)
|
||||
return tuple(x.lower() for x in filepath.split('/'))
|
||||
|
||||
if __name__ == '__main__':
|
||||
dev = MTP_DEVICE(None)
|
||||
dev.startup()
|
||||
|
Loading…
x
Reference in New Issue
Block a user