This commit is contained in:
Kovid Goyal 2008-07-01 12:42:30 -07:00
parent b560528b93
commit 75c3fa5a23
3 changed files with 11 additions and 10 deletions

View File

@ -9,8 +9,6 @@ from optparse import OptionValueError
from htmlentitydefs import name2codepoint from htmlentitydefs import name2codepoint
from uuid import uuid4 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 Book as _Book
from calibre.ebooks.lrf.pylrs.pylrs import TextBlock, Header, PutObj, \ from calibre.ebooks.lrf.pylrs.pylrs import TextBlock, Header, PutObj, \
Paragraph, TextStyle, BlockStyle Paragraph, TextStyle, BlockStyle

View File

@ -66,7 +66,7 @@ def traverse_subdirs(tdir):
return tdir return tdir
def handle_archive(path): def handle_archive(path):
tdir = tempfile.mkdtemp(prefix=__appname__+'_') tdir = tempfile.mkdtemp(prefix=__appname__+'_'+'archive_')
extract(path, tdir) extract(path, tdir)
files = [] files = []
cdir = traverse_subdirs(tdir) cdir = traverse_subdirs(tdir)
@ -75,9 +75,10 @@ def handle_archive(path):
pat = os.path.join(cdir, '*.'+ext) pat = os.path.join(cdir, '*.'+ext)
files.extend(glob.glob(pat)) files.extend(glob.glob(pat))
file = largest_file(files) file = largest_file(files)
if file: if not file:
return tdir, file file = find_htmlfile(cdir)
file = find_htmlfile(cdir) if isinstance(file, str):
file = file.decode(sys.getfilesystemencoding())
return tdir, file return tdir, file
def process_file(path, options, logger=None): def process_file(path, options, logger=None):
@ -109,7 +110,7 @@ def process_file(path, options, logger=None):
if not newpath: if not newpath:
raise UnknownFormatError('Could not find ebook in archive') raise UnknownFormatError('Could not find ebook in archive')
path = newpath path = newpath
logger.info('Found ebook in archive: %s', path) logger.info('Found ebook in archive: %s', repr(path))
try: try:
ext = os.path.splitext(path)[1][1:].lower() ext = os.path.splitext(path)[1][1:].lower()
convertor = None convertor = None

View File

@ -368,9 +368,10 @@ class HTMLConverter(object, LoggingInterface):
else: else:
self.css[selector] = self.override_css[selector] self.css[selector] = self.override_css[selector]
self.file_name = os.path.basename(path) upath = path.encode(sys.getfilesystemencoding()) if isinstance(path, unicode) else path
self.log_info(_('Processing %s'), path if self.verbose else self.file_name) self.file_name = os.path.basename(upath.decode(sys.getfilesystemencoding()))
upath = path.encode('utf-8') if isinstance(path, unicode) else path self.log_info(_('Processing %s'), repr(upath) if self.verbose else repr(self.file_name))
if not os.path.exists(upath): if not os.path.exists(upath):
upath = upath.replace('&', '%26') #convertlit replaces & with %26 in file names upath = upath.replace('&', '%26') #convertlit replaces & with %26 in file names
f = open(upath, 'rb') f = open(upath, 'rb')
@ -1799,6 +1800,7 @@ def process_file(path, options, logger=None):
level = logging.DEBUG if options.verbose else logging.INFO level = logging.DEBUG if options.verbose else logging.INFO
logger = logging.getLogger('html2lrf') logger = logging.getLogger('html2lrf')
setup_cli_handlers(logger, level) setup_cli_handlers(logger, level)
if not isinstance(path, unicode): if not isinstance(path, unicode):
path = path.decode(sys.getfilesystemencoding()) path = path.decode(sys.getfilesystemencoding())
path = os.path.abspath(path) path = os.path.abspath(path)