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 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

View File

@ -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

View File

@ -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)