mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Fix handling of filenames that have non ascii characters on systems with encodings other than utf8
This commit is contained in:
parent
65261cb53b
commit
76c0aeb57c
@ -41,6 +41,11 @@ import sys
|
||||
iswindows = 'win32' in sys.platform.lower()
|
||||
isosx = 'darwin' in sys.platform.lower()
|
||||
|
||||
def filename_to_utf8(name):
|
||||
'''Return C{name} encoded in utf8. Unhandled characters are replaced. '''
|
||||
codec = 'cp1252' if iswindows else 'utf8'
|
||||
return name.decode(codec, 'replace').encode('utf8')
|
||||
|
||||
def extract(path, dir):
|
||||
import os
|
||||
ext = os.path.splitext(path)[1][1:].lower()
|
||||
|
@ -40,7 +40,7 @@ from libprs500.lrf.pylrs.pylrs import Paragraph, CR, Italic, ImageStream, TextBl
|
||||
RuledLine, BookSetting
|
||||
from libprs500.lrf.pylrs.pylrs import Span as _Span
|
||||
from libprs500.lrf import ConversionError, option_parser, Book
|
||||
from libprs500 import extract
|
||||
from libprs500 import extract, filename_to_utf8
|
||||
from libprs500.ptempfile import PersistentTemporaryFile
|
||||
|
||||
class Span(_Span):
|
||||
@ -1063,7 +1063,7 @@ def main():
|
||||
sys.exit(1)
|
||||
src = args[0]
|
||||
if options.title == None:
|
||||
options.title = os.path.splitext(os.path.basename(src))[0]
|
||||
options.title = filename_to_utf8(os.path.splitext(os.path.basename(src))[0])
|
||||
process_file(src, options)
|
||||
|
||||
def console_query(dirpath, candidate, docs):
|
||||
|
@ -20,7 +20,7 @@ import os, sys
|
||||
from libprs500.lrf import ConversionError, option_parser
|
||||
from libprs500.lrf import Book
|
||||
from libprs500.lrf.pylrs.pylrs import Paragraph, Italic, Bold, BookSetting
|
||||
|
||||
from libprs500 import filename_to_utf8
|
||||
|
||||
def main():
|
||||
""" CLI for txt -> lrf conversions """
|
||||
@ -42,7 +42,7 @@ def main():
|
||||
sys.exit(1)
|
||||
src = os.path.abspath(os.path.expanduser(args[0]))
|
||||
if options.title == None:
|
||||
options.title = os.path.splitext(os.path.basename(src))[0]
|
||||
options.title = filename_to_utf8(os.path.splitext(os.path.basename(src))[0])
|
||||
try:
|
||||
convert_txt(src, options)
|
||||
except ConversionError, err:
|
||||
|
Loading…
x
Reference in New Issue
Block a user