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()
|
iswindows = 'win32' in sys.platform.lower()
|
||||||
isosx = 'darwin' 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):
|
def extract(path, dir):
|
||||||
import os
|
import os
|
||||||
ext = os.path.splitext(path)[1][1:].lower()
|
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
|
RuledLine, BookSetting
|
||||||
from libprs500.lrf.pylrs.pylrs import Span as _Span
|
from libprs500.lrf.pylrs.pylrs import Span as _Span
|
||||||
from libprs500.lrf import ConversionError, option_parser, Book
|
from libprs500.lrf import ConversionError, option_parser, Book
|
||||||
from libprs500 import extract
|
from libprs500 import extract, filename_to_utf8
|
||||||
from libprs500.ptempfile import PersistentTemporaryFile
|
from libprs500.ptempfile import PersistentTemporaryFile
|
||||||
|
|
||||||
class Span(_Span):
|
class Span(_Span):
|
||||||
@ -1063,7 +1063,7 @@ def main():
|
|||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
src = args[0]
|
src = args[0]
|
||||||
if options.title == None:
|
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)
|
process_file(src, options)
|
||||||
|
|
||||||
def console_query(dirpath, candidate, docs):
|
def console_query(dirpath, candidate, docs):
|
||||||
|
@ -20,7 +20,7 @@ import os, sys
|
|||||||
from libprs500.lrf import ConversionError, option_parser
|
from libprs500.lrf import ConversionError, option_parser
|
||||||
from libprs500.lrf import Book
|
from libprs500.lrf import Book
|
||||||
from libprs500.lrf.pylrs.pylrs import Paragraph, Italic, Bold, BookSetting
|
from libprs500.lrf.pylrs.pylrs import Paragraph, Italic, Bold, BookSetting
|
||||||
|
from libprs500 import filename_to_utf8
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
""" CLI for txt -> lrf conversions """
|
""" CLI for txt -> lrf conversions """
|
||||||
@ -42,7 +42,7 @@ def main():
|
|||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
src = os.path.abspath(os.path.expanduser(args[0]))
|
src = os.path.abspath(os.path.expanduser(args[0]))
|
||||||
if options.title == None:
|
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:
|
try:
|
||||||
convert_txt(src, options)
|
convert_txt(src, options)
|
||||||
except ConversionError, err:
|
except ConversionError, err:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user