Fix #1169 (any2epub ignores --metadata-from= for lit files)

This commit is contained in:
Kovid Goyal 2008-10-16 17:33:40 -07:00
parent 483ece52ce
commit d0b4cce3cd
2 changed files with 7 additions and 2 deletions

View File

@ -224,6 +224,10 @@ def convert(htmlfile, opts, notification=None):
opts.override_css = open(opts.override_css, 'rb').read().decode(preferred_encoding, 'replace') opts.override_css = open(opts.override_css, 'rb').read().decode(preferred_encoding, 'replace')
except: except:
opts.override_css = opts.override_css.decode(preferred_encoding, 'replace') opts.override_css = opts.override_css.decode(preferred_encoding, 'replace')
if opts.from_opf:
opts.from_opf = os.path.abspath(opts.from_opf)
if opts.from_ncx:
opts.from_ncx = os.path.abspath(opts.from_ncx)
if htmlfile.lower().endswith('.opf'): if htmlfile.lower().endswith('.opf'):
opf = OPF(htmlfile, os.path.dirname(os.path.abspath(htmlfile))) opf = OPF(htmlfile, os.path.dirname(os.path.abspath(htmlfile)))
filelist = opf_traverse(opf, verbose=opts.verbose, encoding=opts.encoding) filelist = opf_traverse(opf, verbose=opts.verbose, encoding=opts.encoding)
@ -233,7 +237,7 @@ def convert(htmlfile, opts, notification=None):
if htmlfile is None: if htmlfile is None:
raise ValueError('Could not find suitable file to convert.') raise ValueError('Could not find suitable file to convert.')
filelist = get_filelist(htmlfile, opts)[1] filelist = get_filelist(htmlfile, opts)[1]
mi = MetaInformation(opf) mi = merge_metadata(None, opf, opts)
else: else:
opf, filelist = get_filelist(htmlfile, opts) opf, filelist = get_filelist(htmlfile, opts)
mi = merge_metadata(htmlfile, opf, opts) mi = merge_metadata(htmlfile, opf, opts)

View File

@ -906,11 +906,12 @@ def merge_metadata(htmlfile, opf, opts):
''' '''
if opf: if opf:
mi = MetaInformation(opf) mi = MetaInformation(opf)
else: elif htmlfile:
try: try:
mi = get_metadata(open(htmlfile, 'rb'), 'html') mi = get_metadata(open(htmlfile, 'rb'), 'html')
except: except:
mi = MetaInformation(None, None) mi = MetaInformation(None, None)
if opts.from_opf is not None and os.access(opts.from_opf, os.R_OK): if opts.from_opf is not None and os.access(opts.from_opf, os.R_OK):
mi.smart_update(OPF(open(opts.from_opf, 'rb'), os.path.abspath(os.path.dirname(opts.from_opf)))) mi.smart_update(OPF(open(opts.from_opf, 'rb'), os.path.abspath(os.path.dirname(opts.from_opf))))
for attr in ('title', 'authors', 'publisher', 'tags', 'comments'): for attr in ('title', 'authors', 'publisher', 'tags', 'comments'):