mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-08-30 23:00:21 -04:00
Add filesystem_encoding to unicode calls
This commit is contained in:
parent
9fcab76112
commit
2c5fb72281
@ -16,6 +16,7 @@ import json
|
|||||||
from itertools import cycle
|
from itertools import cycle
|
||||||
|
|
||||||
from calibre import prints
|
from calibre import prints
|
||||||
|
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
|
||||||
@ -87,7 +88,6 @@ class USBMS(CLI, Device):
|
|||||||
if idx is not None:
|
if idx is not None:
|
||||||
bl_cache[lpath] = None
|
bl_cache[lpath] = None
|
||||||
if self.update_metadata_item(bl[idx]):
|
if self.update_metadata_item(bl[idx]):
|
||||||
#print 'update_metadata_item returned true'
|
|
||||||
changed = True
|
changed = True
|
||||||
else:
|
else:
|
||||||
if bl.add_book(self.book_from_path(prefix, lpath),
|
if bl.add_book(self.book_from_path(prefix, lpath),
|
||||||
@ -112,8 +112,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':unicode(filename),
|
flist.append({'filename':self.path_to_unicode(filename),
|
||||||
'path':unicode(path)})
|
'path':self.path_to_unicode(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)
|
||||||
@ -123,7 +123,8 @@ class USBMS(CLI, Device):
|
|||||||
paths = os.listdir(ebook_dir)
|
paths = os.listdir(ebook_dir)
|
||||||
for i, filename in enumerate(paths):
|
for i, filename in enumerate(paths):
|
||||||
self.report_progress((i+1) / float(len(paths)), _('Getting list of books on device...'))
|
self.report_progress((i+1) / float(len(paths)), _('Getting list of books on device...'))
|
||||||
changed = update_booklist(unicode(filename), ebook_dir, prefix)
|
changed = update_booklist(self.path_to_unicode(filename),
|
||||||
|
ebook_dir, prefix)
|
||||||
if changed:
|
if changed:
|
||||||
need_sync = True
|
need_sync = True
|
||||||
|
|
||||||
@ -267,16 +268,22 @@ class USBMS(CLI, Device):
|
|||||||
|
|
||||||
self.report_progress(1.0, _('Sending metadata to device...'))
|
self.report_progress(1.0, _('Sending metadata to device...'))
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def path_to_unicode(cls, path):
|
||||||
|
if isinstance(path, str): ## bytes is synonym for str as of python 2.6
|
||||||
|
print 'p2u: isString', path
|
||||||
|
return unicode(path, filesystem_encoding)
|
||||||
|
return path
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def normalize_path(cls, path):
|
def normalize_path(cls, path):
|
||||||
'Return path with platform native path separators'
|
'Return path with platform native path separators'
|
||||||
if path is None:
|
if path is None:
|
||||||
return None
|
return None
|
||||||
if os.sep == '\\':
|
if os.sep == '\\':
|
||||||
path = path.replace('/', '\\')
|
return cls.path_to_unicode(path.replace('/', '\\'))
|
||||||
else:
|
else:
|
||||||
path = path.replace('\\', '/')
|
return cls.path_to_unicode(path.replace('\\', '/'))
|
||||||
return unicode(path)
|
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def parse_metadata_cache(cls, bl, prefix, name):
|
def parse_metadata_cache(cls, bl, prefix, name):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user