From f4ade0dc3bb8a4517b3a18f387251d7cdd3a7888 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Sat, 1 Sep 2012 09:31:07 +0530 Subject: [PATCH] ... --- src/calibre/devices/__init__.py | 2 -- src/calibre/devices/mtp/base.py | 8 ++++++-- src/calibre/devices/mtp/driver.py | 16 +++++++++++++++- 3 files changed, 21 insertions(+), 5 deletions(-) diff --git a/src/calibre/devices/__init__.py b/src/calibre/devices/__init__.py index abe7d98b9f..e67c17c063 100644 --- a/src/calibre/devices/__init__.py +++ b/src/calibre/devices/__init__.py @@ -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: diff --git a/src/calibre/devices/mtp/base.py b/src/calibre/devices/mtp/base.py index 346a44e6e8..865eeefb37 100644 --- a/src/calibre/devices/mtp/base.py +++ b/src/calibre/devices/mtp/base.py @@ -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 + diff --git a/src/calibre/devices/mtp/driver.py b/src/calibre/devices/mtp/driver.py index 7ba02e2aaa..2ec9e4e586 100644 --- a/src/calibre/devices/mtp/driver.py +++ b/src/calibre/devices/mtp/driver.py @@ -7,7 +7,7 @@ __license__ = 'GPL v3' __copyright__ = '2012, Kovid Goyal ' __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()