mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Merge from custcol trunk
This commit is contained in:
commit
5dd98939ca
@ -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')
|
||||||
|
@ -184,8 +184,7 @@ class XMLCache(object):
|
|||||||
'descendant::*[local-name()="png"]'):
|
'descendant::*[local-name()="png"]'):
|
||||||
if img.text:
|
if img.text:
|
||||||
raw = b64decode(img.text.strip())
|
raw = b64decode(img.text.strip())
|
||||||
ext = img.tag.split('}')[-1]
|
book.thumbnail = raw
|
||||||
book.cover_data = [ext, raw]
|
|
||||||
break
|
break
|
||||||
break
|
break
|
||||||
# }}}
|
# }}}
|
||||||
|
@ -11,7 +11,8 @@ import time
|
|||||||
from calibre.ebooks.metadata import MetaInformation
|
from calibre.ebooks.metadata import MetaInformation
|
||||||
from calibre.devices.mime import mime_type_ext
|
from calibre.devices.mime import mime_type_ext
|
||||||
from calibre.devices.interface import BookList as _BookList
|
from calibre.devices.interface import BookList as _BookList
|
||||||
from calibre.constants import filesystem_encoding
|
from calibre.constants import filesystem_encoding, preferred_encoding
|
||||||
|
from calibre import isbytestring
|
||||||
|
|
||||||
class Book(MetaInformation):
|
class Book(MetaInformation):
|
||||||
|
|
||||||
@ -105,7 +106,11 @@ class Book(MetaInformation):
|
|||||||
def to_json(self):
|
def to_json(self):
|
||||||
json = {}
|
json = {}
|
||||||
for attr in self.JSON_ATTRS:
|
for attr in self.JSON_ATTRS:
|
||||||
json[attr] = getattr(self, attr)
|
val = getattr(self, attr)
|
||||||
|
if isbytestring(val):
|
||||||
|
enc = filesystem_encoding if attr == 'lpath' else preferred_encoding
|
||||||
|
val = val.decode(enc, 'replace')
|
||||||
|
json[attr] = val
|
||||||
return json
|
return json
|
||||||
|
|
||||||
class BookList(_BookList):
|
class BookList(_BookList):
|
||||||
|
@ -15,7 +15,7 @@ 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.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
|
||||||
@ -88,6 +88,7 @@ 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),
|
||||||
@ -101,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)
|
||||||
@ -112,8 +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':self.path_to_unicode(filename),
|
flist.append({'filename':filename,
|
||||||
'path':self.path_to_unicode(path)})
|
'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)
|
||||||
@ -123,8 +126,7 @@ 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(self.path_to_unicode(filename),
|
changed = update_booklist(filename, ebook_dir, prefix)
|
||||||
ebook_dir, prefix)
|
|
||||||
if changed:
|
if changed:
|
||||||
need_sync = True
|
need_sync = True
|
||||||
|
|
||||||
@ -268,22 +270,18 @@ 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 == '\\':
|
||||||
return cls.path_to_unicode(path.replace('/', '\\'))
|
path = path.replace('/', '\\')
|
||||||
else:
|
else:
|
||||||
return cls.path_to_unicode(path.replace('\\', '/'))
|
path = path.replace('\\', '/')
|
||||||
|
if isbytestring(path):
|
||||||
|
path = path.decode(filesystem_encoding)
|
||||||
|
return path
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def parse_metadata_cache(cls, bl, prefix, name):
|
def parse_metadata_cache(cls, bl, prefix, name):
|
||||||
|
@ -5,9 +5,9 @@ __copyright__ = '2008, Kovid Goyal <kovid at kovidgoyal.net>'
|
|||||||
import os, re, collections
|
import os, re, collections
|
||||||
|
|
||||||
from calibre.utils.config import prefs
|
from calibre.utils.config import prefs
|
||||||
|
from calibre.constants import filesystem_encoding
|
||||||
from calibre.ebooks.metadata.opf2 import OPF
|
from calibre.ebooks.metadata.opf2 import OPF
|
||||||
|
from calibre import isbytestring
|
||||||
from calibre.customize.ui import get_file_type_metadata, set_file_type_metadata
|
from calibre.customize.ui import get_file_type_metadata, set_file_type_metadata
|
||||||
from calibre.ebooks.metadata import MetaInformation, string_to_authors
|
from calibre.ebooks.metadata import MetaInformation, string_to_authors
|
||||||
|
|
||||||
@ -131,6 +131,8 @@ def set_metadata(stream, mi, stream_type='lrf'):
|
|||||||
|
|
||||||
|
|
||||||
def metadata_from_filename(name, pat=None):
|
def metadata_from_filename(name, pat=None):
|
||||||
|
if isbytestring(name):
|
||||||
|
name = name.decode(filesystem_encoding, 'replace')
|
||||||
name = name.rpartition('.')[0]
|
name = name.rpartition('.')[0]
|
||||||
mi = MetaInformation(None, None)
|
mi = MetaInformation(None, None)
|
||||||
if pat is None:
|
if pat is None:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user