mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Unicode/pathsep fixes
This commit is contained in:
commit
dfa03feec9
@ -445,6 +445,9 @@ def prepare_string_for_xml(raw, attribute=False):
|
|||||||
raw = raw.replace('"', '"').replace("'", ''')
|
raw = raw.replace('"', '"').replace("'", ''')
|
||||||
return raw
|
return raw
|
||||||
|
|
||||||
|
def isbytestring(obj):
|
||||||
|
return isinstance(obj, (str, bytes))
|
||||||
|
|
||||||
if isosx:
|
if isosx:
|
||||||
import glob, shutil
|
import glob, shutil
|
||||||
fdir = os.path.expanduser('~/.fonts')
|
fdir = os.path.expanduser('~/.fonts')
|
||||||
|
@ -54,6 +54,7 @@ class FOLDER_DEVICE(USBMS):
|
|||||||
def __init__(self, path):
|
def __init__(self, path):
|
||||||
if not os.path.isdir(path):
|
if not os.path.isdir(path):
|
||||||
raise IOError, 'Path is not a folder'
|
raise IOError, 'Path is not a folder'
|
||||||
|
path = USBMS.normalize_path(path)
|
||||||
if path.endswith(os.sep):
|
if path.endswith(os.sep):
|
||||||
self._main_prefix = path
|
self._main_prefix = path
|
||||||
else:
|
else:
|
||||||
|
@ -15,7 +15,8 @@ import re
|
|||||||
import json
|
import json
|
||||||
from itertools import cycle
|
from itertools import cycle
|
||||||
|
|
||||||
from calibre import prints
|
from calibre import prints, isbytestring
|
||||||
|
from calibre.constants import filesystem_encoding
|
||||||
from calibre.devices.usbms.cli import CLI
|
from calibre.devices.usbms.cli import CLI
|
||||||
from calibre.devices.usbms.device import Device
|
from calibre.devices.usbms.device import Device
|
||||||
from calibre.devices.usbms.books import BookList, Book
|
from calibre.devices.usbms.books import BookList, Book
|
||||||
@ -90,7 +91,6 @@ class USBMS(CLI, Device):
|
|||||||
#print 'update_metadata_item returned true'
|
#print 'update_metadata_item returned true'
|
||||||
changed = True
|
changed = True
|
||||||
else:
|
else:
|
||||||
#print "adding new book", lpath
|
|
||||||
if bl.add_book(self.book_from_path(prefix, lpath),
|
if bl.add_book(self.book_from_path(prefix, lpath),
|
||||||
replace_metadata=False):
|
replace_metadata=False):
|
||||||
changed = True
|
changed = True
|
||||||
@ -102,6 +102,8 @@ class USBMS(CLI, Device):
|
|||||||
if isinstance(ebook_dirs, basestring):
|
if isinstance(ebook_dirs, basestring):
|
||||||
ebook_dirs = [ebook_dirs]
|
ebook_dirs = [ebook_dirs]
|
||||||
for ebook_dir in ebook_dirs:
|
for ebook_dir in ebook_dirs:
|
||||||
|
if isbytestring(ebook_dir):
|
||||||
|
ebook_dir = ebook_dir.decode(filesystem_encoding)
|
||||||
ebook_dir = self.normalize_path( \
|
ebook_dir = self.normalize_path( \
|
||||||
os.path.join(prefix, *(ebook_dir.split('/'))) \
|
os.path.join(prefix, *(ebook_dir.split('/'))) \
|
||||||
if ebook_dir else prefix)
|
if ebook_dir else prefix)
|
||||||
@ -113,7 +115,8 @@ class USBMS(CLI, Device):
|
|||||||
for path, dirs, files in os.walk(ebook_dir):
|
for path, dirs, files in os.walk(ebook_dir):
|
||||||
for filename in files:
|
for filename in files:
|
||||||
if filename != self.METADATA_CACHE:
|
if filename != self.METADATA_CACHE:
|
||||||
flist.append({'filename':filename, 'path': path})
|
flist.append({'filename':filename,
|
||||||
|
'path':path})
|
||||||
for i, f in enumerate(flist):
|
for i, f in enumerate(flist):
|
||||||
self.report_progress(i/float(len(flist)), _('Getting list of books on device...'))
|
self.report_progress(i/float(len(flist)), _('Getting list of books on device...'))
|
||||||
changed = update_booklist(f['filename'], f['path'], prefix)
|
changed = update_booklist(f['filename'], f['path'], prefix)
|
||||||
@ -189,20 +192,22 @@ class USBMS(CLI, Device):
|
|||||||
for i, location in enumerate(locations):
|
for i, location in enumerate(locations):
|
||||||
self.report_progress((i+1) / float(len(locations)), _('Adding books to device metadata listing...'))
|
self.report_progress((i+1) / float(len(locations)), _('Adding books to device metadata listing...'))
|
||||||
info = metadata.next()
|
info = metadata.next()
|
||||||
path = location[0]
|
|
||||||
blist = 2 if location[1] == 'cardb' else 1 if location[1] == 'carda' else 0
|
blist = 2 if location[1] == 'cardb' else 1 if location[1] == 'carda' else 0
|
||||||
|
|
||||||
|
# Extract the correct prefix from the pathname. To do this correctly,
|
||||||
|
# we must ensure that both the prefix and the path are normalized
|
||||||
|
# so that the comparison will work. Book's __init__ will fix up
|
||||||
|
# lpath, so we don't need to worry about that here.
|
||||||
|
path = self.normalize_path(location[0])
|
||||||
if self._main_prefix:
|
if self._main_prefix:
|
||||||
# Normalize path and prefix
|
prefix = self._main_prefix if \
|
||||||
if self._main_prefix.find('\\') >= 0:
|
path.startswith(self.normalize_path(self._main_prefix)) else None
|
||||||
path = path.replace('/', '\\')
|
|
||||||
else:
|
|
||||||
path = path.replace('\\', '/')
|
|
||||||
prefix = self._main_prefix if path.startswith(self._main_prefix) else None
|
|
||||||
if not prefix and self._card_a_prefix:
|
if not prefix and self._card_a_prefix:
|
||||||
prefix = self._card_a_prefix if path.startswith(self._card_a_prefix) else None
|
prefix = self._card_a_prefix if \
|
||||||
|
path.startswith(self.normalize_path(self._card_a_prefix)) else None
|
||||||
if not prefix and self._card_b_prefix:
|
if not prefix and self._card_b_prefix:
|
||||||
prefix = self._card_b_prefix if path.startswith(self._card_b_prefix) else None
|
prefix = self._card_b_prefix if \
|
||||||
|
path.startswith(self.normalize_path(self._card_b_prefix)) else None
|
||||||
if prefix is None:
|
if prefix is None:
|
||||||
prints('in add_books_to_metadata. Prefix is None!', path,
|
prints('in add_books_to_metadata. Prefix is None!', path,
|
||||||
self._main_prefix)
|
self._main_prefix)
|
||||||
@ -274,6 +279,8 @@ class USBMS(CLI, Device):
|
|||||||
path = path.replace('/', '\\')
|
path = path.replace('/', '\\')
|
||||||
else:
|
else:
|
||||||
path = path.replace('\\', '/')
|
path = path.replace('\\', '/')
|
||||||
|
if isbytestring(path):
|
||||||
|
path = path.decode(filesystem_encoding)
|
||||||
return path
|
return path
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
|
@ -560,6 +560,7 @@ get_device_ancestors(HDEVINFO hDevInfo, DWORD index, PyObject *candidates, BOOL
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
interfaceDetailData->cbSize = sizeof (SP_INTERFACE_DEVICE_DETAIL_DATA);
|
interfaceDetailData->cbSize = sizeof (SP_INTERFACE_DEVICE_DETAIL_DATA);
|
||||||
|
devInfoData.cbSize = sizeof(SP_DEVINFO_DATA);
|
||||||
|
|
||||||
status = SetupDiGetDeviceInterfaceDetail (
|
status = SetupDiGetDeviceInterfaceDetail (
|
||||||
hDevInfo, // Interface Device info handle
|
hDevInfo, // Interface Device info handle
|
||||||
|
Loading…
x
Reference in New Issue
Block a user