mirror of
https://github.com/gryf/ebook-converter.git
synced 2026-04-18 12:03:33 +02:00
Cleanup get_path usage in favor of pkg_resources.
This commit is contained in:
@@ -6,6 +6,7 @@ __copyright__ = '2008, Anatoly Shipitsin <norguhtar at gmail.com>'
|
||||
Convert .fb2 files to .lrf
|
||||
"""
|
||||
import os, re
|
||||
import pkg_resources
|
||||
|
||||
from ebook_converter.customize.conversion import InputFormatPlugin, OptionRecommendation
|
||||
from ebook_converter import guess_type
|
||||
@@ -86,8 +87,9 @@ class FB2Input(InputFormatPlugin):
|
||||
css = re.sub(r'name\s*=\s*', 'class=', css)
|
||||
self.extract_embedded_content(doc)
|
||||
log.debug('Converting XML to HTML...')
|
||||
with open(P('templates/fb2.xsl'), 'rb') as f:
|
||||
ss = f.read().decode('utf-8')
|
||||
with open(pkg_resources.resource_filename('ebook_converter',
|
||||
'data/fb2.xsl')) as f:
|
||||
ss = f.read().decode()
|
||||
ss = ss.replace("__FB_NS__", fb_ns)
|
||||
if options.no_inline_fb2_toc:
|
||||
log('Disabling generation of inline FB2 TOC')
|
||||
|
||||
@@ -6,6 +6,7 @@ __docformat__ = 'restructuredtext en'
|
||||
|
||||
import os, re, shutil
|
||||
from os.path import dirname, abspath, relpath as _relpath, exists, basename
|
||||
import pkg_resources
|
||||
|
||||
from ebook_converter.customize.conversion import OutputFormatPlugin, OptionRecommendation
|
||||
from ebook_converter import CurrentDir
|
||||
@@ -95,19 +96,31 @@ class HTMLOutput(OutputFormatPlugin):
|
||||
with open(opts.template_html_index, 'rb') as f:
|
||||
template_html_index_data = f.read()
|
||||
else:
|
||||
template_html_index_data = P('templates/html_export_default_index.tmpl', data=True)
|
||||
with open(pkg_resources.
|
||||
resource_filename('ebook_converter',
|
||||
'data/html_export_default_index.tmpl')
|
||||
) as fobj:
|
||||
template_html_index_data = fobj.read().decode()
|
||||
|
||||
if opts.template_html is not None:
|
||||
with open(opts.template_html, 'rb') as f:
|
||||
template_html_data = f.read()
|
||||
else:
|
||||
template_html_data = P('templates/html_export_default.tmpl', data=True)
|
||||
with open(pkg_resources.
|
||||
resource_filename('ebook_converter',
|
||||
'data/html_export_default.tmpl')
|
||||
) as fobj:
|
||||
template_html_data = fobj.read().decode()
|
||||
|
||||
if opts.template_css is not None:
|
||||
with open(opts.template_css, 'rb') as f:
|
||||
template_css_data = f.read()
|
||||
else:
|
||||
template_css_data = P('templates/html_export_default.css', data=True)
|
||||
with open(pkg_resources.
|
||||
resource_filename('ebook_converter',
|
||||
'data/html_export_default.css')
|
||||
) as fobj:
|
||||
template_css_data = fobj.read().decode()
|
||||
|
||||
template_html_index_data = template_html_index_data.decode('utf-8')
|
||||
template_html_data = template_html_data.decode('utf-8')
|
||||
|
||||
@@ -7,6 +7,8 @@ __copyright__ = '2009, Kovid Goyal <kovid@kovidgoyal.net>'
|
||||
__docformat__ = 'restructuredtext en'
|
||||
|
||||
import os, sys
|
||||
import pkg_resources
|
||||
|
||||
from ebook_converter.customize.conversion import InputFormatPlugin
|
||||
|
||||
|
||||
@@ -54,7 +56,12 @@ class LRFInput(InputFormatPlugin):
|
||||
plot_map[ro] = imgstr[0].get('file')
|
||||
|
||||
self.log('Converting XML to HTML...')
|
||||
styledoc = safe_xml_fromstring(P('templates/lrf.xsl', data=True))
|
||||
|
||||
with open(pkg_resources.
|
||||
resource_filename('ebook_converter',
|
||||
'data/lrf.xsl')) as fobj:
|
||||
# TODO(gryf): change this nonsense to etree.parse() instead.
|
||||
styledoc = safe_xml_fromstring(fobj.read())
|
||||
media_type = MediaType()
|
||||
styles = Styles()
|
||||
text_block = TextBlock(styles, char_button_map, plot_map, log)
|
||||
|
||||
Reference in New Issue
Block a user