This commit is contained in:
Kovid Goyal 2012-09-01 09:31:07 +05:30
parent b562f0324c
commit f4ade0dc3b
3 changed files with 21 additions and 5 deletions

View File

@ -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:

View File

@ -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

View File

@ -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()