From 75c3fa5a2307ab65962de0697916c70aa20087c7 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Tue, 1 Jul 2008 12:42:30 -0700 Subject: [PATCH] Fix #838 --- src/calibre/ebooks/lrf/__init__.py | 2 -- src/calibre/ebooks/lrf/any/convert_from.py | 11 ++++++----- src/calibre/ebooks/lrf/html/convert_from.py | 8 +++++--- 3 files changed, 11 insertions(+), 10 deletions(-) diff --git a/src/calibre/ebooks/lrf/__init__.py b/src/calibre/ebooks/lrf/__init__.py index 1cdba123d8..6b724fd008 100644 --- a/src/calibre/ebooks/lrf/__init__.py +++ b/src/calibre/ebooks/lrf/__init__.py @@ -9,8 +9,6 @@ from optparse import OptionValueError from htmlentitydefs import name2codepoint from uuid import uuid4 -from fontTools.ttLib import TTLibError - from calibre.ebooks.lrf.pylrs.pylrs import Book as _Book from calibre.ebooks.lrf.pylrs.pylrs import TextBlock, Header, PutObj, \ Paragraph, TextStyle, BlockStyle diff --git a/src/calibre/ebooks/lrf/any/convert_from.py b/src/calibre/ebooks/lrf/any/convert_from.py index ab66fc1b89..c0a1a6500c 100644 --- a/src/calibre/ebooks/lrf/any/convert_from.py +++ b/src/calibre/ebooks/lrf/any/convert_from.py @@ -66,7 +66,7 @@ def traverse_subdirs(tdir): return tdir def handle_archive(path): - tdir = tempfile.mkdtemp(prefix=__appname__+'_') + tdir = tempfile.mkdtemp(prefix=__appname__+'_'+'archive_') extract(path, tdir) files = [] cdir = traverse_subdirs(tdir) @@ -75,9 +75,10 @@ def handle_archive(path): pat = os.path.join(cdir, '*.'+ext) files.extend(glob.glob(pat)) file = largest_file(files) - if file: - return tdir, file - file = find_htmlfile(cdir) + if not file: + file = find_htmlfile(cdir) + if isinstance(file, str): + file = file.decode(sys.getfilesystemencoding()) return tdir, file def process_file(path, options, logger=None): @@ -109,7 +110,7 @@ def process_file(path, options, logger=None): if not newpath: raise UnknownFormatError('Could not find ebook in archive') path = newpath - logger.info('Found ebook in archive: %s', path) + logger.info('Found ebook in archive: %s', repr(path)) try: ext = os.path.splitext(path)[1][1:].lower() convertor = None diff --git a/src/calibre/ebooks/lrf/html/convert_from.py b/src/calibre/ebooks/lrf/html/convert_from.py index 27bf152597..15eede6d6c 100644 --- a/src/calibre/ebooks/lrf/html/convert_from.py +++ b/src/calibre/ebooks/lrf/html/convert_from.py @@ -368,9 +368,10 @@ class HTMLConverter(object, LoggingInterface): else: self.css[selector] = self.override_css[selector] - self.file_name = os.path.basename(path) - self.log_info(_('Processing %s'), path if self.verbose else self.file_name) - upath = path.encode('utf-8') if isinstance(path, unicode) else path + upath = path.encode(sys.getfilesystemencoding()) if isinstance(path, unicode) else path + self.file_name = os.path.basename(upath.decode(sys.getfilesystemencoding())) + self.log_info(_('Processing %s'), repr(upath) if self.verbose else repr(self.file_name)) + if not os.path.exists(upath): upath = upath.replace('&', '%26') #convertlit replaces & with %26 in file names f = open(upath, 'rb') @@ -1799,6 +1800,7 @@ def process_file(path, options, logger=None): level = logging.DEBUG if options.verbose else logging.INFO logger = logging.getLogger('html2lrf') setup_cli_handlers(logger, level) + if not isinstance(path, unicode): path = path.decode(sys.getfilesystemencoding()) path = os.path.abspath(path)