1
0
mirror of https://github.com/gryf/ebook-converter.git synced 2026-04-20 13:11:27 +02:00

Convert calibre modules to ebook_converter.

Here is the first batch of modules, which are needed for converting
several formats to LRF. Some of the logic has been change, more cleanups
will follow.
This commit is contained in:
2020-04-11 19:33:43 +02:00
parent 69d2e536c5
commit 0f9792df36
252 changed files with 1925 additions and 2344 deletions
+4
View File
@@ -1 +1,5 @@
__pycache__
build/
dist/
sdist/
*.egg-info/
+1 -1
View File
@@ -6,7 +6,7 @@ This is impudent ripoff of the bits from `Calibre project`_, and is aimed only
for converter thing.
My motivation is to have only converter for ebooks run from commandline,
without all of those bells and whistles Calibre have, and with cleanest more
without all of those bells and whistles Calibre has, and with cleanest more
*pythonic* approach.
+13 -14
View File
@@ -1,11 +1,10 @@
from __future__ import unicode_literals, print_function
''' E-book management software'''
__license__ = 'GPL v3'
__copyright__ = '2008, Kovid Goyal <kovid@kovidgoyal.net>'
__docformat__ = 'restructuredtext en'
import sys, os, re, time, random, warnings
from polyglot.builtins import codepoint_to_chr, unicode_type, range, hasenv, native_string_type
from ebook_converter.polyglot.builtins import codepoint_to_chr, unicode_type, range, hasenv, native_string_type
from math import floor
from functools import partial
@@ -16,12 +15,12 @@ try:
except EnvironmentError:
os.chdir(os.path.expanduser('~'))
from calibre.constants import (iswindows, isosx, islinux, isfrozen,
from ebook_converter.constants import (iswindows, isosx, islinux, isfrozen,
isbsd, preferred_encoding, __appname__, __version__, __author__,
win32event, win32api, winerror, fcntl, ispy3,
filesystem_encoding, plugins, config_dir)
from calibre.startup import winutil, winutilerror
from calibre.utils.icu import safe_chr
from ebook_converter.startup import winutil, winutilerror
from ebook_converter.utils.icu import safe_chr
if False:
# Prevent pyflakes from complaining
@@ -163,7 +162,7 @@ def prints(*args, **kwargs):
for i, arg in enumerate(args):
if isinstance(arg, unicode_type):
if iswindows:
from calibre.utils.terminal import Detect
from ebook_converter.utils.terminal import Detect
cs = Detect(file)
if cs.is_console:
cs.write_unicode_text(arg)
@@ -255,19 +254,19 @@ def extract(path, dir):
with open(path, 'rb') as f:
id_ = f.read(3)
if id_ == b'Rar':
from calibre.utils.unrar import extract as rarextract
from ebook_converter.utils.unrar import extract as rarextract
extractor = rarextract
elif id_.startswith(b'PK'):
from calibre.libunzip import extract as zipextract
from ebook_converter.libunzip import extract as zipextract
extractor = zipextract
if extractor is None:
# Fallback to file extension
ext = os.path.splitext(path)[1][1:].lower()
if ext in ['zip', 'cbz', 'epub', 'oebzip']:
from calibre.libunzip import extract as zipextract
from ebook_converter.libunzip import extract as zipextract
extractor = zipextract
elif ext in ['cbr', 'rar']:
from calibre.utils.unrar import extract as rarextract
from ebook_converter.utils.unrar import extract as rarextract
extractor = rarextract
if extractor is None:
raise Exception('Unknown archive type')
@@ -363,7 +362,7 @@ def is_mobile_ua(ua):
def random_user_agent(choose=None, allow_ie=True):
from calibre.utils.random_ua import common_user_agents
from ebook_converter.utils.random_ua import common_user_agents
ua_list = common_user_agents()
ua_list = [x for x in ua_list if not is_mobile_ua(x)]
if not allow_ie:
@@ -380,7 +379,7 @@ def browser(honor_time=True, max_time=2, mobile_browser=False, user_agent=None,
:param max_time: Maximum time in seconds to wait during a refresh request
:param verify_ssl_certificates: If false SSL certificates errors are ignored
'''
from calibre.utils.browser import Browser
from ebook_converter.utils.browser import Browser
opener = Browser(verify_ssl=verify_ssl_certificates)
opener.set_handle_refresh(handle_refresh, max_time=max_time, honor_time=honor_time)
opener.set_handle_robots(False)
@@ -560,7 +559,7 @@ def entity_to_unicode(match, exceptions=[], encoding='cp1252',
return check(bytes(bytearray((num,))).decode(encoding))
except UnicodeDecodeError:
return check(my_unichr(num))
from calibre.ebooks.html_entities import html5_entities
from ebook_converter.ebooks.html_entities import html5_entities
try:
return check(html5_entities[ent])
except KeyError:
@@ -654,7 +653,7 @@ def human_readable(size, sep=' '):
def ipython(user_ns=None):
from calibre.utils.ipython import ipython
from ebook_converter.utils.ipython import ipython
ipython(user_ns=user_ns)
+36 -36
View File
@@ -1,8 +1,7 @@
#!/usr/bin/env python2
# vim:fileencoding=utf-8
# License: GPLv3 Copyright: 2015, Kovid Goyal <kovid at kovidgoyal.net>
from __future__ import print_function, unicode_literals
from polyglot.builtins import map, unicode_type, environ_item, hasenv, getenv, as_unicode, native_string_type
from ebook_converter.polyglot.builtins import map, unicode_type, environ_item, hasenv, getenv, as_unicode, native_string_type
import sys, locale, codecs, os, importlib, collections
__appname__ = 'calibre'
@@ -151,9 +150,9 @@ def cache_dir():
return ans
plugins_loc = sys.extensions_location
if ispy3:
plugins_loc = os.path.join(plugins_loc, '3')
# plugins_loc = sys.extensions_location
# if ispy3:
# plugins_loc = os.path.join(plugins_loc, '3')
# plugins {{{
@@ -163,35 +162,36 @@ class Plugins(collections.Mapping):
def __init__(self):
self._plugins = {}
plugins = [
'pictureflow',
'lzx',
'msdes',
'podofo',
'cPalmdoc',
'progress_indicator',
'chmlib',
'icu',
'speedup',
'html_as_json',
'unicode_names',
'html_syntax_highlighter',
'hyphen',
'freetype',
'imageops',
'hunspell',
'_patiencediff_c',
'bzzdec',
'matcher',
'tokenizer',
'certgen',
'lzma_binding',
]
if not ispy3:
plugins.extend([
'monotonic',
'zlib2',
])
plugins = []
# plugins = [
# 'pictureflow',
# 'lzx',
# 'msdes',
# 'podofo',
# 'cPalmdoc',
# 'progress_indicator',
# 'chmlib',
# 'icu',
# 'speedup',
# 'html_as_json',
# 'unicode_names',
# 'html_syntax_highlighter',
# 'hyphen',
# 'freetype',
# 'imageops',
# 'hunspell',
# '_patiencediff_c',
# 'bzzdec',
# 'matcher',
# 'tokenizer',
# 'certgen',
# 'lzma_binding',
# ]
# if not ispy3:
# plugins.extend([
# 'monotonic',
# 'zlib2',
# ])
if iswindows:
plugins.extend(['winutil', 'wpd', 'winfonts'])
if isosx:
@@ -205,7 +205,7 @@ class Plugins(collections.Mapping):
def load_plugin(self, name):
if name in self._plugins:
return
sys.path.insert(0, plugins_loc)
# sys.path.insert(0, plugins_loc)
try:
del sys.modules[name]
except KeyError:
@@ -220,7 +220,7 @@ class Plugins(collections.Mapping):
except Exception:
plugin_err = as_unicode(native_string_type(err), encoding=preferred_encoding, errors='replace')
self._plugins[name] = p, plugin_err
sys.path.remove(plugins_loc)
# sys.path.remove(plugins_loc)
def __iter__(self):
return iter(self.plugins)
+3 -3
View File
@@ -5,8 +5,8 @@ from __future__ import absolute_import, division, print_function, unicode_litera
__license__ = 'GPL v3'
__copyright__ = '2015, Kovid Goyal <kovid at kovidgoyal.net>'
from css_selectors.parser import parse
from css_selectors.select import Select, INAPPROPRIATE_PSEUDO_CLASSES
from css_selectors.errors import SelectorError, SelectorSyntaxError, ExpressionError
from ebook_converter.css_selectors.parser import parse
from ebook_converter.css_selectors.select import Select, INAPPROPRIATE_PSEUDO_CLASSES
from ebook_converter.css_selectors.errors import SelectorError, SelectorSyntaxError, ExpressionError
__all__ = ['parse', 'Select', 'INAPPROPRIATE_PSEUDO_CLASSES', 'SelectorError', 'SelectorSyntaxError', 'ExpressionError']
+1 -1
View File
@@ -6,7 +6,7 @@ __license__ = 'GPL v3'
__copyright__ = '2015, Kovid Goyal <kovid at kovidgoyal.net>'
import collections
from polyglot.builtins import string_or_bytes
from ebook_converter.polyglot.builtins import string_or_bytes
SLICE_ALL = slice(None)
+2 -2
View File
@@ -14,8 +14,8 @@ import re
import operator
import string
from css_selectors.errors import SelectorSyntaxError, ExpressionError
from polyglot.builtins import unicode_type, codepoint_to_chr, range
from ebook_converter.css_selectors.errors import SelectorSyntaxError, ExpressionError
from ebook_converter.polyglot.builtins import unicode_type, codepoint_to_chr, range
utab = {c:c+32 for c in range(ord(u'A'), ord(u'Z')+1)}
+4 -4
View File
@@ -12,11 +12,11 @@ from itertools import chain
from lxml import etree
from css_selectors.errors import ExpressionError
from css_selectors.parser import parse, ascii_lower, Element, FunctionalPseudoElement
from css_selectors.ordered_set import OrderedSet
from ebook_converter.css_selectors.errors import ExpressionError
from ebook_converter.css_selectors.parser import parse, ascii_lower, Element, FunctionalPseudoElement
from ebook_converter.css_selectors.ordered_set import OrderedSet
from polyglot.builtins import iteritems, itervalues
from ebook_converter.polyglot.builtins import iteritems, itervalues
PARSE_CACHE_SIZE = 200
parse_cache = OrderedDict()
+3 -3
View File
@@ -9,9 +9,9 @@ import unittest, sys, argparse
from lxml import etree, html
from css_selectors.errors import SelectorSyntaxError, ExpressionError
from css_selectors.parser import tokenize, parse
from css_selectors.select import Select
from ebook_converter.css_selectors.errors import SelectorSyntaxError, ExpressionError
from ebook_converter.css_selectors.parser import tokenize, parse
from ebook_converter.css_selectors.select import Select
class TestCSSSelectors(unittest.TestCase):
+17 -17
View File
@@ -4,9 +4,9 @@ __copyright__ = '2008, Kovid Goyal <kovid at kovidgoyal.net>'
import os, sys, zipfile, importlib
from calibre.constants import numeric_version, iswindows, isosx
from calibre.ptempfile import PersistentTemporaryFile
from polyglot.builtins import unicode_type
from ebook_converter.constants import numeric_version, iswindows, isosx
from ebook_converter.ptempfile import PersistentTemporaryFile
from ebook_converter.polyglot.builtins import unicode_type
platform = 'linux'
if iswindows:
@@ -134,7 +134,7 @@ class Plugin(object): # {{{
'''
from PyQt5.Qt import QDialog, QDialogButtonBox, QVBoxLayout, \
QLabel, Qt, QLineEdit
from calibre.gui2 import gprefs
from ebook_converter.gui2 import gprefs
prefname = 'plugin config dialog:'+self.type + ':' + self.name
geom = gprefs.get(prefname, None)
@@ -159,7 +159,7 @@ class Plugin(object): # {{{
config_widget = None
if isinstance(config_widget, tuple):
from calibre.gui2 import warning_dialog
from ebook_converter.gui2 import warning_dialog
warning_dialog(parent, _('Cannot configure'), config_widget[0],
det_msg=config_widget[1], show=True)
return False
@@ -177,7 +177,7 @@ class Plugin(object): # {{{
else:
self.save_settings(config_widget)
else:
from calibre.customize.ui import plugin_customization, \
from ebook_converter.customize.ui import plugin_customization, \
customize_plugin
help_text = self.customization_help(gui=True)
help_text = QLabel(help_text, config_dialog)
@@ -276,7 +276,7 @@ class Plugin(object): # {{{
import something
'''
if self.plugin_path is not None:
from calibre.utils.zipfile import ZipFile
from ebook_converter.utils.zipfile import ZipFile
zf = ZipFile(self.plugin_path)
extensions = {x.rpartition('.')[-1].lower() for x in
zf.namelist()}
@@ -289,7 +289,7 @@ class Plugin(object): # {{{
sys.path.insert(0, self.plugin_path)
self.sys_insertion_path = self.plugin_path
else:
from calibre.ptempfile import TemporaryDirectory
from ebook_converter.ptempfile import TemporaryDirectory
self._sys_insertion_tdir = TemporaryDirectory('plugin_unzip')
self.sys_insertion_path = self._sys_insertion_tdir.__enter__(*args)
zf.extractall(self.sys_insertion_path)
@@ -426,7 +426,7 @@ class MetadataReaderPlugin(Plugin): # {{{
:param type: The type of file. Guaranteed to be one of the entries
in :attr:`file_types`.
:return: A :class:`calibre.ebooks.metadata.book.Metadata` object
:return: A :class:`ebook_converter.ebooks.metadata.book.Metadata` object
'''
return None
# }}}
@@ -458,7 +458,7 @@ class MetadataWriterPlugin(Plugin): # {{{
:param type: The type of file. Guaranteed to be one of the entries
in :attr:`file_types`.
:param mi: A :class:`calibre.ebooks.metadata.book.Metadata` object
:param mi: A :class:`ebook_converter.ebooks.metadata.book.Metadata` object
'''
pass
@@ -484,7 +484,7 @@ class CatalogPlugin(Plugin): # {{{
#: Option = namedtuple('Option', 'option, default, dest, help')
#: cli_options = [Option('--catalog-title', default = 'My Catalog',
#: dest = 'catalog_title', help = (_('Title of generated catalog. \nDefault:') + " '" + '%default' + "'"))]
#: cli_options parsed in calibre.db.cli.cmd_catalog:option_parser()
#: cli_options parsed in ebook_converter.db.cli.cmd_catalog:option_parser()
#:
cli_options = []
@@ -526,7 +526,7 @@ class CatalogPlugin(Plugin): # {{{
# Validate requested_fields
if requested_fields - all_fields:
from calibre.library import current_library_name
from ebook_converter.library import current_library_name
invalid_fields = sorted(list(requested_fields - all_fields))
print("invalid --fields specified: %s" % ', '.join(invalid_fields))
print("available fields in '%s': %s" %
@@ -547,11 +547,11 @@ class CatalogPlugin(Plugin): # {{{
If plugin is not a built-in, copy the plugin's .ui and .py files from
the ZIP file to $TMPDIR.
Tab will be dynamically generated and added to the Catalog Options dialog in
calibre.gui2.dialogs.catalog.py:Catalog
ebook_converter.gui2.dialogs.catalog.py:Catalog
'''
from calibre.customize.builtins import plugins as builtin_plugins
from calibre.customize.ui import config
from calibre.ptempfile import PersistentTemporaryDirectory
from ebook_converter.customize.builtins import plugins as builtin_plugins
from ebook_converter.customize.ui import config
from ebook_converter.ptempfile import PersistentTemporaryDirectory
if not type(self) in builtin_plugins and self.name not in config['disabled_plugins']:
files_to_copy = ["%s.%s" % (self.name.lower(),ext) for ext in ["ui","py"]]
@@ -663,7 +663,7 @@ class PreferencesPlugin(Plugin): # {{{
'''
Create and return the actual Qt widget used for setting this group of
preferences. The widget must implement the
:class:`calibre.gui2.preferences.ConfigWidgetInterface`.
:class:`ebook_converter.gui2.preferences.ConfigWidgetInterface`.
The default implementation uses :attr:`config_widget` to instantiate
the widget.
File diff suppressed because it is too large Load Diff
+5 -5
View File
@@ -5,9 +5,9 @@ Defines the plugin system for conversions.
'''
import re, os, shutil, numbers
from calibre import CurrentDir
from calibre.customize import Plugin
from polyglot.builtins import unicode_type
from ebook_converter import CurrentDir
from ebook_converter.customize import Plugin
from ebook_converter.polyglot.builtins import unicode_type
class ConversionOption(object):
@@ -106,7 +106,7 @@ def gui_configuration_widget(name, parent, get_option_by_name,
if for_output:
try:
output_widget = importlib.import_module(
'calibre.gui2.convert.'+name)
'ebook_converter.gui2.convert.'+name)
pw = output_widget.PluginWidget
pw.ICON = I('back.png')
pw.HELP = _('Options specific to the output format.')
@@ -116,7 +116,7 @@ def gui_configuration_widget(name, parent, get_option_by_name,
else:
try:
input_widget = importlib.import_module(
'calibre.gui2.convert.'+name)
'ebook_converter.gui2.convert.'+name)
pw = input_widget.PluginWidget
pw.ICON = I('forward.png')
pw.HELP = _('Options specific to the input format.')
+2 -2
View File
@@ -4,8 +4,8 @@ __license__ = 'GPL 3'
__copyright__ = '2009, Kovid Goyal <kovid@kovidgoyal.net>'
__docformat__ = 'restructuredtext en'
from calibre.customize import Plugin as _Plugin
from polyglot.builtins import zip
from ebook_converter.customize import Plugin as _Plugin
from ebook_converter.polyglot.builtins import zip
FONT_SIZES = [('xx-small', 1),
('x-small', None),
+15 -15
View File
@@ -6,23 +6,23 @@ import os, shutil, traceback, functools, sys
from collections import defaultdict
from itertools import chain
from calibre.customize import (CatalogPlugin, FileTypePlugin, PluginNotFound,
from ebook_converter.customize import (CatalogPlugin, FileTypePlugin, PluginNotFound,
MetadataReaderPlugin, MetadataWriterPlugin,
InterfaceActionBase as InterfaceAction,
PreferencesPlugin, platform, InvalidPlugin,
StoreBase as Store, EditBookToolPlugin,
LibraryClosedPlugin)
from calibre.customize.conversion import InputFormatPlugin, OutputFormatPlugin
from calibre.customize.zipplugin import loader
from calibre.customize.profiles import InputProfile, OutputProfile
from calibre.customize.builtins import plugins as builtin_plugins
from calibre.devices.interface import DevicePlugin
from calibre.ebooks.metadata import MetaInformation
from calibre.utils.config import (make_config_dir, Config, ConfigProxy,
from ebook_converter.customize.conversion import InputFormatPlugin, OutputFormatPlugin
from ebook_converter.customize.zipplugin import loader
from ebook_converter.customize.profiles import InputProfile, OutputProfile
from ebook_converter.customize.builtins import plugins as builtin_plugins
# from ebook_converter.devices.interface import DevicePlugin
from ebook_converter.ebooks.metadata import MetaInformation
from ebook_converter.utils.config import (make_config_dir, Config, ConfigProxy,
plugin_dir, OptionParser)
from calibre.ebooks.metadata.sources.base import Source
from calibre.constants import DEBUG, numeric_version
from polyglot.builtins import iteritems, itervalues, unicode_type
# from ebook_converter.ebooks.metadata.sources.base import Source
from ebook_converter.constants import DEBUG, numeric_version
from ebook_converter.polyglot.builtins import iteritems, itervalues, unicode_type
builtin_names = frozenset(p.name for p in builtin_plugins)
BLACKLISTED_PLUGINS = frozenset({'Marvin XD', 'iOS reader applications'})
@@ -448,7 +448,7 @@ def set_file_type_metadata(stream, mi, ftype, report_error=None):
break
except:
if report_error is None:
from calibre import prints
from ebook_converter import prints
prints('Failed to set metadata for the', ftype.upper(), 'format of:', getattr(mi, 'title', ''), file=sys.stderr)
traceback.print_exc()
else:
@@ -737,9 +737,9 @@ def initialized_plugins():
def build_plugin(path):
from calibre import prints
from calibre.ptempfile import PersistentTemporaryFile
from calibre.utils.zipfile import ZipFile, ZIP_STORED
from ebook_converter import prints
from ebook_converter.ptempfile import PersistentTemporaryFile
from ebook_converter.utils.zipfile import ZipFile, ZIP_STORED
path = unicode_type(path)
names = frozenset(os.listdir(path))
if '__init__.py' not in names:
+7 -7
View File
@@ -10,11 +10,11 @@ import os, zipfile, posixpath, importlib, threading, re, imp, sys
from collections import OrderedDict
from functools import partial
from calibre import as_unicode
from calibre.constants import ispy3
from calibre.customize import (Plugin, numeric_version, platform,
from ebook_converter import as_unicode
from ebook_converter.constants import ispy3
from ebook_converter.customize import (Plugin, numeric_version, platform,
InvalidPlugin, PluginNotFound)
from polyglot.builtins import (itervalues, map, string_or_bytes,
from ebook_converter.polyglot.builtins import (itervalues, map, string_or_bytes,
unicode_type, reload)
# PEP 302 based plugin loading mechanism, works around the bug in zipimport in
@@ -94,7 +94,7 @@ def load_translations(namespace, zfp):
if trans is None:
return
if trans is null:
from calibre.utils.localization import get_lang
from ebook_converter.utils.localization import get_lang
lang = get_lang()
if not lang or lang == 'en': # performance optimization
_translations_cache[zfp] = None
@@ -303,8 +303,8 @@ sys.meta_path.insert(0, loader)
if __name__ == '__main__':
from tempfile import NamedTemporaryFile
from calibre.customize.ui import add_plugin
from calibre import CurrentDir
from ebook_converter.customize.ui import add_plugin
from ebook_converter import CurrentDir
path = sys.argv[-1]
with NamedTemporaryFile(suffix='.zip') as f:
with zipfile.ZipFile(f, 'w') as zf:
-216
View File
@@ -1,216 +0,0 @@
from __future__ import absolute_import, division, print_function, unicode_literals
__license__ = 'GPL v3'
__copyright__ = '2008, Kovid Goyal <kovid at kovidgoyal.net>'
'''
Device drivers.
'''
import sys, time, pprint
from functools import partial
from polyglot.builtins import zip, unicode_type
DAY_MAP = dict(Sun=0, Mon=1, Tue=2, Wed=3, Thu=4, Fri=5, Sat=6)
MONTH_MAP = dict(Jan=1, Feb=2, Mar=3, Apr=4, May=5, Jun=6, Jul=7, Aug=8, Sep=9, Oct=10, Nov=11, Dec=12)
INVERSE_DAY_MAP = dict(zip(DAY_MAP.values(), DAY_MAP.keys()))
INVERSE_MONTH_MAP = dict(zip(MONTH_MAP.values(), MONTH_MAP.keys()))
def strptime(src):
src = src.strip()
src = src.split()
src[0] = unicode_type(DAY_MAP[src[0][:-1]])+','
src[2] = unicode_type(MONTH_MAP[src[2]])
return time.strptime(' '.join(src), '%w, %d %m %Y %H:%M:%S %Z')
def strftime(epoch, zone=time.gmtime):
src = time.strftime("%w, %d %m %Y %H:%M:%S GMT", zone(epoch)).split()
src[0] = INVERSE_DAY_MAP[int(src[0][:-1])]+','
src[2] = INVERSE_MONTH_MAP[int(src[2])]
return ' '.join(src)
def get_connected_device():
from calibre.customize.ui import device_plugins
from calibre.devices.scanner import DeviceScanner
dev = None
scanner = DeviceScanner()
scanner.scan()
connected_devices = []
for d in device_plugins():
ok, det = scanner.is_device_connected(d)
if ok:
dev = d
dev.reset(log_packets=False, detected_device=det)
connected_devices.append((det, dev))
if dev is None:
print('Unable to find a connected ebook reader.', file=sys.stderr)
return
for det, d in connected_devices:
try:
d.open(det, None)
except:
continue
else:
dev = d
break
return dev
def debug(ioreg_to_tmp=False, buf=None, plugins=None,
disabled_plugins=None):
'''
If plugins is None, then this method calls startup and shutdown on the
device plugins. So if you are using it in a context where startup could
already have been called (for example in the main GUI), pass in the list of
device plugins as the plugins parameter.
'''
import textwrap
from calibre.customize.ui import device_plugins, disabled_device_plugins
from calibre.debug import print_basic_debug_info
from calibre.devices.scanner import DeviceScanner
from calibre.constants import iswindows, isosx
from calibre import prints
from polyglot.io import PolyglotBytesIO
oldo, olde = sys.stdout, sys.stderr
if buf is None:
buf = PolyglotBytesIO()
sys.stdout = sys.stderr = buf
out = partial(prints, file=buf)
devplugins = device_plugins() if plugins is None else plugins
devplugins = list(sorted(devplugins, key=lambda x: x.__class__.__name__))
if plugins is None:
for d in devplugins:
try:
d.startup()
except:
out('Startup failed for device plugin: %s'%d)
if disabled_plugins is None:
disabled_plugins = list(disabled_device_plugins())
try:
print_basic_debug_info(out=buf)
s = DeviceScanner()
s.scan()
devices = (s.devices)
if not iswindows:
devices = [list(x) for x in devices]
for d in devices:
for i in range(3):
d[i] = hex(d[i])
out('USB devices on system:')
out(pprint.pformat(devices))
ioreg = None
if isosx:
from calibre.devices.usbms.device import Device
mount = '\n'.join(repr(x) for x in Device.osx_run_mount().splitlines())
drives = pprint.pformat(Device.osx_get_usb_drives())
ioreg = 'Output from mount:\n'+mount+'\n\n'
ioreg += 'Output from osx_get_usb_drives:\n'+drives+'\n\n'
ioreg += Device.run_ioreg()
connected_devices = []
if disabled_plugins:
out('\nDisabled plugins:', textwrap.fill(' '.join([x.__class__.__name__ for x in
disabled_plugins])))
out(' ')
else:
out('\nNo disabled plugins')
found_dev = False
for dev in devplugins:
if not dev.MANAGES_DEVICE_PRESENCE:
continue
out('Looking for devices of type:', dev.__class__.__name__)
if dev.debug_managed_device_detection(s.devices, buf):
found_dev = True
break
out(' ')
if not found_dev:
out('Looking for devices...')
for dev in devplugins:
if dev.MANAGES_DEVICE_PRESENCE:
continue
connected, det = s.is_device_connected(dev, debug=True)
if connected:
out('\t\tDetected possible device', dev.__class__.__name__)
connected_devices.append((dev, det))
out(' ')
errors = {}
success = False
out('Devices possibly connected:', end=' ')
for dev, det in connected_devices:
out(dev.name, end=', ')
if not connected_devices:
out('None', end='')
out(' ')
for dev, det in connected_devices:
out('Trying to open', dev.name, '...', end=' ')
dev.do_device_debug = True
try:
dev.reset(detected_device=det)
dev.open(det, None)
out('OK')
except:
import traceback
errors[dev] = traceback.format_exc()
out('failed')
continue
dev.do_device_debug = False
success = True
if hasattr(dev, '_main_prefix'):
out('Main memory:', repr(dev._main_prefix))
out('Total space:', dev.total_space())
break
if not success and errors:
out('Opening of the following devices failed')
for dev,msg in errors.items():
out(dev)
out(msg)
out(' ')
if ioreg is not None:
ioreg = 'IOREG Output\n'+ioreg
out(' ')
if ioreg_to_tmp:
lopen('/tmp/ioreg.txt', 'wb').write(ioreg)
out('Dont forget to send the contents of /tmp/ioreg.txt')
out('You can open it with the command: open /tmp/ioreg.txt')
else:
out(ioreg)
if hasattr(buf, 'getvalue'):
return buf.getvalue().decode('utf-8', 'replace')
finally:
sys.stdout = oldo
sys.stderr = olde
if plugins is None:
for d in devplugins:
try:
d.shutdown()
except:
pass
def device_info(ioreg_to_tmp=False, buf=None):
from calibre.devices.scanner import DeviceScanner
res = {}
res['device_set'] = device_set = set()
res['device_details'] = device_details = {}
s = DeviceScanner()
s.scan()
devices = s.devices
devices = [tuple(x) for x in devices]
for dev in devices:
device_set.add(dev)
device_details[dev] = dev[0:3]
return res
+3 -3
View File
@@ -5,9 +5,9 @@ __copyright__ = '2008, Kovid Goyal <kovid at kovidgoyal.net>'
import os
from collections import namedtuple
from calibre import prints
from calibre.constants import iswindows
from calibre.customize import Plugin
from ebook_converter import prints
from ebook_converter.constants import iswindows
from ebook_converter.customize import Plugin
class DevicePlugin(Plugin):
+3 -3
View File
@@ -10,12 +10,12 @@ from bs4 import ( # noqa
SoupStrainer, Tag, __version__
)
from polyglot.builtins import unicode_type
from ebook_converter.polyglot.builtins import unicode_type
def parse_html(markup):
from calibre.ebooks.chardet import strip_encoding_declarations, xml_to_unicode, substitute_entites
from calibre.utils.cleantext import clean_xml_chars
from ebook_converter.ebooks.chardet import strip_encoding_declarations, xml_to_unicode, substitute_entites
from ebook_converter.utils.cleantext import clean_xml_chars
if isinstance(markup, unicode_type):
markup = strip_encoding_declarations(markup)
markup = substitute_entites(markup)
+15 -17
View File
@@ -1,5 +1,3 @@
from __future__ import absolute_import, division, print_function, unicode_literals
__license__ = 'GPL v3'
__copyright__ = '2008, Kovid Goyal <kovid at kovidgoyal.net>'
@@ -9,9 +7,9 @@ from various formats.
'''
import os, re, numbers, sys
from calibre import prints
from calibre.ebooks.chardet import xml_to_unicode
from polyglot.builtins import unicode_type
from ebook_converter import prints
from ebook_converter.ebooks.chardet import xml_to_unicode
from ebook_converter.polyglot.builtins import unicode_type
class ConversionError(Exception):
@@ -42,7 +40,7 @@ BOOK_EXTENSIONS = ['lrf', 'rar', 'zip', 'rtf', 'lit', 'txt', 'txtz', 'text', 'ht
def return_raster_image(path):
from calibre.utils.imghdr import what
from ebook_converter.utils.imghdr import what
if os.access(path, os.R_OK):
with open(path, 'rb') as f:
raw = f.read()
@@ -51,8 +49,8 @@ def return_raster_image(path):
def extract_cover_from_embedded_svg(html, base, log):
from calibre.ebooks.oeb.base import XPath, SVG, XLINK
from calibre.utils.xml_parse import safe_xml_fromstring
from ebook_converter.ebooks.oeb.base import XPath, SVG, XLINK
from ebook_converter.utils.xml_parse import safe_xml_fromstring
root = safe_xml_fromstring(html)
svg = XPath('//svg:svg')(root)
@@ -65,7 +63,7 @@ def extract_cover_from_embedded_svg(html, base, log):
def extract_calibre_cover(raw, base, log):
from calibre.ebooks.BeautifulSoup import BeautifulSoup
from ebook_converter.ebooks.BeautifulSoup import BeautifulSoup
soup = BeautifulSoup(raw)
matches = soup.find(name=['h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'p', 'span',
'font', 'br'])
@@ -93,7 +91,7 @@ def extract_calibre_cover(raw, base, log):
def render_html_svg_workaround(path_to_html, log, width=590, height=750):
from calibre.ebooks.oeb.base import SVG_NS
from ebook_converter.ebooks.oeb.base import SVG_NS
with open(path_to_html, 'rb') as f:
raw = f.read()
raw = xml_to_unicode(raw, strip_encoding_pats=True)[0]
@@ -116,8 +114,8 @@ def render_html_svg_workaround(path_to_html, log, width=590, height=750):
def render_html_data(path_to_html, width, height):
from calibre.ptempfile import TemporaryDirectory
from calibre.utils.ipc.simple_worker import fork_job, WorkerError
from ebook_converter.ptempfile import TemporaryDirectory
from ebook_converter.utils.ipc.simple_worker import fork_job, WorkerError
result = {}
def report_error(text=''):
@@ -130,7 +128,7 @@ def render_html_data(path_to_html, width, height):
with TemporaryDirectory('-render-html') as tdir:
try:
result = fork_job('calibre.ebooks.render_html', 'main', args=(path_to_html, tdir, 'jpeg'))
result = fork_job('ebook_converter.ebooks.render_html', 'main', args=(path_to_html, tdir, 'jpeg'))
except WorkerError as e:
report_error(e.orig_tb)
else:
@@ -163,8 +161,8 @@ def calibre_cover(title, author_string, series_string=None,
title = normalize(title)
author_string = normalize(author_string)
series_string = normalize(series_string)
from calibre.ebooks.covers import calibre_cover2
from calibre.utils.img import image_to_data
from ebook_converter.ebooks.covers import calibre_cover2
from ebook_converter.utils.img import image_to_data
ans = calibre_cover2(title, author_string or '', series_string or '', logo_path=logo_path, as_qimage=True)
return image_to_data(ans, fmt=output_format)
@@ -226,10 +224,10 @@ def parse_css_length(value):
def generate_masthead(title, output_path=None, width=600, height=60):
from calibre.ebooks.conversion.config import load_defaults
from ebook_converter.ebooks.conversion.config import load_defaults
recs = load_defaults('mobi_output')
masthead_font_family = recs.get('masthead_font', None)
from calibre.ebooks.covers import generate_masthead
from ebook_converter.ebooks.covers import generate_masthead
return generate_masthead(title, output_path=output_path, width=width, height=height, font_family=masthead_font_family)
+3 -3
View File
@@ -7,7 +7,7 @@ __copyright__ = '2009, Kovid Goyal <kovid@kovidgoyal.net>'
__docformat__ = 'restructuredtext en'
import re, codecs
from polyglot.builtins import unicode_type
from ebook_converter.polyglot.builtins import unicode_type
_encoding_pats = (
# XML declaration
@@ -98,7 +98,7 @@ def find_declared_encoding(raw, limit=50*1024):
def substitute_entites(raw):
from calibre import xml_entity_to_unicode
from ebook_converter import xml_entity_to_unicode
return ENTITY_PATTERN.sub(xml_entity_to_unicode, raw)
@@ -112,7 +112,7 @@ def detect(*args, **kwargs):
def force_encoding(raw, verbose, assume_utf8=False):
from calibre.constants import preferred_encoding
from ebook_converter.constants import preferred_encoding
try:
chardet = detect(raw[:1024*50])
@@ -1,6 +0,0 @@
# -*- coding: utf-8 -*-
from __future__ import absolute_import, division, print_function, unicode_literals
__license__ = 'GPL 3'
__copyright__ = '2009, John Schember <john@nachtimwald.com>'
__docformat__ = 'restructuredtext en'
+2 -2
View File
@@ -219,11 +219,11 @@ static struct PyModuleDef cPalmdoc_module = {
/* m_clear */ 0,
/* m_free */ 0,
};
CALIBRE_MODINIT_FUNC PyInit_cPalmdoc(void) {
PyObject* PyInit_cPalmdoc(void) {
#else
#define INITERROR return
#define INITMODULE Py_InitModule3("cPalmdoc", cPalmdoc_methods, cPalmdoc_doc)
CALIBRE_MODINIT_FUNC initcPalmdoc(void) {
PyObject* initcPalmdoc(void) {
#endif
PyObject *m;
@@ -8,12 +8,13 @@ __copyright__ = '2008, Kovid Goyal <kovid at kovidgoyal.net>'
import io
from struct import pack
from calibre.constants import plugins
from polyglot.builtins import range
cPalmdoc = plugins['cPalmdoc'][0]
if not cPalmdoc:
raise RuntimeError(('Failed to load required cPalmdoc module: '
'%s')%plugins['cPalmdoc'][1])
from ebook_converter.constants import plugins
from ebook_converter.ebooks.compression import cPalmdoc
from ebook_converter.polyglot.builtins import range
#cPalmdoc = plugins['cPalmdoc'][0]
#if not cPalmdoc:
# raise RuntimeError(('Failed to load required cPalmdoc module: '
# '%s')%plugins['cPalmdoc'][1])
def decompress_doc(data):
@@ -5,7 +5,7 @@ __license__ = 'GPL v3'
__copyright__ = '2011, Kovid Goyal <kovid@kovidgoyal.net>'
__docformat__ = 'restructuredtext en'
from polyglot.builtins import native_string_type
from ebook_converter.polyglot.builtins import native_string_type
class ConversionUserFeedBack(Exception):
@@ -27,4 +27,4 @@ class ConversionUserFeedBack(Exception):
# Ensure exception uses fully qualified name as this is used to detect it in
# the GUI.
ConversionUserFeedBack.__name__ = native_string_type('calibre.ebooks.conversion.ConversionUserFeedBack')
ConversionUserFeedBack.__name__ = native_string_type('ebook_converter.ebooks.conversion.ConversionUserFeedBack')
+11 -11
View File
@@ -12,13 +12,13 @@ import sys, os, numbers
from optparse import OptionGroup, Option
from collections import OrderedDict
from calibre.utils.config import OptionParser
from calibre.utils.logging import Log
from calibre.customize.conversion import OptionRecommendation
from calibre import patheq
from calibre.ebooks.conversion import ConversionUserFeedBack
from calibre.utils.localization import localize_user_manual_link
from polyglot.builtins import iteritems
from ebook_converter.utils.config import OptionParser
from ebook_converter.utils.logging import Log
from ebook_converter.customize.conversion import OptionRecommendation
from ebook_converter import patheq
from ebook_converter.ebooks.conversion import ConversionUserFeedBack
from ebook_converter.utils.localization import localize_user_manual_link
from ebook_converter.polyglot.builtins import iteritems
USAGE = '%prog ' + _('''\
input_file output_file [options]
@@ -290,12 +290,12 @@ class ProgressBar(object):
def create_option_parser(args, log):
if '--version' in args:
from calibre.constants import __appname__, __version__, __author__
from ebook_converter.constants import __appname__, __version__, __author__
log(os.path.basename(args[0]), '('+__appname__, __version__+')')
log('Created by:', __author__)
raise SystemExit(0)
if '--list-recipes' in args:
from calibre.web.feeds.recipes.collection import get_builtin_recipe_titles
from ebook_converter.web.feeds.recipes.collection import get_builtin_recipe_titles
log('Available recipes:')
titles = sorted(get_builtin_recipe_titles())
for title in titles:
@@ -316,7 +316,7 @@ def create_option_parser(args, log):
input, output = check_command_line_options(parser, args, log)
from calibre.ebooks.conversion.plumber import Plumber
from ebook_converter.ebooks.conversion.plumber import Plumber
reporter = ProgressBar(log)
if patheq(input, output):
@@ -380,7 +380,7 @@ def main(args=sys.argv):
if opts.search_replace:
opts.search_replace = read_sr_patterns(opts.search_replace, log)
if opts.transform_css_rules:
from calibre.ebooks.css_transform_rules import import_rules, validate_rule
from ebook_converter.ebooks.css_transform_rules import import_rules, validate_rule
with open(opts.transform_css_rules, 'rb') as tcr:
opts.transform_css_rules = rules = list(import_rules(tcr.read()))
for rule in rules:
@@ -1,10 +0,0 @@
#!/usr/bin/env python2
# vim:fileencoding=UTF-8:ts=4:sw=4:sta:et:sts=4:ai
from __future__ import absolute_import, division, print_function, unicode_literals
__license__ = 'GPL v3'
__copyright__ = '2012, Kovid Goyal <kovid@kovidgoyal.net>'
__docformat__ = 'restructuredtext en'
@@ -5,8 +5,8 @@ __license__ = 'GPL v3'
__copyright__ = '2011, John Schember <john@nachtimwald.com>'
__docformat__ = 'restructuredtext en'
from calibre.customize.conversion import InputFormatPlugin
from polyglot.builtins import getcwd
from ebook_converter.customize.conversion import InputFormatPlugin
from ebook_converter.polyglot.builtins import getcwd
class AZW4Input(InputFormatPlugin):
@@ -19,8 +19,8 @@ class AZW4Input(InputFormatPlugin):
def convert(self, stream, options, file_ext, log,
accelerators):
from calibre.ebooks.pdb.header import PdbHeaderReader
from calibre.ebooks.azw4.reader import Reader
from ebook_converter.ebooks.pdb.header import PdbHeaderReader
from ebook_converter.ebooks.azw4.reader import Reader
header = PdbHeaderReader(stream)
reader = Reader(header, stream, log, options)
@@ -7,10 +7,10 @@ __copyright__ = '2008, Kovid Goyal <kovid at kovidgoyal.net>,' \
import os
from calibre.customize.conversion import InputFormatPlugin
from calibre.ptempfile import TemporaryDirectory
from calibre.constants import filesystem_encoding
from polyglot.builtins import unicode_type, as_bytes
from ebook_converter.customize.conversion import InputFormatPlugin
from ebook_converter.ptempfile import TemporaryDirectory
from ebook_converter.constants import filesystem_encoding
from ebook_converter.polyglot.builtins import unicode_type, as_bytes
class CHMInput(InputFormatPlugin):
@@ -22,7 +22,7 @@ class CHMInput(InputFormatPlugin):
commit_name = 'chm_input'
def _chmtohtml(self, output_dir, chm_path, no_images, log, debug_dump=False):
from calibre.ebooks.chm.reader import CHMReader
from ebook_converter.ebooks.chm.reader import CHMReader
log.debug('Opening CHM file')
rdr = CHMReader(chm_path, log, input_encoding=self.opts.input_encoding)
log.debug('Extracting CHM to %s' % output_dir)
@@ -31,8 +31,8 @@ class CHMInput(InputFormatPlugin):
return rdr.hhc_path
def convert(self, stream, options, file_ext, log, accelerators):
from calibre.ebooks.chm.metadata import get_metadata_from_reader
from calibre.customize.ui import plugin_for_input_format
from ebook_converter.ebooks.chm.metadata import get_metadata_from_reader
from ebook_converter.customize.ui import plugin_for_input_format
self.opts = options
log.debug('Processing CHM...')
@@ -62,12 +62,12 @@ class CHMInput(InputFormatPlugin):
metadata = get_metadata_from_reader(self._chm_reader)
except Exception:
log.exception('Failed to read metadata, using filename')
from calibre.ebooks.metadata.book.base import Metadata
from ebook_converter.ebooks.metadata.book.base import Metadata
metadata = Metadata(os.path.basename(chm_name))
encoding = self._chm_reader.get_encoding() or options.input_encoding or 'cp1252'
self._chm_reader.CloseCHM()
# print((tdir, mainpath))
# from calibre import ipython
# from ebook_converter import ipython
# ipython()
options.debug_pipeline = None
@@ -85,7 +85,7 @@ class CHMInput(InputFormatPlugin):
return oeb
def parse_html_toc(self, item):
from calibre.ebooks.oeb.base import TOC, XPath
from ebook_converter.ebooks.oeb.base import TOC, XPath
dx = XPath('./h:div')
ax = XPath('./h:a[1]')
@@ -102,7 +102,7 @@ class CHMInput(InputFormatPlugin):
def _create_oebbook_html(self, htmlpath, basedir, opts, log, mi):
# use HTMLInput plugin to generate book
from calibre.customize.builtins import HTMLInput
from ebook_converter.customize.builtins import HTMLInput
opts.breadth_first = True
htmlinput = HTMLInput(None)
oeb = htmlinput.create_oebbook(htmlpath, basedir, opts, log, mi)
@@ -110,9 +110,9 @@ class CHMInput(InputFormatPlugin):
def _create_html_root(self, hhcpath, log, encoding):
from lxml import html
from polyglot.urllib import unquote as _unquote
from calibre.ebooks.oeb.base import urlquote
from calibre.ebooks.chardet import xml_to_unicode
from ebook_converter.polyglot.urllib import unquote as _unquote
from ebook_converter.ebooks.oeb.base import urlquote
from ebook_converter.ebooks.chardet import xml_to_unicode
hhcdata = self._read_file(hhcpath)
hhcdata = hhcdata.decode(encoding)
hhcdata = xml_to_unicode(hhcdata, verbose=True,
@@ -179,7 +179,7 @@ class CHMInput(InputFormatPlugin):
return data
def add_node(self, node, toc, ancestor_map):
from calibre.ebooks.chm.reader import match_string
from ebook_converter.ebooks.chm.reader import match_string
if match_string(node.attrib.get('type', ''), 'text/sitemap'):
p = node.xpath('ancestor::ul[1]/ancestor::li[1]/object[1]')
parent = p[0] if p else None
@@ -194,7 +194,7 @@ class CHMInput(InputFormatPlugin):
ancestor_map[node] = child
def _process_nodes(self, root):
from calibre.ebooks.oeb.base import TOC
from ebook_converter.ebooks.oeb.base import TOC
toc = TOC()
ancestor_map = {}
for node in root.xpath('//object'):
@@ -10,10 +10,10 @@ Based on ideas from comiclrf created by FangornUK.
import shutil, textwrap, codecs, os
from calibre.customize.conversion import InputFormatPlugin, OptionRecommendation
from calibre import CurrentDir
from calibre.ptempfile import PersistentTemporaryDirectory
from polyglot.builtins import getcwd, map
from ebook_converter.customize.conversion import InputFormatPlugin, OptionRecommendation
from ebook_converter import CurrentDir
from ebook_converter.ptempfile import PersistentTemporaryDirectory
from ebook_converter.polyglot.builtins import getcwd, map
class ComicInput(InputFormatPlugin):
@@ -93,7 +93,7 @@ class ComicInput(InputFormatPlugin):
}
def get_comics_from_collection(self, stream):
from calibre.libunzip import extract as zipextract
from ebook_converter.libunzip import extract as zipextract
tdir = PersistentTemporaryDirectory('_comic_collection')
zipextract(stream, tdir)
comics = []
@@ -129,7 +129,7 @@ class ComicInput(InputFormatPlugin):
return comics
def get_pages(self, comic, tdir2):
from calibre.ebooks.comic.input import (extract_comic, process_pages,
from ebook_converter.ebooks.comic.input import (extract_comic, process_pages,
find_pages)
tdir = extract_comic(comic)
new_pages = find_pages(tdir, sort_on_mtime=self.opts.no_sort,
@@ -165,9 +165,9 @@ class ComicInput(InputFormatPlugin):
return self._images
def convert(self, stream, opts, file_ext, log, accelerators):
from calibre.ebooks.metadata import MetaInformation
from calibre.ebooks.metadata.opf2 import OPFCreator
from calibre.ebooks.metadata.toc import TOC
from ebook_converter.ebooks.metadata import MetaInformation
from ebook_converter.ebooks.metadata.opf2 import OPFCreator
from ebook_converter.ebooks.metadata.toc import TOC
self.opts, self.log= opts, log
if file_ext == 'cbc':
@@ -245,7 +245,7 @@ class ComicInput(InputFormatPlugin):
return os.path.abspath('metadata.opf')
def create_wrappers(self, pages):
from calibre.ebooks.oeb.base import XHTML_NS
from ebook_converter.ebooks.oeb.base import XHTML_NS
wrappers = []
WRAPPER = textwrap.dedent('''\
<html xmlns="%s">
@@ -275,7 +275,7 @@ class ComicInput(InputFormatPlugin):
return wrappers
def create_viewer_wrapper(self, pages):
from calibre.ebooks.oeb.base import XHTML_NS
from ebook_converter.ebooks.oeb.base import XHTML_NS
def page(src):
return '<img src="{}"></img>'.format(os.path.basename(src))
@@ -9,8 +9,8 @@ __docformat__ = 'restructuredtext en'
import os
from io import BytesIO
from calibre.customize.conversion import InputFormatPlugin
from polyglot.builtins import getcwd
from ebook_converter.customize.conversion import InputFormatPlugin
from ebook_converter.polyglot.builtins import getcwd
class DJVUInput(InputFormatPlugin):
@@ -22,10 +22,10 @@ class DJVUInput(InputFormatPlugin):
commit_name = 'djvu_input'
def convert(self, stream, options, file_ext, log, accelerators):
from calibre.ebooks.txt.processor import convert_basic
from ebook_converter.ebooks.txt.processor import convert_basic
stdout = BytesIO()
from calibre.ebooks.djvu.djvu import DJVUFile
from ebook_converter.ebooks.djvu.djvu import DJVUFile
x = DJVUFile(stream)
x.get_text(stdout)
raw_text = stdout.getvalue()
@@ -36,7 +36,7 @@ class DJVUInput(InputFormatPlugin):
html = convert_basic(raw_text.replace(b"\n", b' ').replace(
b'\037', b'\n\n'))
# Run the HTMLized text through the html processing plugin.
from calibre.customize.ui import plugin_for_input_format
from ebook_converter.customize.ui import plugin_for_input_format
html_input = plugin_for_input_format('html')
for opt in html_input.options:
setattr(options, opt.option.name, opt.recommended_value)
@@ -59,8 +59,8 @@ class DJVUInput(InputFormatPlugin):
os.remove(htmlfile)
# Set metadata from file.
from calibre.customize.ui import get_file_type_metadata
from calibre.ebooks.oeb.transforms.metadata import meta_info_to_oeb_metadata
from ebook_converter.customize.ui import get_file_type_metadata
from ebook_converter.ebooks.oeb.transforms.metadata import meta_info_to_oeb_metadata
mi = get_file_type_metadata(stream, file_ext)
meta_info_to_oeb_metadata(mi, oeb.metadata, log)
@@ -5,7 +5,7 @@ from __future__ import absolute_import, division, print_function, unicode_litera
__license__ = 'GPL v3'
__copyright__ = '2013, Kovid Goyal <kovid at kovidgoyal.net>'
from calibre.customize.conversion import InputFormatPlugin, OptionRecommendation
from ebook_converter.customize.conversion import InputFormatPlugin, OptionRecommendation
class DOCXInput(InputFormatPlugin):
@@ -29,6 +29,6 @@ class DOCXInput(InputFormatPlugin):
recommendations = {('page_breaks_before', '/', OptionRecommendation.MED)}
def convert(self, stream, options, file_ext, log, accelerators):
from calibre.ebooks.docx.to_html import Convert
from ebook_converter.ebooks.docx.to_html import Convert
return Convert(stream, detect_cover=not options.docx_no_cover, log=log, notes_nopb=options.docx_no_pagebreaks_between_notes,
nosupsub=options.docx_inline_subsup)()
@@ -5,7 +5,7 @@ from __future__ import absolute_import, division, print_function, unicode_litera
__license__ = 'GPL v3'
__copyright__ = '2013, Kovid Goyal <kovid at kovidgoyal.net>'
from calibre.customize.conversion import OutputFormatPlugin, OptionRecommendation
from ebook_converter.customize.conversion import OutputFormatPlugin, OptionRecommendation
PAGE_SIZES = ['a0', 'a1', 'a2', 'a3', 'a4', 'a5', 'a6', 'b0', 'b1',
'b2', 'b3', 'b4', 'b5', 'b6', 'legal', 'letter']
@@ -74,20 +74,20 @@ class DOCXOutput(OutputFormatPlugin):
def convert_metadata(self, oeb):
from lxml import etree
from calibre.ebooks.oeb.base import OPF, OPF2_NS
from calibre.ebooks.metadata.opf2 import OPF as ReadOPF
from ebook_converter.ebooks.oeb.base import OPF, OPF2_NS
from ebook_converter.ebooks.metadata.opf2 import OPF as ReadOPF
from io import BytesIO
package = etree.Element(OPF('package'), attrib={'version': '2.0'}, nsmap={None: OPF2_NS})
oeb.metadata.to_opf2(package)
self.mi = ReadOPF(BytesIO(etree.tostring(package, encoding='utf-8')), populate_spine=False, try_to_guess_cover=False).to_book_metadata()
def convert(self, oeb, output_path, input_plugin, opts, log):
from calibre.ebooks.docx.writer.container import DOCX
from calibre.ebooks.docx.writer.from_html import Convert
from ebook_converter.ebooks.docx.writer.container import DOCX
from ebook_converter.ebooks.docx.writer.from_html import Convert
docx = DOCX(opts, log)
self.convert_metadata(oeb)
Convert(oeb, docx, self.mi, not opts.docx_no_cover, not opts.docx_no_toc)()
docx.write(output_path, self.mi)
if opts.extract_to:
from calibre.ebooks.docx.dump import do_dump
from ebook_converter.ebooks.docx.dump import do_dump
do_dump(output_path, opts.extract_to)
@@ -7,8 +7,8 @@ __docformat__ = 'restructuredtext en'
import os, re, posixpath
from itertools import cycle
from calibre.customize.conversion import InputFormatPlugin, OptionRecommendation
from polyglot.builtins import getcwd
from ebook_converter.customize.conversion import InputFormatPlugin, OptionRecommendation
from ebook_converter.polyglot.builtins import getcwd
ADOBE_OBFUSCATION = 'http://ns.adobe.com/pdf/enc#RC'
IDPF_OBFUSCATION = 'http://www.idpf.org/2008/embedding'
@@ -101,7 +101,7 @@ class EPUBInput(InputFormatPlugin):
def rationalize_cover3(self, opf, log):
''' If there is a reference to the cover/titlepage via manifest properties, convert to
entries in the <guide> so that the rest of the pipeline picks it up. '''
from calibre.ebooks.metadata.opf3 import items_with_property
from ebook_converter.ebooks.metadata.opf3 import items_with_property
removed = guide_titlepage_href = guide_titlepage_id = None
# Look for titlepages incorrectly marked in the <guide> as covers
@@ -150,7 +150,7 @@ class EPUBInput(InputFormatPlugin):
means, at most one entry with type="cover" that points to a raster
cover and at most one entry with type="titlepage" that points to an
HTML titlepage. '''
from calibre.ebooks.oeb.base import OPF
from ebook_converter.ebooks.oeb.base import OPF
removed = None
from lxml import etree
guide_cover, guide_elem = None, None
@@ -215,7 +215,7 @@ class EPUBInput(InputFormatPlugin):
guide_elem.set('href', raster_cover)
else:
# Render the titlepage to create a raster cover
from calibre.ebooks import render_html_svg_workaround
from ebook_converter.ebooks import render_html_svg_workaround
guide_elem.set('href', 'calibre_raster_cover.jpg')
t = etree.SubElement(
elem[0].getparent(), OPF('item'), href=guide_elem.get('href'), id='calibre_raster_cover')
@@ -231,7 +231,7 @@ class EPUBInput(InputFormatPlugin):
return removed
def find_opf(self):
from calibre.utils.xml_parse import safe_xml_fromstring
from ebook_converter.utils.xml_parse import safe_xml_fromstring
def attr(n, attr):
for k, v in n.attrib.items():
@@ -254,17 +254,17 @@ class EPUBInput(InputFormatPlugin):
traceback.print_exc()
def convert(self, stream, options, file_ext, log, accelerators):
from calibre.utils.zipfile import ZipFile
from calibre import walk
from calibre.ebooks import DRMError
from calibre.ebooks.metadata.opf2 import OPF
from ebook_converter.utils.zipfile import ZipFile
from ebook_converter import walk
from ebook_converter.ebooks import DRMError
from ebook_converter.ebooks.metadata.opf2 import OPF
try:
zf = ZipFile(stream)
zf.extractall(getcwd())
except:
log.exception('EPUB appears to be invalid ZIP file, trying a'
' more forgiving ZIP parser')
from calibre.utils.localunzip import extractall
from ebook_converter.utils.localunzip import extractall
stream.seek(0)
extractall(stream)
encfile = os.path.abspath(os.path.join('META-INF', 'encryption.xml'))
@@ -352,11 +352,11 @@ class EPUBInput(InputFormatPlugin):
def convert_epub3_nav(self, nav_path, opf, log, opts):
from lxml import etree
from calibre.ebooks.chardet import xml_to_unicode
from calibre.ebooks.oeb.polish.parsing import parse
from calibre.ebooks.oeb.base import EPUB_NS, XHTML, NCX_MIME, NCX, urlnormalize, urlunquote, serialize
from calibre.ebooks.oeb.polish.toc import first_child
from calibre.utils.xml_parse import safe_xml_fromstring
from ebook_converter.ebooks.chardet import xml_to_unicode
from ebook_converter.ebooks.oeb.polish.parsing import parse
from ebook_converter.ebooks.oeb.base import EPUB_NS, XHTML, NCX_MIME, NCX, urlnormalize, urlunquote, serialize
from ebook_converter.ebooks.oeb.polish.toc import first_child
from ebook_converter.utils.xml_parse import safe_xml_fromstring
from tempfile import NamedTemporaryFile
with lopen(nav_path, 'rb') as f:
raw = f.read()
@@ -8,11 +8,11 @@ __docformat__ = 'restructuredtext en'
import os, shutil, re
from calibre.customize.conversion import (OutputFormatPlugin,
from ebook_converter.customize.conversion import (OutputFormatPlugin,
OptionRecommendation)
from calibre.ptempfile import TemporaryDirectory
from calibre import CurrentDir
from polyglot.builtins import unicode_type, filter, map, zip, range, as_bytes
from ebook_converter.ptempfile import TemporaryDirectory
from ebook_converter import CurrentDir
from ebook_converter.polyglot.builtins import unicode_type, filter, map, zip, range, as_bytes
block_level_tags = (
'address',
@@ -130,7 +130,7 @@ class EPUBOutput(OutputFormatPlugin):
recommendations = {('pretty_print', True, OptionRecommendation.HIGH)}
def workaround_webkit_quirks(self): # {{{
from calibre.ebooks.oeb.base import XPath
from ebook_converter.ebooks.oeb.base import XPath
for x in self.oeb.spine:
root = x.data
body = XPath('//h:body')(root)
@@ -147,7 +147,7 @@ class EPUBOutput(OutputFormatPlugin):
def upshift_markup(self): # {{{
'Upgrade markup to comply with XHTML 1.1 where possible'
from calibre.ebooks.oeb.base import XPath, XML
from ebook_converter.ebooks.oeb.base import XPath, XML
for x in self.oeb.spine:
root = x.data
if (not root.get(XML('lang'))) and (root.get('lang')):
@@ -181,32 +181,32 @@ class EPUBOutput(OutputFormatPlugin):
self.log, self.opts, self.oeb = log, opts, oeb
if self.opts.epub_inline_toc:
from calibre.ebooks.mobi.writer8.toc import TOCAdder
from ebook_converter.ebooks.mobi.writer8.toc import TOCAdder
opts.mobi_toc_at_start = not opts.epub_toc_at_end
opts.mobi_passthrough = False
opts.no_inline_toc = False
TOCAdder(oeb, opts, replace_previous_inline_toc=True, ignore_existing_toc=True)
if self.opts.epub_flatten:
from calibre.ebooks.oeb.transforms.filenames import FlatFilenames
from ebook_converter.ebooks.oeb.transforms.filenames import FlatFilenames
FlatFilenames()(oeb, opts)
else:
from calibre.ebooks.oeb.transforms.filenames import UniqueFilenames
from ebook_converter.ebooks.oeb.transforms.filenames import UniqueFilenames
UniqueFilenames()(oeb, opts)
self.workaround_ade_quirks()
self.workaround_webkit_quirks()
self.upshift_markup()
from calibre.ebooks.oeb.transforms.rescale import RescaleImages
from ebook_converter.ebooks.oeb.transforms.rescale import RescaleImages
RescaleImages(check_colorspaces=True)(oeb, opts)
from calibre.ebooks.oeb.transforms.split import Split
from ebook_converter.ebooks.oeb.transforms.split import Split
split = Split(not self.opts.dont_split_on_page_breaks,
max_flow_size=self.opts.flow_size*1024
)
split(self.oeb, self.opts)
from calibre.ebooks.oeb.transforms.cover import CoverManager
from ebook_converter.ebooks.oeb.transforms.cover import CoverManager
cm = CoverManager(
no_default_cover=self.opts.no_default_epub_cover,
no_svg_cover=self.opts.no_svg_cover,
@@ -221,7 +221,7 @@ class EPUBOutput(OutputFormatPlugin):
first = next(iter(self.oeb.spine))
self.oeb.toc.add(_('Start'), first.href)
from calibre.ebooks.oeb.base import OPF
from ebook_converter.ebooks.oeb.base import OPF
identifiers = oeb.metadata['identifier']
uuid = None
for x in identifiers:
@@ -245,12 +245,12 @@ class EPUBOutput(OutputFormatPlugin):
x.content = 'urn:uuid:'+uuid
with TemporaryDirectory('_epub_output') as tdir:
from calibre.customize.ui import plugin_for_output_format
from ebook_converter.customize.ui import plugin_for_output_format
metadata_xml = None
extra_entries = []
if self.is_periodical:
if self.opts.output_profile.epub_periodical_format == 'sony':
from calibre.ebooks.epub.periodical import sony_metadata
from ebook_converter.ebooks.epub.periodical import sony_metadata
metadata_xml, atom_xml = sony_metadata(oeb)
extra_entries = [('atom.xml', 'application/atom+xml', atom_xml)]
oeb_output = plugin_for_output_format('oeb')
@@ -264,7 +264,7 @@ class EPUBOutput(OutputFormatPlugin):
if encrypted_fonts:
encryption = self.encrypt_fonts(encrypted_fonts, tdir, uuid)
from calibre.ebooks.epub import initialize_container
from ebook_converter.ebooks.epub import initialize_container
with initialize_container(output_path, os.path.basename(opf),
extra_entries=extra_entries) as epub:
epub.add_dir(tdir)
@@ -274,7 +274,7 @@ class EPUBOutput(OutputFormatPlugin):
epub.writestr('META-INF/metadata.xml',
metadata_xml.encode('utf-8'))
if opts.extract_to is not None:
from calibre.utils.zipfile import ZipFile
from ebook_converter.utils.zipfile import ZipFile
if os.path.exists(opts.extract_to):
if os.path.isdir(opts.extract_to):
shutil.rmtree(opts.extract_to)
@@ -287,17 +287,17 @@ class EPUBOutput(OutputFormatPlugin):
def upgrade_to_epub3(self, tdir, opf):
self.log.info('Upgrading to EPUB 3...')
from calibre.ebooks.epub import simple_container_xml
from calibre.ebooks.oeb.polish.cover import fix_conversion_titlepage_links_in_nav
from ebook_converter.ebooks.epub import simple_container_xml
from ebook_converter.ebooks.oeb.polish.cover import fix_conversion_titlepage_links_in_nav
try:
os.mkdir(os.path.join(tdir, 'META-INF'))
except EnvironmentError:
pass
with open(os.path.join(tdir, 'META-INF', 'container.xml'), 'wb') as f:
f.write(simple_container_xml(os.path.basename(opf)).encode('utf-8'))
from calibre.ebooks.oeb.polish.container import EpubContainer
from ebook_converter.ebooks.oeb.polish.container import EpubContainer
container = EpubContainer(tdir, self.log)
from calibre.ebooks.oeb.polish.upgrade import epub_2_to_3
from ebook_converter.ebooks.oeb.polish.upgrade import epub_2_to_3
existing_nav = getattr(self.opts, 'epub3_nav_parsed', None)
nav_href = getattr(self.opts, 'epub3_nav_href', None)
previous_nav = (nav_href, existing_nav) if existing_nav and nav_href else None
@@ -311,7 +311,7 @@ class EPUBOutput(OutputFormatPlugin):
pass
def encrypt_fonts(self, uris, tdir, uuid): # {{{
from polyglot.binary import from_hex_bytes
from ebook_converter.polyglot.binary import from_hex_bytes
key = re.sub(r'[^a-fA-F0-9]', '', uuid)
if len(key) < 16:
@@ -376,7 +376,7 @@ class EPUBOutput(OutputFormatPlugin):
Perform various markup transforms to get the output to render correctly
in the quirky ADE.
'''
from calibre.ebooks.oeb.base import XPath, XHTML, barename, urlunquote
from ebook_converter.ebooks.oeb.base import XPath, XHTML, barename, urlunquote
stylesheet = self.oeb.manifest.main_stylesheet
@@ -517,8 +517,8 @@ class EPUBOutput(OutputFormatPlugin):
'''
Perform toc link transforms to alleviate slow loading.
'''
from calibre.ebooks.oeb.base import urldefrag, XPath
from calibre.ebooks.oeb.polish.toc import item_at_top
from ebook_converter.ebooks.oeb.base import urldefrag, XPath
from ebook_converter.ebooks.oeb.polish.toc import item_at_top
def frag_is_at_top(root, frag):
elem = XPath('//*[@id="%s" or @name="%s"]'%(frag, frag))(root)
@@ -7,9 +7,9 @@ Convert .fb2 files to .lrf
"""
import os, re
from calibre.customize.conversion import InputFormatPlugin, OptionRecommendation
from calibre import guess_type
from polyglot.builtins import iteritems, getcwd
from ebook_converter.customize.conversion import InputFormatPlugin, OptionRecommendation
from ebook_converter import guess_type
from ebook_converter.polyglot.builtins import iteritems, getcwd
FB2NS = 'http://www.gribuser.ru/xml/fictionbook/2.0'
FB21NS = 'http://www.gribuser.ru/xml/fictionbook/2.1'
@@ -39,12 +39,12 @@ class FB2Input(InputFormatPlugin):
def convert(self, stream, options, file_ext, log,
accelerators):
from lxml import etree
from calibre.utils.xml_parse import safe_xml_fromstring
from calibre.ebooks.metadata.fb2 import ensure_namespace, get_fb2_data
from calibre.ebooks.metadata.opf2 import OPFCreator
from calibre.ebooks.metadata.meta import get_metadata
from calibre.ebooks.oeb.base import XLINK_NS, XHTML_NS
from calibre.ebooks.chardet import xml_to_unicode
from ebook_converter.utils.xml_parse import safe_xml_fromstring
from ebook_converter.ebooks.metadata.fb2 import ensure_namespace, get_fb2_data
from ebook_converter.ebooks.metadata.opf2 import OPFCreator
from ebook_converter.ebooks.metadata.meta import get_metadata
from ebook_converter.ebooks.oeb.base import XLINK_NS, XHTML_NS
from ebook_converter.ebooks.chardet import xml_to_unicode
self.log = log
log.debug('Parsing XML...')
raw = get_fb2_data(stream)[0]
@@ -156,7 +156,7 @@ class FB2Input(InputFormatPlugin):
return os.path.join(getcwd(), 'metadata.opf')
def extract_embedded_content(self, doc):
from calibre.ebooks.fb2 import base64_decode
from ebook_converter.ebooks.fb2 import base64_decode
self.binary_map = {}
for elem in doc.xpath('./*'):
if elem.text and 'binary' in elem.tag and 'id' in elem.attrib:
@@ -7,7 +7,7 @@ __docformat__ = 'restructuredtext en'
import os
from calibre.customize.conversion import OutputFormatPlugin, OptionRecommendation
from ebook_converter.customize.conversion import OutputFormatPlugin, OptionRecommendation
class FB2Output(OutputFormatPlugin):
@@ -171,9 +171,9 @@ class FB2Output(OutputFormatPlugin):
}
def convert(self, oeb_book, output_path, input_plugin, opts, log):
from calibre.ebooks.oeb.transforms.jacket import linearize_jacket
from calibre.ebooks.oeb.transforms.rasterize import SVGRasterizer, Unavailable
from calibre.ebooks.fb2.fb2ml import FB2MLizer
from ebook_converter.ebooks.oeb.transforms.jacket import linearize_jacket
from ebook_converter.ebooks.oeb.transforms.rasterize import SVGRasterizer, Unavailable
from ebook_converter.ebooks.fb2.fb2ml import FB2MLizer
try:
rasterizer = SVGRasterizer()
@@ -9,13 +9,13 @@ __docformat__ = 'restructuredtext en'
import re, tempfile, os
from functools import partial
from calibre.constants import islinux, isbsd
from calibre.customize.conversion import (InputFormatPlugin,
from ebook_converter.constants import islinux, isbsd
from ebook_converter.customize.conversion import (InputFormatPlugin,
OptionRecommendation)
from calibre.utils.localization import get_lang
from calibre.utils.filenames import ascii_filename
from calibre.utils.imghdr import what
from polyglot.builtins import unicode_type, zip, getcwd, as_unicode
from ebook_converter.utils.localization import get_lang
from ebook_converter.utils.filenames import ascii_filename
from ebook_converter.utils.imghdr import what
from ebook_converter.polyglot.builtins import unicode_type, zip, getcwd, as_unicode
def sanitize_file_name(x):
@@ -74,17 +74,17 @@ class HTMLInput(InputFormatPlugin):
if file_ext != 'opf':
if opts.dont_package:
raise ValueError('The --dont-package option is not supported for an HTML input file')
from calibre.ebooks.metadata.html import get_metadata
from ebook_converter.ebooks.metadata.html import get_metadata
mi = get_metadata(stream)
if fname:
from calibre.ebooks.metadata.meta import metadata_from_filename
from ebook_converter.ebooks.metadata.meta import metadata_from_filename
fmi = metadata_from_filename(fname)
fmi.smart_update(mi)
mi = fmi
oeb = self.create_oebbook(stream.name, basedir, opts, log, mi)
return oeb
from calibre.ebooks.conversion.plumber import create_oebbook
from ebook_converter.ebooks.conversion.plumber import create_oebbook
return create_oebbook(log, stream.name, opts,
encoding=opts.input_encoding)
@@ -98,16 +98,16 @@ class HTMLInput(InputFormatPlugin):
def create_oebbook(self, htmlpath, basedir, opts, log, mi):
import uuid
from calibre.ebooks.conversion.plumber import create_oebbook
from calibre.ebooks.oeb.base import (DirContainer,
from ebook_converter.ebooks.conversion.plumber import create_oebbook
from ebook_converter.ebooks.oeb.base import (DirContainer,
rewrite_links, urlnormalize, urldefrag, BINARY_MIME, OEB_STYLES,
xpath, urlquote)
from calibre import guess_type
from calibre.ebooks.oeb.transforms.metadata import \
from ebook_converter import guess_type
from ebook_converter.ebooks.oeb.transforms.metadata import \
meta_info_to_oeb_metadata
from calibre.ebooks.html.input import get_filelist
from calibre.ebooks.metadata import string_to_authors
from calibre.utils.localization import canonicalize_lang
from ebook_converter.ebooks.html.input import get_filelist
from ebook_converter.ebooks.metadata import string_to_authors
from ebook_converter.utils.localization import canonicalize_lang
import css_parser, logging
css_parser.log.setLevel(logging.WARN)
self.OEB_STYLES = OEB_STYLES
@@ -223,7 +223,7 @@ class HTMLInput(InputFormatPlugin):
return oeb
def link_to_local_path(self, link_, base=None):
from calibre.ebooks.html.input import Link
from ebook_converter.ebooks.html.input import Link
if not isinstance(link_, unicode_type):
try:
link_ = link_.decode('utf-8', 'error')
@@ -245,7 +245,7 @@ class HTMLInput(InputFormatPlugin):
return link, frag
def resource_adder(self, link_, base=None):
from polyglot.urllib import quote
from ebook_converter.polyglot.urllib import quote
link, frag = self.link_to_local_path(link_, base=base)
if link is None:
return link_
@@ -7,10 +7,10 @@ __docformat__ = 'restructuredtext en'
import os, re, shutil
from os.path import dirname, abspath, relpath as _relpath, exists, basename
from calibre.customize.conversion import OutputFormatPlugin, OptionRecommendation
from calibre import CurrentDir
from calibre.ptempfile import PersistentTemporaryDirectory
from polyglot.builtins import unicode_type
from ebook_converter.customize.conversion import OutputFormatPlugin, OptionRecommendation
from ebook_converter import CurrentDir
from ebook_converter.ptempfile import PersistentTemporaryDirectory
from ebook_converter.polyglot.builtins import unicode_type
def relpath(*args):
@@ -48,10 +48,10 @@ class HTMLOutput(OutputFormatPlugin):
Generate table of contents
'''
from lxml import etree
from polyglot.urllib import unquote
from ebook_converter.polyglot.urllib import unquote
from calibre.ebooks.oeb.base import element
from calibre.utils.cleantext import clean_xml_chars
from ebook_converter.ebooks.oeb.base import element
from ebook_converter.utils.cleantext import clean_xml_chars
with CurrentDir(output_dir):
def build_node(current_node, parent=None):
if parent is None:
@@ -85,10 +85,10 @@ class HTMLOutput(OutputFormatPlugin):
def convert(self, oeb_book, output_path, input_plugin, opts, log):
from lxml import etree
from calibre.utils import zipfile
from ebook_converter.utils import zipfile
from templite import Templite
from polyglot.urllib import unquote
from calibre.ebooks.html.meta import EasyMeta
from ebook_converter.polyglot.urllib import unquote
from ebook_converter.ebooks.html.meta import EasyMeta
# read template files
if opts.template_html_index is not None:
@@ -8,9 +8,9 @@ __docformat__ = 'restructuredtext en'
import os
from calibre import guess_type
from calibre.customize.conversion import InputFormatPlugin
from polyglot.builtins import getcwd
from ebook_converter import guess_type
from ebook_converter.customize.conversion import InputFormatPlugin
from ebook_converter.polyglot.builtins import getcwd
class HTMLZInput(InputFormatPlugin):
@@ -23,9 +23,9 @@ class HTMLZInput(InputFormatPlugin):
def convert(self, stream, options, file_ext, log,
accelerators):
from calibre.ebooks.chardet import xml_to_unicode
from calibre.ebooks.metadata.opf2 import OPF
from calibre.utils.zipfile import ZipFile
from ebook_converter.ebooks.chardet import xml_to_unicode
from ebook_converter.ebooks.metadata.opf2 import OPF
from ebook_converter.utils.zipfile import ZipFile
self.log = log
html = u''
@@ -82,7 +82,7 @@ class HTMLZInput(InputFormatPlugin):
html = html.decode(ienc, 'replace')
# Run the HTML through the html processing plugin.
from calibre.customize.ui import plugin_for_input_format
from ebook_converter.customize.ui import plugin_for_input_format
html_input = plugin_for_input_format('html')
for opt in html_input.options:
setattr(options, opt.option.name, opt.recommended_value)
@@ -105,8 +105,8 @@ class HTMLZInput(InputFormatPlugin):
os.remove(htmlfile)
# Set metadata from file.
from calibre.customize.ui import get_file_type_metadata
from calibre.ebooks.oeb.transforms.metadata import meta_info_to_oeb_metadata
from ebook_converter.customize.ui import get_file_type_metadata
from ebook_converter.ebooks.oeb.transforms.metadata import meta_info_to_oeb_metadata
mi = get_file_type_metadata(stream, file_ext)
meta_info_to_oeb_metadata(mi, oeb.metadata, log)
@@ -9,10 +9,10 @@ __docformat__ = 'restructuredtext en'
import io
import os
from calibre.customize.conversion import OutputFormatPlugin, \
from ebook_converter.customize.conversion import OutputFormatPlugin, \
OptionRecommendation
from calibre.ptempfile import TemporaryDirectory
from polyglot.builtins import unicode_type
from ebook_converter.ptempfile import TemporaryDirectory
from ebook_converter.polyglot.builtins import unicode_type
class HTMLZOutput(OutputFormatPlugin):
@@ -59,20 +59,20 @@ class HTMLZOutput(OutputFormatPlugin):
def convert(self, oeb_book, output_path, input_plugin, opts, log):
from lxml import etree
from calibre.ebooks.oeb.base import OEB_IMAGES, SVG_MIME
from calibre.ebooks.metadata.opf2 import OPF, metadata_to_opf
from calibre.utils.zipfile import ZipFile
from calibre.utils.filenames import ascii_filename
from ebook_converter.ebooks.oeb.base import OEB_IMAGES, SVG_MIME
from ebook_converter.ebooks.metadata.opf2 import OPF, metadata_to_opf
from ebook_converter.utils.zipfile import ZipFile
from ebook_converter.utils.filenames import ascii_filename
# HTML
if opts.htmlz_css_type == 'inline':
from calibre.ebooks.htmlz.oeb2html import OEB2HTMLInlineCSSizer
from ebook_converter.ebooks.htmlz.oeb2html import OEB2HTMLInlineCSSizer
OEB2HTMLizer = OEB2HTMLInlineCSSizer
elif opts.htmlz_css_type == 'tag':
from calibre.ebooks.htmlz.oeb2html import OEB2HTMLNoCSSizer
from ebook_converter.ebooks.htmlz.oeb2html import OEB2HTMLNoCSSizer
OEB2HTMLizer = OEB2HTMLNoCSSizer
else:
from calibre.ebooks.htmlz.oeb2html import OEB2HTMLClassCSSizer as OEB2HTMLizer
from ebook_converter.ebooks.htmlz.oeb2html import OEB2HTMLClassCSSizer as OEB2HTMLizer
with TemporaryDirectory(u'_htmlz_output') as tdir:
htmlizer = OEB2HTMLizer(log)
@@ -80,7 +80,7 @@ class HTMLZOutput(OutputFormatPlugin):
fname = u'index'
if opts.htmlz_title_filename:
from calibre.utils.filenames import shorten_components_to
from ebook_converter.utils.filenames import shorten_components_to
fname = shorten_components_to(100, (ascii_filename(unicode_type(oeb_book.metadata.title[0])),))[0]
with open(os.path.join(tdir, fname+u'.html'), 'wb') as tf:
if isinstance(html, unicode_type):
@@ -115,7 +115,7 @@ class HTMLZOutput(OutputFormatPlugin):
term = oeb_book.metadata.cover[0].term
cover_data = oeb_book.guide[term].item.data
if cover_data:
from calibre.utils.img import save_cover_data_to
from ebook_converter.utils.img import save_cover_data_to
cover_path = os.path.join(tdir, u'cover.jpg')
with lopen(cover_path, 'w') as cf:
cf.write('')
@@ -6,7 +6,7 @@ __license__ = 'GPL v3'
__copyright__ = '2009, Kovid Goyal <kovid@kovidgoyal.net>'
__docformat__ = 'restructuredtext en'
from calibre.customize.conversion import InputFormatPlugin
from ebook_converter.customize.conversion import InputFormatPlugin
class LITInput(InputFormatPlugin):
@@ -19,13 +19,13 @@ class LITInput(InputFormatPlugin):
def convert(self, stream, options, file_ext, log,
accelerators):
from calibre.ebooks.lit.reader import LitReader
from calibre.ebooks.conversion.plumber import create_oebbook
from ebook_converter.ebooks.lit.reader import LitReader
from ebook_converter.ebooks.conversion.plumber import create_oebbook
self.log = log
return create_oebbook(log, stream, options, reader=LitReader)
def postprocess_book(self, oeb, opts, log):
from calibre.ebooks.oeb.base import XHTML_NS, XPath, XHTML
from ebook_converter.ebooks.oeb.base import XHTML_NS, XPath, XHTML
for item in oeb.spine:
root = item.data
if not hasattr(root, 'xpath'):
@@ -40,10 +40,10 @@ class LITInput(InputFormatPlugin):
body = body[0]
if len(body) == 1 and body[0].tag == XHTML('pre'):
pre = body[0]
from calibre.ebooks.txt.processor import convert_basic, \
from ebook_converter.ebooks.txt.processor import convert_basic, \
separate_paragraphs_single_line
from calibre.ebooks.chardet import xml_to_unicode
from calibre.utils.xml_parse import safe_xml_fromstring
from ebook_converter.ebooks.chardet import xml_to_unicode
from ebook_converter.utils.xml_parse import safe_xml_fromstring
import copy
self.log('LIT file with all text in singe <pre> tag detected')
html = separate_paragraphs_single_line(pre.text)
@@ -53,7 +53,7 @@ class LITInput(InputFormatPlugin):
resolve_entities=True)[0]
if opts.smarten_punctuation:
# SmartyPants skips text inside <pre> tags
from calibre.ebooks.conversion.preprocess import smarten_punctuation
from ebook_converter.ebooks.conversion.preprocess import smarten_punctuation
html = smarten_punctuation(html, self.log)
root = safe_xml_fromstring(html)
body = XPath('//h:body')(root)
@@ -7,7 +7,7 @@ __copyright__ = '2009, Kovid Goyal <kovid@kovidgoyal.net>'
__docformat__ = 'restructuredtext en'
from calibre.customize.conversion import OutputFormatPlugin
from ebook_converter.customize.conversion import OutputFormatPlugin
class LITOutput(OutputFormatPlugin):
@@ -19,11 +19,11 @@ class LITOutput(OutputFormatPlugin):
def convert(self, oeb, output_path, input_plugin, opts, log):
self.log, self.opts, self.oeb = log, opts, oeb
from calibre.ebooks.oeb.transforms.manglecase import CaseMangler
from calibre.ebooks.oeb.transforms.rasterize import SVGRasterizer
from calibre.ebooks.oeb.transforms.htmltoc import HTMLTOCAdder
from calibre.ebooks.lit.writer import LitWriter
from calibre.ebooks.oeb.transforms.split import Split
from ebook_converter.ebooks.oeb.transforms.manglecase import CaseMangler
from ebook_converter.ebooks.oeb.transforms.rasterize import SVGRasterizer
from ebook_converter.ebooks.oeb.transforms.htmltoc import HTMLTOCAdder
from ebook_converter.ebooks.lit.writer import LitWriter
from ebook_converter.ebooks.oeb.transforms.split import Split
split = Split(split_on_page_breaks=True, max_flow_size=0,
remove_css_pagebreaks=False)
split(self.oeb, self.opts)
@@ -7,7 +7,7 @@ __copyright__ = '2009, Kovid Goyal <kovid@kovidgoyal.net>'
__docformat__ = 'restructuredtext en'
import os, sys
from calibre.customize.conversion import InputFormatPlugin
from ebook_converter.customize.conversion import InputFormatPlugin
class LRFInput(InputFormatPlugin):
@@ -20,12 +20,12 @@ class LRFInput(InputFormatPlugin):
def convert(self, stream, options, file_ext, log,
accelerators):
from calibre.ebooks.lrf.input import (MediaType, Styles, TextBlock,
from ebook_converter.ebooks.lrf.input import (MediaType, Styles, TextBlock,
Canvas, ImageBlock, RuledLine)
self.log = log
self.log('Generating XML')
from calibre.ebooks.lrf.lrfparser import LRFDocument
from calibre.utils.xml_parse import safe_xml_fromstring
from ebook_converter.ebooks.lrf.lrfparser import LRFDocument
from ebook_converter.utils.xml_parse import safe_xml_fromstring
from lxml import etree
d = LRFDocument(stream)
d.parse()
@@ -8,9 +8,9 @@ __docformat__ = 'restructuredtext en'
import sys, os
from calibre.customize.conversion import OutputFormatPlugin
from calibre.customize.conversion import OptionRecommendation
from polyglot.builtins import unicode_type
from ebook_converter.customize.conversion import OutputFormatPlugin
from ebook_converter.customize.conversion import OptionRecommendation
from ebook_converter.polyglot.builtins import unicode_type
class LRFOptions(object):
@@ -53,7 +53,7 @@ class LRFOptions(object):
self.use_spine = True
self.font_delta = 0
self.ignore_colors = False
from calibre.ebooks.lrf import PRS500_PROFILE
from ebook_converter.ebooks.lrf import PRS500_PROFILE
self.profile = PRS500_PROFILE
self.link_levels = sys.maxsize
self.link_exclude = '@'
@@ -140,9 +140,9 @@ class LRFOutput(OutputFormatPlugin):
('change_justification', 'original', OptionRecommendation.HIGH)}
def convert_images(self, pages, opts, wide):
from calibre.ebooks.lrf.pylrs.pylrs import Book, BookSetting, ImageStream, ImageBlock
from ebook_converter.ebooks.lrf.pylrs.pylrs import Book, BookSetting, ImageStream, ImageBlock
from uuid import uuid4
from calibre.constants import __appname__, __version__
from ebook_converter.constants import __appname__, __version__
width, height = (784, 1012) if wide else (584, 754)
@@ -168,7 +168,7 @@ class LRFOutput(OutputFormatPlugin):
book.renderLrf(open(opts.output, 'wb'))
def flatten_toc(self):
from calibre.ebooks.oeb.base import TOC
from ebook_converter.ebooks.oeb.base import TOC
nroot = TOC()
for x in self.oeb.toc.iterdescendants():
nroot.add(x.title, x.href)
@@ -186,11 +186,11 @@ class LRFOutput(OutputFormatPlugin):
self.flatten_toc()
from calibre.ptempfile import TemporaryDirectory
from ebook_converter.ptempfile import TemporaryDirectory
with TemporaryDirectory('_lrf_output') as tdir:
from calibre.customize.ui import plugin_for_output_format
from ebook_converter.customize.ui import plugin_for_output_format
oeb_output = plugin_for_output_format('oeb')
oeb_output.convert(oeb, tdir, input_plugin, opts, log)
opf = [x for x in os.listdir(tdir) if x.endswith('.opf')][0]
from calibre.ebooks.lrf.html.convert_from import process_file
from ebook_converter.ebooks.lrf.html.convert_from import process_file
process_file(os.path.join(tdir, opf), lrf_opts, self.log)
@@ -6,8 +6,8 @@ __docformat__ = 'restructuredtext en'
import os
from calibre.customize.conversion import InputFormatPlugin
from polyglot.builtins import unicode_type
from ebook_converter.customize.conversion import InputFormatPlugin
from ebook_converter.polyglot.builtins import unicode_type
class MOBIInput(InputFormatPlugin):
@@ -23,7 +23,7 @@ class MOBIInput(InputFormatPlugin):
self.is_kf8 = False
self.mobi_is_joint = False
from calibre.ebooks.mobi.reader.mobi6 import MobiReader
from ebook_converter.ebooks.mobi.reader.mobi6 import MobiReader
from lxml import html
parse_cache = {}
try:
@@ -42,7 +42,7 @@ class MOBIInput(InputFormatPlugin):
log('Found KF8 MOBI of type %r'%mr.kf8_type)
if mr.kf8_type == 'joint':
self.mobi_is_joint = True
from calibre.ebooks.mobi.reader.mobi8 import Mobi8Reader
from ebook_converter.ebooks.mobi.reader.mobi8 import Mobi8Reader
mr = Mobi8Reader(mr, log)
opf = os.path.abspath(mr())
self.encrypted_fonts = mr.encrypted_fonts
@@ -55,7 +55,7 @@ class MOBIInput(InputFormatPlugin):
raw = raw.encode('utf-8')
with lopen('debug-raw.html', 'wb') as f:
f.write(raw)
from calibre.ebooks.oeb.base import close_self_closing_tags
from ebook_converter.ebooks.oeb.base import close_self_closing_tags
for f, root in parse_cache.items():
raw = html.tostring(root, encoding='utf-8', method='xml',
include_meta_content_type=False)
@@ -6,13 +6,13 @@ __license__ = 'GPL v3'
__copyright__ = '2009, Kovid Goyal <kovid@kovidgoyal.net>'
__docformat__ = 'restructuredtext en'
from calibre.customize.conversion import (OutputFormatPlugin,
from ebook_converter.customize.conversion import (OutputFormatPlugin,
OptionRecommendation)
from polyglot.builtins import unicode_type
from ebook_converter.polyglot.builtins import unicode_type
def remove_html_cover(oeb, log):
from calibre.ebooks.oeb.base import OEB_DOCS
from ebook_converter.ebooks.oeb.base import OEB_DOCS
if not oeb.metadata.cover \
or 'cover' not in oeb.guide:
@@ -32,7 +32,7 @@ def remove_html_cover(oeb, log):
def extract_mobi(output_path, opts):
if opts.extract_to is not None:
from calibre.ebooks.mobi.debug.main import inspect_mobi
from ebook_converter.ebooks.mobi.debug.main import inspect_mobi
ddir = opts.extract_to
inspect_mobi(output_path, ddir=ddir)
@@ -120,7 +120,7 @@ class MOBIOutput(OutputFormatPlugin):
def check_for_masthead(self):
found = 'masthead' in self.oeb.guide
if not found:
from calibre.ebooks import generate_masthead
from ebook_converter.ebooks import generate_masthead
self.oeb.log.debug('No masthead found in manifest, generating default mastheadImage...')
raw = generate_masthead(unicode_type(self.oeb.metadata['title'][0]))
id, href = self.oeb.manifest.generate('masthead', 'masthead')
@@ -130,7 +130,7 @@ class MOBIOutput(OutputFormatPlugin):
self.oeb.log.debug('Using mastheadImage supplied in manifest...')
def periodicalize_toc(self):
from calibre.ebooks.oeb.base import TOC
from ebook_converter.ebooks.oeb.base import TOC
toc = self.oeb.toc
if not toc or len(self.oeb.spine) < 3:
return
@@ -183,7 +183,7 @@ class MOBIOutput(OutputFormatPlugin):
toc.nodes[0].href = toc.nodes[0].nodes[0].href
def convert(self, oeb, output_path, input_plugin, opts, log):
from calibre.ebooks.mobi.writer2.resources import Resources
from ebook_converter.ebooks.mobi.writer2.resources import Resources
self.log, self.opts, self.oeb = log, opts, oeb
mobi_type = opts.mobi_file_type
@@ -197,10 +197,10 @@ class MOBIOutput(OutputFormatPlugin):
self.check_for_periodical()
if create_kf8:
from calibre.ebooks.mobi.writer8.cleanup import remove_duplicate_anchors
from ebook_converter.ebooks.mobi.writer8.cleanup import remove_duplicate_anchors
remove_duplicate_anchors(self.oeb)
# Split on pagebreaks so that the resulting KF8 is faster to load
from calibre.ebooks.oeb.transforms.split import Split
from ebook_converter.ebooks.oeb.transforms.split import Split
Split()(self.oeb, self.opts)
kf8 = self.create_kf8(resources, for_joint=mobi_type=='both'
@@ -214,16 +214,16 @@ class MOBIOutput(OutputFormatPlugin):
self.write_mobi(input_plugin, output_path, kf8, resources)
def create_kf8(self, resources, for_joint=False):
from calibre.ebooks.mobi.writer8.main import create_kf8_book
from ebook_converter.ebooks.mobi.writer8.main import create_kf8_book
return create_kf8_book(self.oeb, self.opts, resources,
for_joint=for_joint)
def write_mobi(self, input_plugin, output_path, kf8, resources):
from calibre.ebooks.mobi.mobiml import MobiMLizer
from calibre.ebooks.oeb.transforms.manglecase import CaseMangler
from calibre.ebooks.oeb.transforms.rasterize import SVGRasterizer, Unavailable
from calibre.ebooks.oeb.transforms.htmltoc import HTMLTOCAdder
from calibre.customize.ui import plugin_for_input_format
from ebook_converter.ebooks.mobi.mobiml import MobiMLizer
from ebook_converter.ebooks.oeb.transforms.manglecase import CaseMangler
from ebook_converter.ebooks.oeb.transforms.rasterize import SVGRasterizer, Unavailable
from ebook_converter.ebooks.oeb.transforms.htmltoc import HTMLTOCAdder
from ebook_converter.customize.ui import plugin_for_input_format
opts, oeb = self.opts, self.oeb
if not opts.no_inline_toc:
@@ -245,20 +245,20 @@ class MOBIOutput(OutputFormatPlugin):
mobimlizer = MobiMLizer(ignore_tables=opts.linearize_tables)
mobimlizer(oeb, opts)
write_page_breaks_after_item = input_plugin is not plugin_for_input_format('cbz')
from calibre.ebooks.mobi.writer2.main import MobiWriter
from ebook_converter.ebooks.mobi.writer2.main import MobiWriter
writer = MobiWriter(opts, resources, kf8,
write_page_breaks_after_item=write_page_breaks_after_item)
writer(oeb, output_path)
extract_mobi(output_path, opts)
def specialize_css_for_output(self, log, opts, item, stylizer):
from calibre.ebooks.mobi.writer8.cleanup import CSSCleanup
from ebook_converter.ebooks.mobi.writer8.cleanup import CSSCleanup
CSSCleanup(log, opts)(item, stylizer)
def workaround_fire_bugs(self, jacket):
# The idiotic Fire crashes when trying to render the table used to
# layout the jacket
from calibre.ebooks.oeb.base import XHTML
from ebook_converter.ebooks.oeb.base import XHTML
for table in jacket.data.xpath('//*[local-name()="table"]'):
table.tag = XHTML('div')
for tr in table.xpath('descendant::*[local-name()="tr"]'):
@@ -309,9 +309,9 @@ class AZW3Output(OutputFormatPlugin):
}
def convert(self, oeb, output_path, input_plugin, opts, log):
from calibre.ebooks.mobi.writer2.resources import Resources
from calibre.ebooks.mobi.writer8.main import create_kf8_book
from calibre.ebooks.mobi.writer8.cleanup import remove_duplicate_anchors
from ebook_converter.ebooks.mobi.writer2.resources import Resources
from ebook_converter.ebooks.mobi.writer8.main import create_kf8_book
from ebook_converter.ebooks.mobi.writer8.cleanup import remove_duplicate_anchors
self.oeb, self.opts, self.log = oeb, opts, log
opts.mobi_periodical = self.is_periodical
@@ -324,7 +324,7 @@ class AZW3Output(OutputFormatPlugin):
remove_html_cover(self.oeb, self.log)
# Split on pagebreaks so that the resulting KF8 is faster to load
from calibre.ebooks.oeb.transforms.split import Split
from ebook_converter.ebooks.oeb.transforms.split import Split
Split()(self.oeb, self.opts)
kf8 = create_kf8_book(self.oeb, self.opts, resources, for_joint=False)
@@ -333,5 +333,5 @@ class AZW3Output(OutputFormatPlugin):
extract_mobi(output_path, opts)
def specialize_css_for_output(self, log, opts, item, stylizer):
from calibre.ebooks.mobi.writer8.cleanup import CSSCleanup
from ebook_converter.ebooks.mobi.writer8.cleanup import CSSCleanup
CSSCleanup(log, opts)(item, stylizer)
@@ -8,7 +8,7 @@ __docformat__ = 'restructuredtext en'
Convert an ODT file into a Open Ebook
'''
from calibre.customize.conversion import InputFormatPlugin
from ebook_converter.customize.conversion import InputFormatPlugin
class ODTInput(InputFormatPlugin):
@@ -21,5 +21,5 @@ class ODTInput(InputFormatPlugin):
def convert(self, stream, options, file_ext, log,
accelerators):
from calibre.ebooks.odt.input import Extract
from ebook_converter.ebooks.odt.input import Extract
return Extract()(stream, '.', log)
@@ -7,9 +7,9 @@ __docformat__ = 'restructuredtext en'
import os, re
from calibre.customize.conversion import (OutputFormatPlugin,
from ebook_converter.customize.conversion import (OutputFormatPlugin,
OptionRecommendation)
from calibre import CurrentDir
from ebook_converter import CurrentDir
class OEBOutput(OutputFormatPlugin):
@@ -22,14 +22,14 @@ class OEBOutput(OutputFormatPlugin):
recommendations = {('pretty_print', True, OptionRecommendation.HIGH)}
def convert(self, oeb_book, output_path, input_plugin, opts, log):
from polyglot.urllib import unquote
from ebook_converter.polyglot.urllib import unquote
from lxml import etree
self.log, self.opts = log, opts
if not os.path.exists(output_path):
os.makedirs(output_path)
from calibre.ebooks.oeb.base import OPF_MIME, NCX_MIME, PAGE_MAP_MIME, OEB_STYLES
from calibre.ebooks.oeb.normalize_css import condense_sheet
from ebook_converter.ebooks.oeb.base import OPF_MIME, NCX_MIME, PAGE_MAP_MIME, OEB_STYLES
from ebook_converter.ebooks.oeb.normalize_css import condense_sheet
with CurrentDir(output_path):
results = oeb_book.to_opf2(page_map=True)
for key in (OPF_MIME, NCX_MIME, PAGE_MAP_MIME):
@@ -89,7 +89,7 @@ class OEBOutput(OutputFormatPlugin):
self.log.warn('The cover image has an id != "cover". Renaming'
' to work around bug in Nook Color')
from calibre.ebooks.oeb.base import uuid_id
from ebook_converter.ebooks.oeb.base import uuid_id
newid = uuid_id()
for item in manifest_items_with_id('cover'):
@@ -114,7 +114,7 @@ class OEBOutput(OutputFormatPlugin):
# }}}
def migrate_lang_code(self, root): # {{{
from calibre.utils.localization import lang_as_iso639_1
from ebook_converter.utils.localization import lang_as_iso639_1
for lang in root.xpath('//*[local-name() = "language"]'):
clc = lang_as_iso639_1(lang.text)
if clc:
@@ -5,8 +5,8 @@ __license__ = 'GPL v3'
__copyright__ = '2009, John Schember <john@nachtimwald.com>'
__docformat__ = 'restructuredtext en'
from calibre.customize.conversion import InputFormatPlugin
from polyglot.builtins import getcwd
from ebook_converter.customize.conversion import InputFormatPlugin
from ebook_converter.polyglot.builtins import getcwd
class PDBInput(InputFormatPlugin):
@@ -19,8 +19,8 @@ class PDBInput(InputFormatPlugin):
def convert(self, stream, options, file_ext, log,
accelerators):
from calibre.ebooks.pdb.header import PdbHeaderReader
from calibre.ebooks.pdb import PDBError, IDENTITY_TO_NAME, get_reader
from ebook_converter.ebooks.pdb.header import PdbHeaderReader
from ebook_converter.ebooks.pdb import PDBError, IDENTITY_TO_NAME, get_reader
header = PdbHeaderReader(stream)
Reader = get_reader(header.ident)
@@ -7,9 +7,9 @@ __docformat__ = 'restructuredtext en'
import os
from calibre.customize.conversion import OutputFormatPlugin, \
from ebook_converter.customize.conversion import OutputFormatPlugin, \
OptionRecommendation
from calibre.ebooks.pdb import PDBError, get_writer, ALL_FORMAT_WRITERS
from ebook_converter.ebooks.pdb import PDBError, get_writer, ALL_FORMAT_WRITERS
class PDBOutput(OutputFormatPlugin):
@@ -7,8 +7,8 @@ __docformat__ = 'restructuredtext en'
import os
from calibre.customize.conversion import InputFormatPlugin, OptionRecommendation
from polyglot.builtins import as_bytes, getcwd
from ebook_converter.customize.conversion import InputFormatPlugin, OptionRecommendation
from ebook_converter.polyglot.builtins import as_bytes, getcwd
class PDFInput(InputFormatPlugin):
@@ -31,9 +31,9 @@ class PDFInput(InputFormatPlugin):
}
def convert_new(self, stream, accelerators):
from calibre.ebooks.pdf.pdftohtml import pdftohtml
from calibre.utils.cleantext import clean_ascii_chars
from calibre.ebooks.pdf.reflow import PDFDocument
from ebook_converter.ebooks.pdf.pdftohtml import pdftohtml
from ebook_converter.utils.cleantext import clean_ascii_chars
from ebook_converter.ebooks.pdf.reflow import PDFDocument
pdftohtml(getcwd(), stream.name, self.opts.no_images, as_xml=True)
with lopen('index.xml', 'rb') as f:
@@ -43,8 +43,8 @@ class PDFInput(InputFormatPlugin):
def convert(self, stream, options, file_ext, log,
accelerators):
from calibre.ebooks.metadata.opf2 import OPFCreator
from calibre.ebooks.pdf.pdftohtml import pdftohtml
from ebook_converter.ebooks.metadata.opf2 import OPFCreator
from ebook_converter.ebooks.pdf.pdftohtml import pdftohtml
log.debug('Converting file to html...')
# The main html file will be named index.html
@@ -53,7 +53,7 @@ class PDFInput(InputFormatPlugin):
return self.convert_new(stream, accelerators)
pdftohtml(getcwd(), stream.name, options.no_images)
from calibre.ebooks.metadata.meta import get_metadata
from ebook_converter.ebooks.metadata.meta import get_metadata
log.debug('Retrieving document metadata...')
mi = get_metadata(stream, 'pdf')
opf = OPFCreator(getcwd(), mi)
@@ -11,10 +11,10 @@ Convert OEB ebook format to PDF.
import glob, os
from calibre.customize.conversion import (OutputFormatPlugin,
from ebook_converter.customize.conversion import (OutputFormatPlugin,
OptionRecommendation)
from calibre.ptempfile import TemporaryDirectory
from polyglot.builtins import iteritems, unicode_type
from ebook_converter.ptempfile import TemporaryDirectory
from ebook_converter.polyglot.builtins import iteritems, unicode_type
UNITS = ('millimeter', 'centimeter', 'point', 'inch' , 'pica' , 'didot',
'cicero', 'devicepixel')
@@ -150,8 +150,8 @@ class PDFOutput(OutputFormatPlugin):
# that hopefully no Qt application has been constructed as yet
from PyQt5.QtWebEngineCore import QWebEngineUrlScheme
from PyQt5.QtWebEngineWidgets import QWebEnginePage # noqa
from calibre.gui2 import must_use_qt
from calibre.constants import FAKE_PROTOCOL
from ebook_converter.gui2 import must_use_qt
from ebook_converter.constants import FAKE_PROTOCOL
scheme = QWebEngineUrlScheme(FAKE_PROTOCOL.encode('ascii'))
scheme.setSyntax(QWebEngineUrlScheme.Syntax.Host)
scheme.setFlags(QWebEngineUrlScheme.SecureScheme)
@@ -169,13 +169,13 @@ class PDFOutput(OutputFormatPlugin):
self.oeb = oeb_book
self.input_plugin, self.opts, self.log = input_plugin, opts, log
self.output_path = output_path
from calibre.ebooks.oeb.base import OPF, OPF2_NS
from ebook_converter.ebooks.oeb.base import OPF, OPF2_NS
from lxml import etree
from io import BytesIO
package = etree.Element(OPF('package'),
attrib={'version': '2.0', 'unique-identifier': 'dummy'},
nsmap={None: OPF2_NS})
from calibre.ebooks.metadata.opf2 import OPF
from ebook_converter.ebooks.metadata.opf2 import OPF
self.oeb.metadata.to_opf2(package)
self.metadata = OPF(BytesIO(etree.tostring(package))).to_book_metadata()
self.cover_data = None
@@ -188,7 +188,7 @@ class PDFOutput(OutputFormatPlugin):
self.convert_text(oeb_book)
def convert_images(self, images):
from calibre.ebooks.pdf.image_writer import convert
from ebook_converter.ebooks.pdf.image_writer import convert
convert(images, self.output_path, self.opts, self.metadata, self.report_progress)
def get_cover_data(self):
@@ -200,8 +200,8 @@ class PDFOutput(OutputFormatPlugin):
def process_fonts(self):
''' Make sure all fonts are embeddable '''
from calibre.ebooks.oeb.base import urlnormalize
from calibre.utils.fonts.utils import remove_embed_restriction
from ebook_converter.ebooks.oeb.base import urlnormalize
from ebook_converter.utils.fonts.utils import remove_embed_restriction
processed = set()
for item in list(self.oeb.manifest):
@@ -232,7 +232,7 @@ class PDFOutput(OutputFormatPlugin):
def convert_text(self, oeb_book):
import json
from calibre.ebooks.pdf.html_writer import convert
from ebook_converter.ebooks.pdf.html_writer import convert
self.get_cover_data()
self.process_fonts()
@@ -245,7 +245,7 @@ class PDFOutput(OutputFormatPlugin):
root.set('data-calibre-pdf-output-page-margins', json.dumps(margins))
with TemporaryDirectory('_pdf_out') as oeb_dir:
from calibre.customize.ui import plugin_for_output_format
from ebook_converter.customize.ui import plugin_for_output_format
oeb_dir = os.path.realpath(oeb_dir)
oeb_output = plugin_for_output_format('oeb')
oeb_output.convert(oeb_book, oeb_dir, self.input_plugin, self.opts, self.log)
@@ -9,9 +9,9 @@ import glob
import os
import shutil
from calibre.customize.conversion import InputFormatPlugin
from calibre.ptempfile import TemporaryDirectory
from polyglot.builtins import getcwd
from ebook_converter.customize.conversion import InputFormatPlugin
from ebook_converter.ptempfile import TemporaryDirectory
from ebook_converter.polyglot.builtins import getcwd
class PMLInput(InputFormatPlugin):
@@ -24,7 +24,7 @@ class PMLInput(InputFormatPlugin):
commit_name = 'pml_input'
def process_pml(self, pml_path, html_path, close_all=False):
from calibre.ebooks.pml.pmlconverter import PML_HTMLizer
from ebook_converter.ebooks.pml.pmlconverter import PML_HTMLizer
pclose = False
hclose = False
@@ -89,9 +89,9 @@ class PMLInput(InputFormatPlugin):
def convert(self, stream, options, file_ext, log,
accelerators):
from calibre.ebooks.metadata.toc import TOC
from calibre.ebooks.metadata.opf2 import OPFCreator
from calibre.utils.zipfile import ZipFile
from ebook_converter.ebooks.metadata.toc import TOC
from ebook_converter.ebooks.metadata.opf2 import OPFCreator
from ebook_converter.utils.zipfile import ZipFile
self.options = options
self.log = log
@@ -128,7 +128,7 @@ class PMLInput(InputFormatPlugin):
for item in pages+images:
manifest_items.append((item, None))
from calibre.ebooks.metadata.meta import get_metadata
from ebook_converter.ebooks.metadata.meta import get_metadata
log.debug('Reading metadata from input file...')
mi = get_metadata(stream, 'pml')
if 'images/cover.png' in images:
@@ -145,7 +145,7 @@ class PMLInput(InputFormatPlugin):
return os.path.join(getcwd(), 'metadata.opf')
def postprocess_book(self, oeb, opts, log):
from calibre.ebooks.oeb.base import XHTML, barename
from ebook_converter.ebooks.oeb.base import XHTML, barename
for item in oeb.spine:
if hasattr(item.data, 'xpath'):
for heading in item.data.iterdescendants(*map(XHTML, 'h1 h2 h3 h4 h5 h6'.split())):
@@ -7,10 +7,10 @@ __docformat__ = 'restructuredtext en'
import os, io
from calibre.customize.conversion import (OutputFormatPlugin,
from ebook_converter.customize.conversion import (OutputFormatPlugin,
OptionRecommendation)
from calibre.ptempfile import TemporaryDirectory
from polyglot.builtins import unicode_type
from ebook_converter.ptempfile import TemporaryDirectory
from ebook_converter.polyglot.builtins import unicode_type
class PMLOutput(OutputFormatPlugin):
@@ -37,8 +37,8 @@ class PMLOutput(OutputFormatPlugin):
}
def convert(self, oeb_book, output_path, input_plugin, opts, log):
from calibre.ebooks.pml.pmlml import PMLMLizer
from calibre.utils.zipfile import ZipFile
from ebook_converter.ebooks.pml.pmlml import PMLMLizer
from ebook_converter.utils.zipfile import ZipFile
with TemporaryDirectory('_pmlz_output') as tdir:
pmlmlizer = PMLMLizer(log)
@@ -58,7 +58,7 @@ class PMLOutput(OutputFormatPlugin):
def write_images(self, manifest, image_hrefs, out_dir, opts):
from PIL import Image
from calibre.ebooks.oeb.base import OEB_RASTER_IMAGES
from ebook_converter.ebooks.oeb.base import OEB_RASTER_IMAGES
for item in manifest:
if item.media_type in OEB_RASTER_IMAGES and item.href in image_hrefs.keys():
if opts.full_image_depth:
@@ -6,8 +6,8 @@ __copyright__ = '2009, John Schember <john@nachtimwald.com>'
__docformat__ = 'restructuredtext en'
from calibre.customize.conversion import InputFormatPlugin
from polyglot.builtins import getcwd
from ebook_converter.customize.conversion import InputFormatPlugin
from ebook_converter.polyglot.builtins import getcwd
class RBInput(InputFormatPlugin):
@@ -20,7 +20,7 @@ class RBInput(InputFormatPlugin):
def convert(self, stream, options, file_ext, log,
accelerators):
from calibre.ebooks.rb.reader import Reader
from ebook_converter.ebooks.rb.reader import Reader
reader = Reader(stream, log, options.input_encoding)
opf = reader.extract_content(getcwd())
@@ -7,7 +7,7 @@ __docformat__ = 'restructuredtext en'
import os
from calibre.customize.conversion import OutputFormatPlugin, OptionRecommendation
from ebook_converter.customize.conversion import OutputFormatPlugin, OptionRecommendation
class RBOutput(OutputFormatPlugin):
@@ -23,7 +23,7 @@ class RBOutput(OutputFormatPlugin):
help=_('Add Table of Contents to beginning of the book.'))}
def convert(self, oeb_book, output_path, input_plugin, opts, log):
from calibre.ebooks.rb.writer import RBWriter
from ebook_converter.ebooks.rb.writer import RBWriter
close = False
if not hasattr(output_path, 'write'):
@@ -8,10 +8,10 @@ __docformat__ = 'restructuredtext en'
import os
from calibre.customize.conversion import InputFormatPlugin, OptionRecommendation
from calibre.constants import numeric_version
from calibre import walk
from polyglot.builtins import unicode_type
from ebook_converter.customize.conversion import InputFormatPlugin, OptionRecommendation
from ebook_converter.constants import numeric_version
from ebook_converter import walk
from ebook_converter.polyglot.builtins import unicode_type
class RecipeDisabled(Exception):
@@ -58,10 +58,10 @@ class RecipeInput(InputFormatPlugin):
def convert(self, recipe_or_file, opts, file_ext, log,
accelerators):
from calibre.web.feeds.recipes import compile_recipe
from ebook_converter.web.feeds.recipes import compile_recipe
opts.output_profile.flow_size = 0
if file_ext == 'downloaded_recipe':
from calibre.utils.zipfile import ZipFile
from ebook_converter.utils.zipfile import ZipFile
zf = ZipFile(recipe_or_file, 'r')
zf.extractall()
zf.close()
@@ -72,7 +72,7 @@ class RecipeInput(InputFormatPlugin):
self.recipe_object = recipe(opts, log, self.report_progress)
else:
if os.environ.get('CALIBRE_RECIPE_URN'):
from calibre.web.feeds.recipes.collection import get_custom_recipe, get_builtin_recipe_by_id
from ebook_converter.web.feeds.recipes.collection import get_custom_recipe, get_builtin_recipe_by_id
urn = os.environ['CALIBRE_RECIPE_URN']
log('Downloading recipe urn: ' + urn)
rtype, recipe_id = urn.partition(':')[::2]
@@ -93,7 +93,7 @@ class RecipeInput(InputFormatPlugin):
recipe = compile_recipe(self.recipe_source)
log('Using custom recipe')
else:
from calibre.web.feeds.recipes.collection import (
from ebook_converter.web.feeds.recipes.collection import (
get_builtin_recipe_by_title, get_builtin_recipe_titles)
title = getattr(opts, 'original_recipe_input_arg', recipe_or_file)
title = os.path.basename(title).rpartition('.')[0]
@@ -157,7 +157,7 @@ class RecipeInput(InputFormatPlugin):
def specialize(self, oeb, opts, log, output_fmt):
if opts.no_inline_navbars:
from calibre.ebooks.oeb.base import XPath
from ebook_converter.ebooks.oeb.base import XPath
for item in oeb.spine:
for div in XPath('//h:div[contains(@class, "calibre_navbar")]')(item.data):
div.getparent().remove(div)
@@ -4,8 +4,8 @@ __copyright__ = '2008, Kovid Goyal <kovid at kovidgoyal.net>'
import os, glob, re, textwrap
from calibre.customize.conversion import InputFormatPlugin, OptionRecommendation
from polyglot.builtins import iteritems, filter, getcwd, as_bytes
from ebook_converter.customize.conversion import InputFormatPlugin, OptionRecommendation
from ebook_converter.polyglot.builtins import iteritems, filter, getcwd, as_bytes
border_style_map = {
'single' : 'solid',
@@ -53,7 +53,7 @@ class RTFInput(InputFormatPlugin):
}
def generate_xml(self, stream):
from calibre.ebooks.rtf2xml.ParseRtf import ParseRtf
from ebook_converter.ebooks.rtf2xml.ParseRtf import ParseRtf
ofile = u'dataxml.xml'
run_lev, debug_dir, indent_out = 1, None, 0
if getattr(self.opts, 'debug_pipeline', None) is not None:
@@ -117,7 +117,7 @@ class RTFInput(InputFormatPlugin):
return f.read()
def extract_images(self, picts):
from calibre.utils.imghdr import what
from ebook_converter.utils.imghdr import what
from binascii import unhexlify
self.log('Extracting images...')
@@ -167,7 +167,7 @@ class RTFInput(InputFormatPlugin):
if self.opts.ignore_wmf:
os.remove(name)
return '__REMOVE_ME__'
from calibre.ebooks.covers import message_image
from ebook_converter.ebooks.covers import message_image
if self.default_img is None:
self.default_img = message_image('Conversion of WMF images is not supported.'
' Use Microsoft Word or OpenOffice to save this RTF file'
@@ -178,7 +178,7 @@ class RTFInput(InputFormatPlugin):
return name
def rasterize_wmf(self, name):
from calibre.utils.wmf.parse import wmf_unwrap
from ebook_converter.utils.wmf.parse import wmf_unwrap
with open(name, 'rb') as f:
data = f.read()
data = wmf_unwrap(data)
@@ -247,11 +247,11 @@ class RTFInput(InputFormatPlugin):
def convert(self, stream, options, file_ext, log,
accelerators):
from lxml import etree
from calibre.ebooks.metadata.meta import get_metadata
from calibre.ebooks.metadata.opf2 import OPFCreator
from calibre.ebooks.rtf2xml.ParseRtf import RtfInvalidCodeException
from calibre.ebooks.rtf.input import InlineClass
from calibre.utils.xml_parse import safe_xml_fromstring
from ebook_converter.ebooks.metadata.meta import get_metadata
from ebook_converter.ebooks.metadata.opf2 import OPFCreator
from ebook_converter.ebooks.rtf2xml.ParseRtf import RtfInvalidCodeException
from ebook_converter.ebooks.rtf.input import InlineClass
from ebook_converter.utils.xml_parse import safe_xml_fromstring
self.opts = options
self.log = log
self.log('Converting RTF to XML...')
@@ -7,7 +7,7 @@ __docformat__ = 'restructuredtext en'
import os
from calibre.customize.conversion import OutputFormatPlugin
from ebook_converter.customize.conversion import OutputFormatPlugin
class RTFOutput(OutputFormatPlugin):
@@ -18,7 +18,7 @@ class RTFOutput(OutputFormatPlugin):
commit_name = 'rtf_output'
def convert(self, oeb_book, output_path, input_plugin, opts, log):
from calibre.ebooks.rtf.rtfml import RTFMLizer
from ebook_converter.ebooks.rtf.rtfml import RTFMLizer
rtfmlitzer = RTFMLizer(log)
content = rtfmlitzer.extract_content(oeb_book, opts)
@@ -7,10 +7,10 @@ __docformat__ = 'restructuredtext en'
import os
from calibre.customize.conversion import InputFormatPlugin
from calibre.ptempfile import TemporaryDirectory
from calibre.utils.filenames import ascii_filename
from polyglot.builtins import unicode_type
from ebook_converter.customize.conversion import InputFormatPlugin
from ebook_converter.ptempfile import TemporaryDirectory
from ebook_converter.utils.filenames import ascii_filename
from ebook_converter.polyglot.builtins import unicode_type
HTML_TEMPLATE = '<html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"/><title>%s</title></head><body>\n%s\n</body></html>'
@@ -33,9 +33,9 @@ class SNBInput(InputFormatPlugin):
accelerators):
import uuid
from calibre.ebooks.oeb.base import DirContainer
from calibre.ebooks.snb.snbfile import SNBFile
from calibre.utils.xml_parse import safe_xml_fromstring
from ebook_converter.ebooks.oeb.base import DirContainer
from ebook_converter.ebooks.snb.snbfile import SNBFile
from ebook_converter.utils.xml_parse import safe_xml_fromstring
log.debug("Parsing SNB file...")
snbFile = SNBFile()
@@ -47,7 +47,7 @@ class SNBInput(InputFormatPlugin):
log.debug("Invalid SNB file")
raise ValueError("Invalid SNB file")
log.debug("Handle meta data ...")
from calibre.ebooks.conversion.plumber import create_oebbook
from ebook_converter.ebooks.conversion.plumber import create_oebbook
oeb = create_oebbook(log, None, options,
encoding=options.input_encoding, populate=False)
meta = snbFile.GetFileStream('snbf/book.snbf')
@@ -7,10 +7,10 @@ __docformat__ = 'restructuredtext en'
import os
from calibre.customize.conversion import OutputFormatPlugin, OptionRecommendation
from calibre.ptempfile import TemporaryDirectory
from calibre.constants import __appname__, __version__
from polyglot.builtins import unicode_type
from ebook_converter.customize.conversion import OutputFormatPlugin, OptionRecommendation
from ebook_converter.ptempfile import TemporaryDirectory
from ebook_converter.constants import __appname__, __version__
from ebook_converter.polyglot.builtins import unicode_type
class SNBOutput(OutputFormatPlugin):
@@ -51,11 +51,11 @@ class SNBOutput(OutputFormatPlugin):
def convert(self, oeb_book, output_path, input_plugin, opts, log):
from lxml import etree
from calibre.ebooks.snb.snbfile import SNBFile
from calibre.ebooks.snb.snbml import SNBMLizer, ProcessFileName
from ebook_converter.ebooks.snb.snbfile import SNBFile
from ebook_converter.ebooks.snb.snbml import SNBMLizer, ProcessFileName
self.opts = opts
from calibre.ebooks.oeb.transforms.rasterize import SVGRasterizer, Unavailable
from ebook_converter.ebooks.oeb.transforms.rasterize import SVGRasterizer, Unavailable
try:
rasterizer = SVGRasterizer()
rasterizer(oeb_book, opts)
@@ -176,7 +176,7 @@ class SNBOutput(OutputFormatPlugin):
mergeLast = False
lastName = None
for item in s:
from calibre.ebooks.oeb.base import OEB_DOCS, OEB_IMAGES
from ebook_converter.ebooks.oeb.base import OEB_DOCS, OEB_IMAGES
if m.hrefs[item.href].media_type in OEB_DOCS:
if item.href not in outputFiles:
log.debug('File %s is unused in TOC. Continue in last chapter' % item.href)
@@ -225,7 +225,7 @@ class SNBOutput(OutputFormatPlugin):
snbFile.Output(output_path)
def HandleImage(self, imageData, imagePath):
from calibre.utils.img import image_from_data, resize_image, image_to_data
from ebook_converter.utils.img import image_from_data, resize_image, image_to_data
img = image_from_data(imageData)
x, y = img.width(), img.height()
if self.opts:
@@ -250,10 +250,10 @@ class SNBOutput(OutputFormatPlugin):
if __name__ == '__main__':
from calibre.ebooks.oeb.reader import OEBReader
from calibre.ebooks.oeb.base import OEBBook
from calibre.ebooks.conversion.preprocess import HTMLPreProcessor
from calibre.customize.profiles import HanlinV3Output
from ebook_converter.ebooks.oeb.reader import OEBReader
from ebook_converter.ebooks.oeb.base import OEBBook
from ebook_converter.ebooks.conversion.preprocess import HTMLPreProcessor
from ebook_converter.customize.profiles import HanlinV3Output
class OptionValues(object):
pass
@@ -262,7 +262,7 @@ if __name__ == '__main__':
opts.output_profile = HanlinV3Output(None)
html_preprocessor = HTMLPreProcessor(None, None, opts)
from calibre.utils.logging import default_log
from ebook_converter.utils.logging import default_log
oeb = OEBBook(default_log, html_preprocessor)
reader = OEBReader
reader()(oeb, '/tmp/bbb/processed/')
@@ -7,7 +7,7 @@ __docformat__ = 'restructuredtext en'
from io import BytesIO
from calibre.customize.conversion import InputFormatPlugin
from ebook_converter.customize.conversion import InputFormatPlugin
class TCRInput(InputFormatPlugin):
@@ -19,7 +19,7 @@ class TCRInput(InputFormatPlugin):
commit_name = 'tcr_input'
def convert(self, stream, options, file_ext, log, accelerators):
from calibre.ebooks.compression.tcr import decompress
from ebook_converter.ebooks.compression.tcr import decompress
log.info('Decompressing text...')
raw_txt = decompress(stream)
@@ -27,7 +27,7 @@ class TCRInput(InputFormatPlugin):
log.info('Converting text to OEB...')
stream = BytesIO(raw_txt)
from calibre.customize.ui import plugin_for_input_format
from ebook_converter.customize.ui import plugin_for_input_format
txt_plugin = plugin_for_input_format('txt')
for opt in txt_plugin.options:
@@ -7,7 +7,7 @@ __docformat__ = 'restructuredtext en'
import os
from calibre.customize.conversion import OutputFormatPlugin, \
from ebook_converter.customize.conversion import OutputFormatPlugin, \
OptionRecommendation
@@ -25,8 +25,8 @@ class TCROutput(OutputFormatPlugin):
'The default is utf-8.'))}
def convert(self, oeb_book, output_path, input_plugin, opts, log):
from calibre.ebooks.txt.txtml import TXTMLizer
from calibre.ebooks.compression.tcr import compress
from ebook_converter.ebooks.txt.txtml import TXTMLizer
from ebook_converter.ebooks.compression.tcr import compress
close = False
if not hasattr(output_path, 'write'):
@@ -7,9 +7,9 @@ __docformat__ = 'restructuredtext en'
import os
from calibre import _ent_pat, walk, xml_entity_to_unicode
from calibre.customize.conversion import InputFormatPlugin, OptionRecommendation
from polyglot.builtins import getcwd
from ebook_converter import _ent_pat, walk, xml_entity_to_unicode
from ebook_converter.customize.conversion import InputFormatPlugin, OptionRecommendation
from ebook_converter.polyglot.builtins import getcwd
MD_EXTENSIONS = {
'abbr': _('Abbreviations'),
@@ -129,10 +129,10 @@ class TXTInput(InputFormatPlugin):
def convert(self, stream, options, file_ext, log,
accelerators):
from calibre.ebooks.conversion.preprocess import DocAnalysis, Dehyphenator
from calibre.ebooks.chardet import detect
from calibre.utils.zipfile import ZipFile
from calibre.ebooks.txt.processor import (convert_basic,
from ebook_converter.ebooks.conversion.preprocess import DocAnalysis, Dehyphenator
from ebook_converter.ebooks.chardet import detect
from ebook_converter.utils.zipfile import ZipFile
from ebook_converter.ebooks.txt.processor import (convert_basic,
convert_markdown_with_metadata, separate_paragraphs_single_line,
separate_paragraphs_print_formatted, preserve_spaces,
detect_paragraph_type, detect_formatting_type,
@@ -225,7 +225,7 @@ class TXTInput(InputFormatPlugin):
txt = separate_paragraphs_print_formatted(txt)
txt = block_to_single_line(txt)
elif options.paragraph_type == 'unformatted':
from calibre.ebooks.conversion.utils import HeuristicProcessor
from ebook_converter.ebooks.conversion.utils import HeuristicProcessor
# unwrap lines based on punctuation
docanalysis = DocAnalysis('txt', txt)
length = docanalysis.line_length(.5)
@@ -275,7 +275,7 @@ class TXTInput(InputFormatPlugin):
html = convert_basic(txt, epub_split_size_kb=flow_size)
# Run the HTMLized text through the html processing plugin.
from calibre.customize.ui import plugin_for_input_format
from ebook_converter.customize.ui import plugin_for_input_format
html_input = plugin_for_input_format('html')
for opt in html_input.options:
setattr(options, opt.option.name, opt.recommended_value)
@@ -292,9 +292,9 @@ class TXTInput(InputFormatPlugin):
# Set metadata from file.
if input_mi is None:
from calibre.customize.ui import get_file_type_metadata
from ebook_converter.customize.ui import get_file_type_metadata
input_mi = get_file_type_metadata(stream, file_ext)
from calibre.ebooks.oeb.transforms.metadata import meta_info_to_oeb_metadata
from ebook_converter.ebooks.oeb.transforms.metadata import meta_info_to_oeb_metadata
meta_info_to_oeb_metadata(input_mi, oeb.metadata, log)
self.html_postprocess_title = input_mi.title
@@ -9,9 +9,9 @@ import os
import shutil
from calibre.customize.conversion import OutputFormatPlugin, \
from ebook_converter.customize.conversion import OutputFormatPlugin, \
OptionRecommendation
from calibre.ptempfile import TemporaryDirectory, TemporaryFile
from ebook_converter.ptempfile import TemporaryDirectory, TemporaryFile
NEWLINE_TYPES = ['system', 'unix', 'old_mac', 'windows']
@@ -84,15 +84,15 @@ class TXTOutput(OutputFormatPlugin):
}
def convert(self, oeb_book, output_path, input_plugin, opts, log):
from calibre.ebooks.txt.txtml import TXTMLizer
from calibre.utils.cleantext import clean_ascii_chars
from calibre.ebooks.txt.newlines import specified_newlines, TxtNewlines
from ebook_converter.ebooks.txt.txtml import TXTMLizer
from ebook_converter.utils.cleantext import clean_ascii_chars
from ebook_converter.ebooks.txt.newlines import specified_newlines, TxtNewlines
if opts.txt_output_formatting.lower() == 'markdown':
from calibre.ebooks.txt.markdownml import MarkdownMLizer
from ebook_converter.ebooks.txt.markdownml import MarkdownMLizer
self.writer = MarkdownMLizer(log)
elif opts.txt_output_formatting.lower() == 'textile':
from calibre.ebooks.txt.textileml import TextileMLizer
from ebook_converter.ebooks.txt.textileml import TextileMLizer
self.writer = TextileMLizer(log)
else:
self.writer = TXTMLizer(log)
@@ -127,8 +127,8 @@ class TXTZOutput(TXTOutput):
file_type = 'txtz'
def convert(self, oeb_book, output_path, input_plugin, opts, log):
from calibre.ebooks.oeb.base import OEB_IMAGES
from calibre.utils.zipfile import ZipFile
from ebook_converter.ebooks.oeb.base import OEB_IMAGES
from ebook_converter.utils.zipfile import ZipFile
from lxml import etree
with TemporaryDirectory('_txtz_output') as tdir:
+36 -36
View File
@@ -8,19 +8,19 @@ __docformat__ = 'restructuredtext en'
import os, re, sys, shutil, pprint, json
from functools import partial
from calibre.customize.conversion import OptionRecommendation, DummyReporter
from calibre.customize.ui import input_profiles, output_profiles, \
from ebook_converter.customize.conversion import OptionRecommendation, DummyReporter
from ebook_converter.customize.ui import input_profiles, output_profiles, \
plugin_for_input_format, plugin_for_output_format, \
available_input_formats, available_output_formats, \
run_plugins_on_preprocess, run_plugins_on_postprocess
from calibre.ebooks.conversion.preprocess import HTMLPreProcessor
from calibre.ptempfile import PersistentTemporaryDirectory
from calibre.utils.date import parse_date
from calibre.utils.zipfile import ZipFile
from calibre import (extract, walk, isbytestring, filesystem_encoding,
from ebook_converter.ebooks.conversion.preprocess import HTMLPreProcessor
from ebook_converter.ptempfile import PersistentTemporaryDirectory
from ebook_converter.utils.date import parse_date
from ebook_converter.utils.zipfile import ZipFile
from ebook_converter import (extract, walk, isbytestring, filesystem_encoding,
get_types_map)
from calibre.constants import __version__
from polyglot.builtins import unicode_type, string_or_bytes, map
from ebook_converter.constants import __version__
from ebook_converter.polyglot.builtins import unicode_type, string_or_bytes, map
DEBUG_README=b'''
This debug directory contains snapshots of the e-book as it passes through the
@@ -799,7 +799,7 @@ OptionRecommendation(name='search_replace',
files = list(walk(tdir))
files = [f if isinstance(f, unicode_type) else f.decode(filesystem_encoding)
for f in files]
from calibre.customize.ui import available_input_formats
from ebook_converter.customize.ui import available_input_formats
fmts = set(available_input_formats())
fmts -= {'htm', 'html', 'xhtm', 'xhtml'}
fmts -= set(ARCHIVE_FMTS)
@@ -899,7 +899,7 @@ OptionRecommendation(name='search_replace',
self.changed_options.add(rec)
def opts_to_mi(self, mi):
from calibre.ebooks.metadata import string_to_authors
from ebook_converter.ebooks.metadata import string_to_authors
for x in self.metadata_option_names:
val = getattr(self.opts, x, None)
if val is not None:
@@ -923,10 +923,10 @@ OptionRecommendation(name='search_replace',
setattr(mi, x, val)
def download_cover(self, url):
from calibre import browser
from ebook_converter import browser
from PIL import Image
import io
from calibre.ptempfile import PersistentTemporaryFile
from ebook_converter.ptempfile import PersistentTemporaryFile
self.log('Downloading cover from %r'%url)
br = browser()
raw = br.open_novisit(url).read()
@@ -942,8 +942,8 @@ OptionRecommendation(name='search_replace',
Read all metadata specified by the user. Command line options override
metadata from a specified OPF file.
'''
from calibre.ebooks.metadata import MetaInformation
from calibre.ebooks.metadata.opf2 import OPF
from ebook_converter.ebooks.metadata import MetaInformation
from ebook_converter.ebooks.metadata.opf2 import OPF
mi = MetaInformation(None, [])
if self.opts.read_metadata_from_opf is not None:
self.opts.read_metadata_from_opf = os.path.abspath(
@@ -1003,7 +1003,7 @@ OptionRecommendation(name='search_replace',
if self.opts.verbose > 1:
self.log.debug('Resolved conversion options')
try:
self.log.debug('calibre version:', __version__)
self.log.debug('ebook_converter version:', __version__)
odict = dict(self.opts.__dict__)
for x in ('username', 'password'):
odict.pop(x, None)
@@ -1019,7 +1019,7 @@ OptionRecommendation(name='search_replace',
pass
def dump_oeb(self, oeb, out_dir):
from calibre.ebooks.oeb.writer import OEBWriter
from ebook_converter.ebooks.oeb.writer import OEBWriter
w = OEBWriter(pretty_print=self.opts.pretty_print)
w(oeb, out_dir)
@@ -1054,7 +1054,7 @@ OptionRecommendation(name='search_replace',
self.flush()
if self.opts.embed_all_fonts or self.opts.embed_font_family:
# Start the threaded font scanner now, for performance
from calibre.utils.fonts.scanner import font_scanner # noqa
from ebook_converter.utils.fonts.scanner import font_scanner # noqa
import css_parser, logging
css_parser.log.setLevel(logging.WARN)
get_types_map() # Ensure the mimetypes module is intialized
@@ -1072,7 +1072,7 @@ OptionRecommendation(name='search_replace',
shutil.rmtree(x)
# Run any preprocess plugins
from calibre.customize.ui import run_plugins_on_preprocess
from ebook_converter.customize.ui import run_plugins_on_preprocess
self.input = run_plugins_on_preprocess(self.input)
self.flush()
@@ -1091,7 +1091,7 @@ OptionRecommendation(name='search_replace',
if self.input_fmt == 'azw4' and self.output_plugin.file_type == 'pdf':
self.ui_reporter(0.01, 'AZW4 files are simply wrappers around PDF files.'
' Skipping the conversion and unwrapping the embedded PDF instead')
from calibre.ebooks.azw4.reader import unwrap
from ebook_converter.ebooks.azw4.reader import unwrap
unwrap(stream, self.output)
self.ui_reporter(1.)
self.log(self.output_fmt.upper(), 'output written to', self.output)
@@ -1136,9 +1136,9 @@ OptionRecommendation(name='search_replace',
self.oeb.plumber_output_format = self.output_fmt or ''
from calibre.ebooks.oeb.transforms.data_url import DataURL
from ebook_converter.ebooks.oeb.transforms.data_url import DataURL
DataURL()(self.oeb, self.opts)
from calibre.ebooks.oeb.transforms.guide import Clean
from ebook_converter.ebooks.oeb.transforms.guide import Clean
Clean()(self.oeb, self.opts)
pr(0.1)
self.flush()
@@ -1146,15 +1146,15 @@ OptionRecommendation(name='search_replace',
self.opts.source = self.opts.input_profile
self.opts.dest = self.opts.output_profile
from calibre.ebooks.oeb.transforms.jacket import RemoveFirstImage
from ebook_converter.ebooks.oeb.transforms.jacket import RemoveFirstImage
RemoveFirstImage()(self.oeb, self.opts, self.user_metadata)
from calibre.ebooks.oeb.transforms.metadata import MergeMetadata
from ebook_converter.ebooks.oeb.transforms.metadata import MergeMetadata
MergeMetadata()(self.oeb, self.user_metadata, self.opts,
override_input_metadata=self.override_input_metadata)
pr(0.2)
self.flush()
from calibre.ebooks.oeb.transforms.structure import DetectStructure
from ebook_converter.ebooks.oeb.transforms.structure import DetectStructure
DetectStructure()(self.oeb, self.opts)
pr(0.35)
self.flush()
@@ -1166,7 +1166,7 @@ OptionRecommendation(name='search_replace',
if item is not None and item.count() == 0:
self.oeb.toc.remove(item)
from calibre.ebooks.oeb.transforms.flatcss import CSSFlattener
from ebook_converter.ebooks.oeb.transforms.flatcss import CSSFlattener
fbase = self.opts.base_font_size
if fbase < 1e-4:
fbase = float(self.opts.dest.fbase)
@@ -1180,7 +1180,7 @@ OptionRecommendation(name='search_replace',
self.log.error('Invalid font size key: %r ignoring'%fkey)
fkey = self.opts.dest.fkey
from calibre.ebooks.oeb.transforms.jacket import Jacket
from ebook_converter.ebooks.oeb.transforms.jacket import Jacket
Jacket()(self.oeb, self.opts, self.user_metadata)
pr(0.4)
self.flush()
@@ -1205,11 +1205,11 @@ OptionRecommendation(name='search_replace',
if self.opts.linearize_tables and \
self.output_plugin.file_type not in ('mobi', 'lrf'):
from calibre.ebooks.oeb.transforms.linearize_tables import LinearizeTables
from ebook_converter.ebooks.oeb.transforms.linearize_tables import LinearizeTables
LinearizeTables()(self.oeb, self.opts)
if self.opts.unsmarten_punctuation:
from calibre.ebooks.oeb.transforms.unsmarten import UnsmartenPunctuation
from ebook_converter.ebooks.oeb.transforms.unsmarten import UnsmartenPunctuation
UnsmartenPunctuation()(self.oeb, self.opts)
mobi_file_type = getattr(self.opts, 'mobi_file_type', 'old')
@@ -1235,23 +1235,23 @@ OptionRecommendation(name='search_replace',
self.opts.insert_blank_line = oibl
self.opts.remove_paragraph_spacing = orps
from calibre.ebooks.oeb.transforms.page_margin import \
from ebook_converter.ebooks.oeb.transforms.page_margin import \
RemoveFakeMargins, RemoveAdobeMargins
RemoveFakeMargins()(self.oeb, self.log, self.opts)
RemoveAdobeMargins()(self.oeb, self.log, self.opts)
if self.opts.embed_all_fonts:
from calibre.ebooks.oeb.transforms.embed_fonts import EmbedFonts
from ebook_converter.ebooks.oeb.transforms.embed_fonts import EmbedFonts
EmbedFonts()(self.oeb, self.log, self.opts)
if self.opts.subset_embedded_fonts and self.output_plugin.file_type != 'pdf':
from calibre.ebooks.oeb.transforms.subset import SubsetFonts
from ebook_converter.ebooks.oeb.transforms.subset import SubsetFonts
SubsetFonts()(self.oeb, self.log, self.opts)
pr(0.9)
self.flush()
from calibre.ebooks.oeb.transforms.trimmanifest import ManifestTrimmer
from ebook_converter.ebooks.oeb.transforms.trimmanifest import ManifestTrimmer
self.log.info('Cleaning up manifest...')
trimmer = ManifestTrimmer()
@@ -1296,7 +1296,7 @@ def create_oebbook(log, path_or_stream, opts, reader=None,
'''
Create an OEBBook.
'''
from calibre.ebooks.oeb.base import OEBBook
from ebook_converter.ebooks.oeb.base import OEBBook
html_preprocessor = HTMLPreProcessor(log, opts, regex_wizard_callback=regex_wizard_callback)
if not encoding:
encoding = None
@@ -1310,7 +1310,7 @@ def create_oebbook(log, path_or_stream, opts, reader=None,
log('Parsing all content...')
oeb.removed_items_to_ignore = removed_items
if reader is None:
from calibre.ebooks.oeb.reader import OEBReader
from ebook_converter.ebooks.oeb.reader import OEBReader
reader = OEBReader
reader()(oeb, path_or_stream)
@@ -1318,7 +1318,7 @@ def create_oebbook(log, path_or_stream, opts, reader=None,
def create_dummy_plumber(input_format, output_format):
from calibre.utils.logging import Log
from ebook_converter.utils.logging import Log
input_format = input_format.lower()
output_format = output_format.lower()
output_path = 'dummy.'+output_format
+12 -12
View File
@@ -9,8 +9,8 @@ __docformat__ = 'restructuredtext en'
import functools, re, json
from math import ceil
from calibre import entity_to_unicode, as_unicode
from polyglot.builtins import unicode_type, range
from ebook_converter import entity_to_unicode, as_unicode
from ebook_converter.polyglot.builtins import unicode_type, range
XMLDECL_RE = re.compile(r'^\s*<[?]xml.*?[?]>')
SVG_NS = 'http://www.w3.org/2000/svg'
@@ -70,9 +70,9 @@ def wrap_lines(match):
def smarten_punctuation(html, log=None):
from calibre.utils.smartypants import smartyPants
from calibre.ebooks.chardet import substitute_entites
from calibre.ebooks.conversion.utils import HeuristicProcessor
from ebook_converter.utils.smartypants import smartyPants
from ebook_converter.ebooks.chardet import substitute_entites
from ebook_converter.ebooks.conversion.utils import HeuristicProcessor
preprocessor = HeuristicProcessor(log=log)
from uuid import uuid4
start = 'calibre-smartypants-'+unicode_type(uuid4())
@@ -321,7 +321,7 @@ class CSSPreProcessor(object):
return start + end
def __call__(self, data, add_namespace=False):
from calibre.ebooks.oeb.base import XHTML_CSS_NAMESPACE
from ebook_converter.ebooks.oeb.base import XHTML_CSS_NAMESPACE
data = self.MS_PAT.sub(self.ms_sub, data)
if not add_namespace:
return data
@@ -497,7 +497,7 @@ class HTMLPreProcessor(object):
# Function for processing search and replace
def do_search_replace(search_pattern, replace_txt):
from calibre.ebooks.conversion.search_replace import compile_regular_expression
from ebook_converter.ebooks.conversion.search_replace import compile_regular_expression
try:
search_re = compile_regular_expression(search_pattern)
if not replace_txt:
@@ -595,7 +595,7 @@ class HTMLPreProcessor(object):
html = dehyphenator(html,'html', length)
if is_pdftohtml:
from calibre.ebooks.conversion.utils import HeuristicProcessor
from ebook_converter.ebooks.conversion.utils import HeuristicProcessor
pdf_markup = HeuristicProcessor(self.extra_opts, None)
totalwords = 0
if pdf_markup.get_word_count(html) > 7000:
@@ -614,15 +614,15 @@ class HTMLPreProcessor(object):
html = XMLDECL_RE.sub('', html)
if getattr(self.extra_opts, 'asciiize', False):
from calibre.utils.localization import get_udc
from calibre.utils.mreplace import MReplace
from ebook_converter.utils.localization import get_udc
from ebook_converter.utils.mreplace import MReplace
unihandecoder = get_udc()
mr = MReplace(data={'«':'&lt;'*3, '»':'&gt;'*3})
html = mr.mreplace(html)
html = unihandecoder.decode(html)
if getattr(self.extra_opts, 'enable_heuristics', False):
from calibre.ebooks.conversion.utils import HeuristicProcessor
from ebook_converter.ebooks.conversion.utils import HeuristicProcessor
preprocessor = HeuristicProcessor(self.extra_opts, self.log)
html = preprocessor(html)
@@ -637,7 +637,7 @@ class HTMLPreProcessor(object):
except AttributeError:
unsupported_unicode_chars = ''
if unsupported_unicode_chars:
from calibre.utils.localization import get_udc
from ebook_converter.utils.localization import get_udc
unihandecoder = get_udc()
for char in unsupported_unicode_chars:
asciichar = unihandecoder.decode(char)
+8 -8
View File
@@ -8,10 +8,10 @@ __docformat__ = 'restructuredtext en'
import re
from math import ceil
from calibre.ebooks.conversion.preprocess import DocAnalysis, Dehyphenator
from calibre.utils.logging import default_log
from calibre.utils.wordcount import get_wordcount_obj
from polyglot.builtins import unicode_type
from ebook_converter.ebooks.conversion.preprocess import DocAnalysis, Dehyphenator
from ebook_converter.utils.logging import default_log
from ebook_converter.utils.wordcount import get_wordcount_obj
from ebook_converter.polyglot.builtins import unicode_type
class HeuristicProcessor(object):
@@ -49,7 +49,7 @@ class HeuristicProcessor(object):
return '<meta name="generator" content="ABBYY FineReader' in src[:1000]
def chapter_head(self, match):
from calibre.utils.html2text import html2text
from ebook_converter.utils.html2text import html2text
chap = match.group('chap')
title = match.group('title')
if not title:
@@ -400,7 +400,7 @@ class HeuristicProcessor(object):
return content
def txt_process(self, match):
from calibre.ebooks.txt.processor import convert_basic, separate_paragraphs_single_line
from ebook_converter.ebooks.txt.processor import convert_basic, separate_paragraphs_single_line
content = match.group('text')
content = separate_paragraphs_single_line(content)
content = convert_basic(content, epub_split_size_kb=0)
@@ -412,7 +412,7 @@ class HeuristicProcessor(object):
self.log.debug("Running Text Processing")
outerhtml = re.compile(r'.*?(?<=<pre>)(?P<text>.*?)</pre>', re.IGNORECASE|re.DOTALL)
html = outerhtml.sub(self.txt_process, html)
from calibre.ebooks.conversion.preprocess import convert_entities
from ebook_converter.ebooks.conversion.preprocess import convert_entities
html = re.sub(r'&(\S+?);', convert_entities, html)
else:
# Add markup naively
@@ -616,7 +616,7 @@ class HeuristicProcessor(object):
elif re.match('^<img', replacement_break):
scene_break = self.scene_break_open+replacement_break+'</p>'
else:
from calibre.utils.html2text import html2text
from ebook_converter.utils.html2text import html2text
replacement_break = html2text(replacement_break)
replacement_break = re.sub('\\s', '&nbsp;', replacement_break)
scene_break = self.scene_break_open+replacement_break+'</p>'
+1 -1
View File
@@ -7,7 +7,7 @@ __copyright__ = '2013, Kovid Goyal <kovid at kovidgoyal.net>'
import numbers
from collections import OrderedDict
from polyglot.builtins import iteritems
from ebook_converter.polyglot.builtins import iteritems
class Inherit(object):
+2 -2
View File
@@ -6,7 +6,7 @@ __license__ = 'GPL v3'
__copyright__ = '2013, Kovid Goyal <kovid at kovidgoyal.net>'
from collections import OrderedDict
from calibre.ebooks.docx.block_styles import ( # noqa
from ebook_converter.ebooks.docx.block_styles import ( # noqa
inherit, simple_color, LINE_STYLES, simple_float, binary_property, read_shd)
# Read from XML {{{
@@ -89,7 +89,7 @@ def read_lang(parent, dest, XPath, get):
except (ValueError, TypeError):
ans = val
else:
from calibre.ebooks.docx.lcid import lcid
from ebook_converter.ebooks.docx.lcid import lcid
val = lcid.get(code, None)
if val:
ans = val
+2 -2
View File
@@ -6,7 +6,7 @@ __license__ = 'GPL v3'
__copyright__ = '2013, Kovid Goyal <kovid at kovidgoyal.net>'
import os
from polyglot.builtins import itervalues, range
from ebook_converter.polyglot.builtins import itervalues, range
NBSP = '\xa0'
@@ -218,7 +218,7 @@ def cleanup_markup(log, root, styles, dest_dir, detect_cover, XPath):
img = img[0]
path = os.path.join(dest_dir, img.get('src'))
if os.path.exists(path) and before_count(root, img, limit=10) < 5:
from calibre.utils.imghdr import identify
from ebook_converter.utils.imghdr import identify
try:
with lopen(path, 'rb') as imf:
fmt, width, height = identify(imf)
+11 -11
View File
@@ -9,16 +9,16 @@ import os, sys, shutil
from lxml import etree
from calibre import walk, guess_type
from calibre.ebooks.metadata import string_to_authors, authors_to_sort_string
from calibre.ebooks.metadata.book.base import Metadata
from calibre.ebooks.docx import InvalidDOCX
from calibre.ebooks.docx.names import DOCXNamespace
from calibre.ptempfile import PersistentTemporaryDirectory
from calibre.utils.localization import canonicalize_lang
from calibre.utils.logging import default_log
from calibre.utils.zipfile import ZipFile
from calibre.utils.xml_parse import safe_xml_fromstring
from ebook_converter import walk, guess_type
from ebook_converter.ebooks.metadata import string_to_authors, authors_to_sort_string
from ebook_converter.ebooks.metadata.book.base import Metadata
from ebook_converter.ebooks.docx import InvalidDOCX
from ebook_converter.ebooks.docx.names import DOCXNamespace
from ebook_converter.ptempfile import PersistentTemporaryDirectory
from ebook_converter.utils.localization import canonicalize_lang
from ebook_converter.utils.logging import default_log
from ebook_converter.utils.zipfile import ZipFile
from ebook_converter.utils.xml_parse import safe_xml_fromstring
def fromstring(raw, parser=None):
@@ -113,7 +113,7 @@ class DOCX(object):
except:
self.log.exception('DOCX appears to be invalid ZIP file, trying a'
' more forgiving ZIP parser')
from calibre.utils.localunzip import extractall
from ebook_converter.utils.localunzip import extractall
stream.seek(0)
extractall(stream, self.tdir)
+2 -2
View File
@@ -7,8 +7,8 @@ __copyright__ = '2013, Kovid Goyal <kovid at kovidgoyal.net>'
import re
from calibre.ebooks.docx.index import process_index, polish_index_markup
from polyglot.builtins import iteritems, native_string_type
from ebook_converter.ebooks.docx.index import process_index, polish_index_markup
from ebook_converter.polyglot.builtins import iteritems, native_string_type
class Field(object):
+6 -6
View File
@@ -8,12 +8,12 @@ __copyright__ = '2013, Kovid Goyal <kovid at kovidgoyal.net>'
import os, re
from collections import namedtuple
from calibre.ebooks.docx.block_styles import binary_property, inherit
from calibre.utils.filenames import ascii_filename
from calibre.utils.fonts.scanner import font_scanner, NoFonts
from calibre.utils.fonts.utils import panose_to_css_generic_family, is_truetype_font
from calibre.utils.icu import ord_string
from polyglot.builtins import codepoint_to_chr, iteritems, range
from ebook_converter.ebooks.docx.block_styles import binary_property, inherit
from ebook_converter.utils.filenames import ascii_filename
from ebook_converter.utils.fonts.scanner import font_scanner, NoFonts
from ebook_converter.utils.fonts.utils import panose_to_css_generic_family, is_truetype_font
from ebook_converter.utils.icu import ord_string
from ebook_converter.polyglot.builtins import codepoint_to_chr, iteritems, range
Embed = namedtuple('Embed', 'name key subsetted')
+1 -1
View File
@@ -6,7 +6,7 @@ __license__ = 'GPL v3'
__copyright__ = '2013, Kovid Goyal <kovid at kovidgoyal.net>'
from collections import OrderedDict
from polyglot.builtins import iteritems, unicode_type
from ebook_converter.polyglot.builtins import iteritems, unicode_type
class Note(object):
+7 -7
View File
@@ -9,12 +9,12 @@ import os
from lxml.html.builder import IMG, HR
from calibre.constants import iswindows
from calibre.ebooks.docx.names import barename
from calibre.utils.filenames import ascii_filename
from calibre.utils.img import resize_to_fit, image_to_data
from calibre.utils.imghdr import what
from polyglot.builtins import iteritems, itervalues
from ebook_converter.constants import iswindows
from ebook_converter.ebooks.docx.names import barename
from ebook_converter.utils.filenames import ascii_filename
from ebook_converter.utils.img import resize_to_fit, image_to_data
from ebook_converter.utils.imghdr import what
from ebook_converter.polyglot.builtins import iteritems, itervalues
class LinkedImageNotFound(ValueError):
@@ -143,7 +143,7 @@ class Images(object):
if ext == 'emf':
# For an example, see: https://bugs.launchpad.net/bugs/1224849
self.log('Found an EMF image: %s, trying to extract embedded raster image' % fname)
from calibre.utils.wmf.emf import emf_unwrap
from ebook_converter.utils.wmf.emf import emf_unwrap
try:
raw = emf_unwrap(raw)
except Exception:
+2 -2
View File
@@ -9,8 +9,8 @@ from operator import itemgetter
from lxml import etree
from calibre.utils.icu import partition_by_first_letter, sort_key
from polyglot.builtins import iteritems, filter
from ebook_converter.utils.icu import partition_by_first_letter, sort_key
from ebook_converter.polyglot.builtins import iteritems, filter
def get_applicable_xe_fields(index, xe_fields, XPath, expand):
+2 -2
View File
@@ -9,8 +9,8 @@ import re
from lxml.etree import XPath as X
from calibre.utils.filenames import ascii_text
from polyglot.builtins import iteritems
from ebook_converter.utils.filenames import ascii_text
from ebook_converter.polyglot.builtins import iteritems
# Names {{{
TRANSITIONAL_NAMES = {
+4 -4
View File
@@ -11,10 +11,10 @@ from functools import partial
from lxml.html.builder import OL, UL, SPAN
from calibre.ebooks.docx.block_styles import ParagraphStyle
from calibre.ebooks.docx.char_styles import RunStyle, inherit
from calibre.ebooks.metadata import roman
from polyglot.builtins import iteritems, unicode_type
from ebook_converter.ebooks.docx.block_styles import ParagraphStyle
from ebook_converter.ebooks.docx.char_styles import RunStyle, inherit
from ebook_converter.ebooks.metadata import roman
from ebook_converter.polyglot.builtins import iteritems, unicode_type
STYLE_MAP = {
'aiueo': 'hiragana',
+4 -4
View File
@@ -8,10 +8,10 @@ __copyright__ = '2013, Kovid Goyal <kovid at kovidgoyal.net>'
import textwrap
from collections import OrderedDict, Counter
from calibre.ebooks.docx.block_styles import ParagraphStyle, inherit, twips
from calibre.ebooks.docx.char_styles import RunStyle
from calibre.ebooks.docx.tables import TableStyle
from polyglot.builtins import iteritems, itervalues
from ebook_converter.ebooks.docx.block_styles import ParagraphStyle, inherit, twips
from ebook_converter.ebooks.docx.char_styles import RunStyle
from ebook_converter.ebooks.docx.tables import TableStyle
from ebook_converter.polyglot.builtins import iteritems, itervalues
class PageProperties(object):
+3 -3
View File
@@ -7,9 +7,9 @@ __copyright__ = '2013, Kovid Goyal <kovid at kovidgoyal.net>'
from lxml.html.builder import TABLE, TR, TD
from calibre.ebooks.docx.block_styles import inherit, read_shd as rs, read_border, binary_property, border_props, ParagraphStyle, border_to_css
from calibre.ebooks.docx.char_styles import RunStyle
from polyglot.builtins import filter, iteritems, itervalues, range, unicode_type
from ebook_converter.ebooks.docx.block_styles import inherit, read_shd as rs, read_border, binary_property, border_props, ParagraphStyle, border_to_css
from ebook_converter.ebooks.docx.char_styles import RunStyle
from ebook_converter.polyglot.builtins import filter, iteritems, itervalues, range, unicode_type
# Read from XML {{{
read_shd = rs
+18 -18
View File
@@ -12,23 +12,23 @@ from lxml import html
from lxml.html.builder import (
HTML, HEAD, TITLE, BODY, LINK, META, P, SPAN, BR, DIV, A, DT, DL, DD, H1)
from calibre import guess_type
from calibre.ebooks.docx.container import DOCX, fromstring
from calibre.ebooks.docx.names import XML, generate_anchor
from calibre.ebooks.docx.styles import Styles, inherit, PageProperties
from calibre.ebooks.docx.numbering import Numbering
from calibre.ebooks.docx.fonts import Fonts, is_symbol_font, map_symbol_text
from calibre.ebooks.docx.images import Images
from calibre.ebooks.docx.tables import Tables
from calibre.ebooks.docx.footnotes import Footnotes
from calibre.ebooks.docx.cleanup import cleanup_markup
from calibre.ebooks.docx.theme import Theme
from calibre.ebooks.docx.toc import create_toc
from calibre.ebooks.docx.fields import Fields
from calibre.ebooks.docx.settings import Settings
from calibre.ebooks.metadata.opf2 import OPFCreator
from calibre.utils.localization import canonicalize_lang, lang_as_iso639_1
from polyglot.builtins import iteritems, itervalues, filter, getcwd, map, unicode_type
from ebook_converter import guess_type
from ebook_converter.ebooks.docx.container import DOCX, fromstring
from ebook_converter.ebooks.docx.names import XML, generate_anchor
from ebook_converter.ebooks.docx.styles import Styles, inherit, PageProperties
from ebook_converter.ebooks.docx.numbering import Numbering
from ebook_converter.ebooks.docx.fonts import Fonts, is_symbol_font, map_symbol_text
from ebook_converter.ebooks.docx.images import Images
from ebook_converter.ebooks.docx.tables import Tables
from ebook_converter.ebooks.docx.footnotes import Footnotes
from ebook_converter.ebooks.docx.cleanup import cleanup_markup
from ebook_converter.ebooks.docx.theme import Theme
from ebook_converter.ebooks.docx.toc import create_toc
from ebook_converter.ebooks.docx.fields import Fields
from ebook_converter.ebooks.docx.settings import Settings
from ebook_converter.ebooks.metadata.opf2 import OPFCreator
from ebook_converter.utils.localization import canonicalize_lang, lang_as_iso639_1
from ebook_converter.polyglot.builtins import iteritems, itervalues, filter, getcwd, map, unicode_type
NBSP = '\xa0'
@@ -830,7 +830,7 @@ class Convert(object):
if __name__ == '__main__':
import shutil
from calibre.utils.logging import default_log
from ebook_converter.utils.logging import default_log
default_log.filter_level = default_log.DEBUG
dest_dir = os.path.join(getcwd(), 'docx_input')
if os.path.exists(dest_dir):
+3 -3
View File
@@ -10,9 +10,9 @@ from itertools import count
from lxml.etree import tostring
from calibre.ebooks.metadata.toc import TOC
from calibre.ebooks.oeb.polish.toc import elem_to_toc_text
from polyglot.builtins import iteritems, range
from ebook_converter.ebooks.metadata.toc import TOC
from ebook_converter.ebooks.oeb.polish.toc import elem_to_toc_text
from ebook_converter.polyglot.builtins import iteritems, range
def from_headings(body, log, namespace, num_levels=3):
-7
View File
@@ -1,7 +0,0 @@
#!/usr/bin/env python2
# vim:fileencoding=UTF-8:ts=4:sw=4:sta:et:sts=4:ai
from __future__ import absolute_import, division, print_function, unicode_literals
__license__ = 'GPL v3'
__copyright__ = '2009, Kovid Goyal <kovid@kovidgoyal.net>'
__docformat__ = 'restructuredtext en'
+6 -6
View File
@@ -13,12 +13,12 @@ Input plugin for HTML or OPF ebooks.
import os, re, sys, errno as gerrno
from calibre.ebooks.oeb.base import urlunquote
from calibre.ebooks.chardet import detect_xml_encoding
from calibre.constants import iswindows
from calibre import unicode_path, as_unicode, replace_entities
from polyglot.builtins import is_py3, unicode_type
from polyglot.urllib import urlparse, urlunparse
from ebook_converter.ebooks.oeb.base import urlunquote
from ebook_converter.ebooks.chardet import detect_xml_encoding
from ebook_converter.constants import iswindows
from ebook_converter import unicode_path, as_unicode, replace_entities
from ebook_converter.polyglot.builtins import is_py3, unicode_type
from ebook_converter.polyglot.urllib import urlparse, urlunparse
class Link(object):
+9 -9
View File
@@ -8,9 +8,9 @@ __docformat__ = 'restructuredtext en'
import textwrap, os, glob
from calibre.customize import FileTypePlugin
from calibre.constants import numeric_version
from polyglot.builtins import unicode_type
from ebook_converter.customize import FileTypePlugin
from ebook_converter.constants import numeric_version
from ebook_converter.polyglot.builtins import unicode_type
class HTML2ZIP(FileTypePlugin):
@@ -28,11 +28,11 @@ every time you add an HTML file to the library.\
def run(self, htmlfile):
import codecs
from calibre import prints
from calibre.ptempfile import TemporaryDirectory
from calibre.gui2.convert.gui_conversion import gui_convert
from calibre.customize.conversion import OptionRecommendation
from calibre.ebooks.epub import initialize_container
from ebook_converter import prints
from ebook_converter.ptempfile import TemporaryDirectory
from ebook_converter.gui2.convert.gui_conversion import gui_convert
from ebook_converter.customize.conversion import OptionRecommendation
from ebook_converter.ebooks.epub import initialize_container
with TemporaryDirectory('_plugin_html2zip') as tdir:
recs =[('debug_pipeline', tdir, OptionRecommendation.HIGH)]
@@ -86,7 +86,7 @@ every time you add an HTML file to the library.\
button_box.accepted.connect(config_dialog.accept)
button_box.rejected.connect(config_dialog.reject)
config_dialog.setWindowTitle(_('Customize') + ' ' + self.name)
from calibre.customize.ui import (plugin_customization,
from ebook_converter.customize.ui import (plugin_customization,
customize_plugin)
help_text = self.customization_help(gui=True)
help_text = QLabel(help_text, config_dialog)
+5 -5
View File
@@ -7,11 +7,11 @@ This package contains logic to read and write LRF files.
The LRF file format is documented at U{http://www.sven.de/librie/Librie/LrfFormat}.
"""
from calibre.ebooks.lrf.pylrs.pylrs import Book as _Book
from calibre.ebooks.lrf.pylrs.pylrs import TextBlock, Header, \
from ebook_converter.ebooks.lrf.pylrs.pylrs import Book as _Book
from ebook_converter.ebooks.lrf.pylrs.pylrs import TextBlock, Header, \
TextStyle, BlockStyle
from calibre.ebooks.lrf.fonts import FONT_FILE_MAP
from calibre.ebooks import ConversionError
from ebook_converter.ebooks.lrf.fonts import FONT_FILE_MAP
from ebook_converter.ebooks import ConversionError
__docformat__ = "epytext"
@@ -38,7 +38,7 @@ class PRS500_PROFILE(object):
def find_custom_fonts(options, logger):
from calibre.utils.fonts.scanner import font_scanner
from ebook_converter.utils.fonts.scanner import font_scanner
fonts = {'serif' : None, 'sans' : None, 'mono' : None}
def family(cmd):
@@ -1,10 +0,0 @@
from __future__ import absolute_import, division, print_function, unicode_literals
__license__ = 'GPL v3'
__copyright__ = '2008, Kovid Goyal <kovid at kovidgoyal.net>'
"""
This package contains code to convert HTML ebooks to LRF ebooks.
"""
__docformat__ = "epytext"
__author__ = "Kovid Goyal <kovid@kovidgoyal.net>"
+14 -14
View File
@@ -13,27 +13,27 @@ from functools import partial
from itertools import chain
from math import ceil, floor
from calibre import (
from ebook_converter import (
__appname__, entity_to_unicode, fit_image, force_unicode, preferred_encoding
)
from calibre.constants import filesystem_encoding
from calibre.devices.interface import DevicePlugin as Device
from calibre.ebooks import ConversionError
from calibre.ebooks.BeautifulSoup import (
from ebook_converter.constants import filesystem_encoding
from ebook_converter.devices.interface import DevicePlugin as Device
from ebook_converter.ebooks import ConversionError
from ebook_converter.ebooks.BeautifulSoup import (
BeautifulSoup, Comment, Declaration, NavigableString, ProcessingInstruction, Tag
)
from calibre.ebooks.chardet import xml_to_unicode
from calibre.ebooks.lrf import Book
from calibre.ebooks.lrf.html.color_map import lrs_color
from calibre.ebooks.lrf.html.table import Table
from calibre.ebooks.lrf.pylrs.pylrs import (
from ebook_converter.ebooks.chardet import xml_to_unicode
from ebook_converter.ebooks.lrf import Book
from ebook_converter.ebooks.lrf.html.color_map import lrs_color
from ebook_converter.ebooks.lrf.html.table import Table
from ebook_converter.ebooks.lrf.pylrs.pylrs import (
CR, BlockSpace, BookSetting, Canvas, CharButton, DropCaps, EmpLine, Image,
ImageBlock, ImageStream, Italic, JumpButton, LrsError, Paragraph, Plot,
RuledLine, Span, Sub, Sup, TextBlock
)
from calibre.ptempfile import PersistentTemporaryFile
from polyglot.builtins import getcwd, itervalues, string_or_bytes, unicode_type
from polyglot.urllib import unquote, urlparse
from ebook_converter.ptempfile import PersistentTemporaryFile
from ebook_converter.polyglot.builtins import getcwd, itervalues, string_or_bytes, unicode_type
from ebook_converter.polyglot.urllib import unquote, urlparse
"""
Code to convert HTML ebooks into LRF ebooks.
@@ -1911,7 +1911,7 @@ def try_opf(path, options, logger):
return
dirpath = os.path.dirname(os.path.abspath(opf))
from calibre.ebooks.metadata.opf2 import OPF as OPF2
from ebook_converter.ebooks.metadata.opf2 import OPF as OPF2
with open(opf, 'rb') as f:
opf = OPF2(f, dirpath)
try:
+4 -4
View File
@@ -4,11 +4,11 @@ __license__ = 'GPL v3'
__copyright__ = '2008, Kovid Goyal <kovid at kovidgoyal.net>'
import math, sys, re, numbers
from calibre.ebooks.lrf.fonts import get_font
from calibre.ebooks.lrf.pylrs.pylrs import TextBlock, Text, CR, Span, \
from ebook_converter.ebooks.lrf.fonts import get_font
from ebook_converter.ebooks.lrf.pylrs.pylrs import TextBlock, Text, CR, Span, \
CharButton, Plot, Paragraph, \
LrsTextTag
from polyglot.builtins import string_or_bytes, range, native_string_type
from ebook_converter.polyglot.builtins import string_or_bytes, range, native_string_type
def ceil(num):
@@ -16,7 +16,7 @@ def ceil(num):
def print_xml(elem):
from calibre.ebooks.lrf.pylrs.pylrs import ElementWriter
from ebook_converter.ebooks.lrf.pylrs.pylrs import ElementWriter
elem = elem.toElement(native_string_type('utf8'))
ew = ElementWriter(elem, sourceEncoding=native_string_type('utf8'))
ew.write(sys.stdout)
+1 -1
View File
@@ -2,7 +2,7 @@ from __future__ import absolute_import, division, print_function, unicode_litera
""" elements.py -- replacements and helpers for ElementTree """
from polyglot.builtins import unicode_type, string_or_bytes
from ebook_converter.polyglot.builtins import unicode_type, string_or_bytes
class ElementWriter(object):
+1 -1
View File
@@ -12,7 +12,7 @@ import codecs
import os
from .pylrfopt import tagListOptimizer
from polyglot.builtins import iteritems, string_or_bytes, unicode_type
from ebook_converter.polyglot.builtins import iteritems, string_or_bytes, unicode_type
PYLRF_VERSION = "1.0"
+4 -4
View File
@@ -47,14 +47,14 @@ from .pylrf import (LrfWriter, LrfObject, LrfTag, LrfToc,
STREAM_COMPRESSED, LrfTagStream, LrfStreamBase, IMAGE_TYPE_ENCODING,
BINDING_DIRECTION_ENCODING, LINE_TYPE_ENCODING, LrfFileStream,
STREAM_FORCE_COMPRESSED)
from calibre.utils.date import isoformat
from ebook_converter.utils.date import isoformat
DEFAULT_SOURCE_ENCODING = "cp1252" # default is us-windows character set
DEFAULT_GENREADING = "fs" # default is yes to both lrf and lrs
from calibre import __appname__, __version__
from calibre import entity_to_unicode
from polyglot.builtins import string_or_bytes, unicode_type, iteritems, native_string_type
from ebook_converter import __appname__, __version__
from ebook_converter import entity_to_unicode
from ebook_converter.polyglot.builtins import string_or_bytes, unicode_type, iteritems, native_string_type
class LrsError(Exception):
+6 -6
View File
@@ -11,10 +11,10 @@ Provides abstraction for metadata reading.writing from a variety of ebook format
"""
import os, sys, re
from calibre import relpath, guess_type, prints, force_unicode
from calibre.utils.config_base import tweaks
from polyglot.builtins import codepoint_to_chr, unicode_type, range, map, zip, getcwd, iteritems, itervalues, as_unicode
from polyglot.urllib import quote, unquote, urlparse
from ebook_converter import relpath, guess_type, prints, force_unicode
from ebook_converter.utils.config_base import tweaks
from ebook_converter.polyglot.builtins import codepoint_to_chr, unicode_type, range, map, zip, getcwd, iteritems, itervalues, as_unicode
from ebook_converter.polyglot.urllib import quote, unquote, urlparse
try:
@@ -131,7 +131,7 @@ def get_title_sort_pat(lang=None):
if ans is not None:
return ans
q = lang
from calibre.utils.localization import canonicalize_lang, get_lang
from ebook_converter.utils.localization import canonicalize_lang, get_lang
if lang is None:
q = tweaks['default_language_for_title_sort']
if q is None:
@@ -348,7 +348,7 @@ def MetaInformation(title, authors=(_('Unknown'),)):
@param title: title or ``_('Unknown')`` or a MetaInformation object
@param authors: List of strings or []
'''
from calibre.ebooks.metadata.book.base import Metadata
from ebook_converter.ebooks.metadata.book.base import Metadata
mi = None
if hasattr(title, 'title') and hasattr(title, 'authors'):
mi = title
+11 -11
View File
@@ -9,9 +9,9 @@ __docformat__ = 'restructuredtext en'
import os
from contextlib import closing
from calibre.customize import FileTypePlugin
from calibre.utils.localization import canonicalize_lang
from polyglot.builtins import filter, unicode_type
from ebook_converter.customize import FileTypePlugin
from ebook_converter.utils.localization import canonicalize_lang
from ebook_converter.polyglot.builtins import filter, unicode_type
def is_comic(list_of_names):
@@ -22,7 +22,7 @@ def is_comic(list_of_names):
def archive_type(stream):
from calibre.utils.zipfile import stringFileHeader
from ebook_converter.utils.zipfile import stringFileHeader
try:
pos = stream.tell()
except:
@@ -51,7 +51,7 @@ class KPFExtract(FileTypePlugin):
on_import = True
def run(self, archive):
from calibre.utils.zipfile import ZipFile
from ebook_converter.utils.zipfile import ZipFile
with ZipFile(archive, 'r') as zf:
fnames = zf.namelist()
candidates = [x for x in fnames if x.lower().endswith('.docx')]
@@ -74,10 +74,10 @@ class ArchiveExtract(FileTypePlugin):
on_import = True
def run(self, archive):
from calibre.utils.zipfile import ZipFile
from ebook_converter.utils.zipfile import ZipFile
is_rar = archive.lower().endswith('.rar')
if is_rar:
from calibre.utils.unrar import extract_member, names
from ebook_converter.utils.unrar import extract_member, names
else:
zf = ZipFile(archive, 'r')
@@ -166,7 +166,7 @@ def get_comic_book_info(d, mi, series_index='volume'):
mi.comments = comments.strip()
pubm, puby = d.get('publicationMonth', None), d.get('publicationYear', None)
if puby is not None:
from calibre.utils.date import parse_only_date
from ebook_converter.utils.date import parse_only_date
from datetime import date
try:
dt = date(puby, 6 if pubm is None else pubm, 15)
@@ -178,7 +178,7 @@ def get_comic_book_info(d, mi, series_index='volume'):
def parse_comic_comment(comment, series_index='volume'):
# See http://code.google.com/p/comicbookinfo/wiki/Example
from calibre.ebooks.metadata import MetaInformation
from ebook_converter.ebooks.metadata import MetaInformation
import json
mi = MetaInformation(None, None)
m = json.loads(comment)
@@ -193,11 +193,11 @@ def parse_comic_comment(comment, series_index='volume'):
def get_comic_metadata(stream, stream_type, series_index='volume'):
comment = None
if stream_type == 'cbz':
from calibre.utils.zipfile import ZipFile
from ebook_converter.utils.zipfile import ZipFile
zf = ZipFile(stream)
comment = zf.comment
elif stream_type == 'cbr':
from calibre.utils.unrar import comment as get_comment
from ebook_converter.utils.unrar import comment as get_comment
comment = get_comment(stream)
return parse_comic_comment(comment or b'{}', series_index=series_index)
+24 -23
View File
@@ -8,14 +8,14 @@ __docformat__ = 'restructuredtext en'
import copy, traceback
from calibre import prints
from calibre.constants import DEBUG, ispy3
from calibre.ebooks.metadata.book import (SC_COPYABLE_FIELDS,
from ebook_converter import prints
from ebook_converter.constants import DEBUG, ispy3
from ebook_converter.ebooks.metadata.book import (SC_COPYABLE_FIELDS,
SC_FIELDS_COPY_NOT_NULL, STANDARD_METADATA_FIELDS,
TOP_LEVEL_IDENTIFIERS, ALL_METADATA_FIELDS)
from calibre.library.field_metadata import FieldMetadata
from calibre.utils.icu import sort_key
from polyglot.builtins import iteritems, unicode_type, filter, map
from ebook_converter.library.field_metadata import FieldMetadata
from ebook_converter.utils.icu import sort_key
from ebook_converter.polyglot.builtins import iteritems, unicode_type, filter, map
# Special sets used to optimize the performance of getting and setting
# attributes on Metadata objects
@@ -52,7 +52,7 @@ def reset_field_metadata():
field_metadata = FieldMetadata()
ck = lambda typ: icu_lower(typ).strip().replace(':', '').replace(',', '')
ck = lambda typ: typ.lower().strip().replace(':', '').replace(',', '')
cv = lambda val: val.strip().replace(',', '|')
@@ -97,7 +97,7 @@ class Metadata(object):
# List of strings or []
self.author = list(authors) if authors else [] # Needed for backward compatibility
self.authors = list(authors) if authors else []
from calibre.ebooks.metadata.book.formatter import SafeFormat
from ebook_converter.ebooks.metadata.book.formatter import SafeFormat
self.formatter = SafeFormat() if formatter is None else formatter
self.template_cache = template_cache
@@ -441,7 +441,7 @@ class Metadata(object):
'''
if not ops:
return
from calibre.ebooks.metadata.book.formatter import SafeFormat
from ebook_converter.ebooks.metadata.book.formatter import SafeFormat
formatter = SafeFormat()
for op in ops:
try:
@@ -584,14 +584,15 @@ class Metadata(object):
for attr in TOP_LEVEL_IDENTIFIERS:
copy_not_none(self, other, attr)
other_lang = getattr(other, 'languages', [])
if other_lang and other_lang != ['und']:
self.languages = list(other_lang)
# other_lang = getattr(other, 'languages', [])
# if other_lang and other_lang != ['und']:
# self.languages = list(other_lang)
self.languages = []
if not getattr(self, 'series', None):
self.series_index = None
def format_series_index(self, val=None):
from calibre.ebooks.metadata import fmt_sidx
from ebook_converter.ebooks.metadata import fmt_sidx
v = self.series_index if val is None else val
try:
x = float(v)
@@ -600,11 +601,11 @@ class Metadata(object):
return fmt_sidx(x)
def authors_from_string(self, raw):
from calibre.ebooks.metadata import string_to_authors
from ebook_converter.ebooks.metadata import string_to_authors
self.authors = string_to_authors(raw)
def format_authors(self):
from calibre.ebooks.metadata import authors_to_string
from ebook_converter.ebooks.metadata import authors_to_string
return authors_to_string(self.authors)
def format_tags(self):
@@ -625,12 +626,12 @@ class Metadata(object):
return (name, val)
def format_field_extended(self, key, series_with_index=True):
from calibre.ebooks.metadata import authors_to_string
from ebook_converter.ebooks.metadata import authors_to_string
'''
returns the tuple (display_name, formatted_value, original_value,
field_metadata)
'''
from calibre.utils.date import format_date
from ebook_converter.utils.date import format_date
# Handle custom series index
if key.startswith('#') and key.endswith('_index'):
@@ -715,8 +716,8 @@ class Metadata(object):
A string representation of this object, suitable for printing to
console
'''
from calibre.utils.date import isoformat
from calibre.ebooks.metadata import authors_to_string
from ebook_converter.utils.date import isoformat
from ebook_converter.ebooks.metadata import authors_to_string
ans = []
def fmt(x, y):
@@ -765,8 +766,8 @@ class Metadata(object):
'''
A HTML representation of this object.
'''
from calibre.ebooks.metadata import authors_to_string
from calibre.utils.date import isoformat
from ebook_converter.ebooks.metadata import authors_to_string
from ebook_converter.utils.date import isoformat
ans = [(_('Title'), unicode_type(self.title))]
ans += [(_('Author(s)'), (authors_to_string(self.authors) if self.authors else _('Unknown')))]
ans += [(_('Publisher'), unicode_type(self.publisher))]
@@ -817,7 +818,7 @@ def field_from_string(field, raw, field_metadata):
elif dt == 'rating':
val = float(raw) * 2
elif dt == 'datetime':
from calibre.utils.date import parse_only_date
from ebook_converter.utils.date import parse_only_date
val = parse_only_date(raw)
elif dt == 'bool':
if raw.lower() in {'true', 'yes', 'y'}:
@@ -833,7 +834,7 @@ def field_from_string(field, raw, field_metadata):
if field == 'identifiers':
val = {x.partition(':')[0]:x.partition(':')[-1] for x in val}
elif field == 'languages':
from calibre.utils.localization import canonicalize_lang
from ebook_converter.utils.localization import canonicalize_lang
val = [canonicalize_lang(x) for x in val]
val = [x for x in val if x]
if val is object:
@@ -5,9 +5,9 @@ from __future__ import absolute_import, division, print_function, unicode_litera
__license__ = 'GPL v3'
__copyright__ = '2013, Kovid Goyal <kovid at kovidgoyal.net>'
from calibre.ebooks.metadata.book import TOP_LEVEL_IDENTIFIERS, ALL_METADATA_FIELDS
from ebook_converter.ebooks.metadata.book import TOP_LEVEL_IDENTIFIERS, ALL_METADATA_FIELDS
from calibre.utils.formatter import TemplateFormatter
from ebook_converter.utils.formatter import TemplateFormatter
class SafeFormat(TemplateFormatter):
@@ -21,7 +21,7 @@ class SafeFormat(TemplateFormatter):
key = orig_key = orig_key.lower()
if (key != 'title_sort' and key not in TOP_LEVEL_IDENTIFIERS and
key not in ALL_METADATA_FIELDS):
from calibre.ebooks.metadata.book.base import field_metadata
from ebook_converter.ebooks.metadata.book.base import field_metadata
key = field_metadata.search_term_to_field_key(key)
if key is None or (self.book and
key not in self.book.all_field_keys()):
@@ -9,19 +9,19 @@ Created on 4 Jun 2010
import json, traceback
from datetime import datetime, time
from calibre.ebooks.metadata.book import SERIALIZABLE_FIELDS
from calibre.constants import filesystem_encoding, preferred_encoding
from calibre.library.field_metadata import FieldMetadata
from calibre import isbytestring
from polyglot.builtins import iteritems, itervalues, as_bytes
from polyglot.binary import as_base64_unicode, from_base64_bytes
from ebook_converter.ebooks.metadata.book import SERIALIZABLE_FIELDS
from ebook_converter.constants import filesystem_encoding, preferred_encoding
from ebook_converter.library.field_metadata import FieldMetadata
from ebook_converter import isbytestring
from ebook_converter.polyglot.builtins import iteritems, itervalues, as_bytes
from ebook_converter.polyglot.binary import as_base64_unicode, from_base64_bytes
# Translate datetimes to and from strings. The string form is the datetime in
# UTC. The returned date is also UTC
def string_to_datetime(src):
from calibre.utils.iso8601 import parse_iso8601
from ebook_converter.utils.iso8601 import parse_iso8601
if src != "None":
try:
return parse_iso8601(src)
@@ -31,7 +31,7 @@ def string_to_datetime(src):
def datetime_to_string(dateval):
from calibre.utils.date import isoformat, UNDEFINED_DATE, local_tz
from ebook_converter.utils.date import isoformat, UNDEFINED_DATE, local_tz
if dateval is None:
return "None"
if not isinstance(dateval, datetime):
@@ -47,7 +47,7 @@ def encode_thumbnail(thumbnail):
'''
Encode the image part of a thumbnail, then return the 3 part tuple
'''
from calibre.utils.imghdr import identify
from ebook_converter.utils.imghdr import identify
if thumbnail is None:
return None
if not isinstance(thumbnail, (tuple, list)):
+6 -6
View File
@@ -15,12 +15,12 @@ from collections import defaultdict
from html5_parser import parse
from lxml.etree import Comment
from calibre.ebooks.metadata import string_to_authors, authors_to_string
from calibre.ebooks.metadata.book.base import Metadata
from calibre.ebooks.chardet import xml_to_unicode
from calibre import replace_entities, isbytestring
from calibre.utils.date import parse_date, is_date_undefined
from polyglot.builtins import iteritems
from ebook_converter.ebooks.metadata import string_to_authors, authors_to_string
from ebook_converter.ebooks.metadata.book.base import Metadata
from ebook_converter.ebooks.chardet import xml_to_unicode
from ebook_converter import replace_entities, isbytestring
from ebook_converter.utils.date import parse_date, is_date_undefined
from ebook_converter.polyglot.builtins import iteritems
def get_metadata(stream):
+9 -9
View File
@@ -5,13 +5,13 @@ __copyright__ = '2008, Kovid Goyal <kovid at kovidgoyal.net>'
import os, re, collections
from calibre.utils.config import prefs
from calibre.constants import filesystem_encoding
from calibre.ebooks.metadata.opf2 import OPF
from calibre import isbytestring
from calibre.customize.ui import get_file_type_metadata, set_file_type_metadata
from calibre.ebooks.metadata import MetaInformation, string_to_authors
from polyglot.builtins import getcwd, unicode_type
from ebook_converter.utils.config import prefs
from ebook_converter.constants import filesystem_encoding
from ebook_converter.ebooks.metadata.opf2 import OPF
from ebook_converter import isbytestring
from ebook_converter.customize.ui import get_file_type_metadata, set_file_type_metadata
from ebook_converter.ebooks.metadata import MetaInformation, string_to_authors
from ebook_converter.polyglot.builtins import getcwd, unicode_type
# The priorities for loading metadata from different file types
# Higher values should be used to update metadata from lower values
@@ -184,7 +184,7 @@ def metadata_from_filename(name, pat=None, fallback_pat=None):
try:
pubdate = match.group('published')
if pubdate:
from calibre.utils.date import parse_only_date
from ebook_converter.utils.date import parse_only_date
mi.pubdate = parse_only_date(pubdate)
except:
pass
@@ -224,7 +224,7 @@ def opf_metadata(opfpath):
def forked_read_metadata(path, tdir):
from calibre.ebooks.metadata.opf2 import metadata_to_opf
from ebook_converter.ebooks.metadata.opf2 import metadata_to_opf
with lopen(path, 'rb') as f:
fmt = os.path.splitext(path)[1][1:].lower()
f.seek(0, 2)

Some files were not shown because too many files have changed in this diff Show More