mirror of
https://github.com/gryf/ebook-converter.git
synced 2026-03-17 15:23:43 +01: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:
@@ -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):
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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)
|
||||
|
||||
|
||||
@@ -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):
|
||||
|
||||
@@ -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')
|
||||
|
||||
|
||||
@@ -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):
|
||||
|
||||
@@ -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:
|
||||
|
||||
@@ -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):
|
||||
|
||||
@@ -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 = {
|
||||
|
||||
@@ -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',
|
||||
|
||||
@@ -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):
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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):
|
||||
|
||||
@@ -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):
|
||||
|
||||
Reference in New Issue
Block a user