1
0
mirror of https://github.com/gryf/ebook-converter.git synced 2026-03-11 03:55:45 +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:
2020-04-11 19:33:43 +02:00
parent 69d2e536c5
commit 0f9792df36
252 changed files with 1925 additions and 2344 deletions

View File

@@ -7,12 +7,12 @@ __copyright__ = '2008, Kovid Goyal <kovid at kovidgoyal.net>'
import os
from polyglot.builtins import range
from ebook_converter.polyglot.builtins import range
def db(path=None, read_only=False):
from calibre.db.legacy import LibraryDatabase
from calibre.utils.config import prefs
from ebook_converter.db.legacy import LibraryDatabase
from ebook_converter.utils.config import prefs
return LibraryDatabase(os.path.expanduser(path) if path else prefs['library_path'],
read_only=read_only)
@@ -28,7 +28,7 @@ def generate_test_db(library_path, # {{{
max_tags=10
):
import random, string, os, sys, time
from calibre.constants import preferred_encoding
from ebook_converter.constants import preferred_encoding
if not os.path.exists(library_path):
os.makedirs(library_path)
@@ -59,7 +59,7 @@ def generate_test_db(library_path, # {{{
authors = [random.choice(all_authors) for i in range(authors)]
tags = random.randint(0, max_tags)
tags = [random.choice(all_tags) for i in range(tags)]
from calibre.ebooks.metadata.book.base import Metadata
from ebook_converter.ebooks.metadata.book.base import Metadata
mi = Metadata(title, authors)
mi.tags = tags
testdb.import_book(mi, [])
@@ -71,7 +71,7 @@ def generate_test_db(library_path, # {{{
def current_library_path():
from calibre.utils.config import prefs
from ebook_converter.utils.config import prefs
path = prefs['library_path']
if path:
path = path.replace('\\', '/')

View File

@@ -9,12 +9,12 @@ __docformat__ = 'restructuredtext en'
import re, codecs, os, numbers
from collections import namedtuple
from calibre import strftime
from calibre.customize import CatalogPlugin
from calibre.library.catalogs import FIELDS, TEMPLATE_ALLOWED_FIELDS
from calibre.customize.conversion import DummyReporter
from calibre.ebooks.metadata import format_isbn
from polyglot.builtins import filter, string_or_bytes, unicode_type
from ebook_converter import strftime
from ebook_converter.customize import CatalogPlugin
from ebook_converter.library.catalogs import FIELDS, TEMPLATE_ALLOWED_FIELDS
from ebook_converter.customize.conversion import DummyReporter
from ebook_converter.ebooks.metadata import format_isbn
from ebook_converter.polyglot.builtins import filter, string_or_bytes, unicode_type
class BIBTEX(CatalogPlugin):
@@ -108,12 +108,12 @@ class BIBTEX(CatalogPlugin):
"Applies to: BIBTEX output format"))]
def run(self, path_to_output, opts, db, notification=DummyReporter()):
from calibre.utils.date import isoformat
from calibre.utils.html2text import html2text
from calibre.utils.bibtex import BibTeX
from calibre.library.save_to_disk import preprocess_template
from calibre.utils.logging import default_log as log
from calibre.utils.filenames import ascii_text
from ebook_converter.utils.date import isoformat
from ebook_converter.utils.html2text import html2text
from ebook_converter.utils.bibtex import BibTeX
from ebook_converter.library.save_to_disk import preprocess_template
from ebook_converter.utils.logging import default_log as log
from ebook_converter.utils.filenames import ascii_text
library_name = os.path.basename(db.library_path)

View File

@@ -9,10 +9,10 @@ __docformat__ = 'restructuredtext en'
import re, codecs, os
from collections import namedtuple
from calibre.customize import CatalogPlugin
from calibre.library.catalogs import FIELDS
from calibre.customize.conversion import DummyReporter
from polyglot.builtins import unicode_type
from ebook_converter.customize import CatalogPlugin
from ebook_converter.library.catalogs import FIELDS
from ebook_converter.customize.conversion import DummyReporter
from ebook_converter.polyglot.builtins import unicode_type
class CSV_XML(CatalogPlugin):
@@ -52,12 +52,12 @@ class CSV_XML(CatalogPlugin):
"Applies to: CSV, XML output formats"))]
def run(self, path_to_output, opts, db, notification=DummyReporter()):
from calibre.library import current_library_name
from calibre.utils.date import isoformat
from calibre.utils.html2text import html2text
from calibre.utils.logging import default_log as log
from ebook_converter.library import current_library_name
from ebook_converter.utils.date import isoformat
from ebook_converter.utils.html2text import html2text
from ebook_converter.utils.logging import default_log as log
from lxml import etree
from calibre.ebooks.metadata import authors_to_string
from ebook_converter.ebooks.metadata import authors_to_string
self.fmt = path_to_output.rpartition('.')[2]
self.notification = notification

View File

@@ -9,14 +9,14 @@ __docformat__ = 'restructuredtext en'
import datetime, os, time
from collections import namedtuple
from calibre import strftime
from calibre.customize import CatalogPlugin
from calibre.customize.conversion import OptionRecommendation, DummyReporter
from calibre.library import current_library_name
from calibre.library.catalogs import AuthorSortMismatchException, EmptyCatalogException
from calibre.ptempfile import PersistentTemporaryFile
from calibre.utils.localization import calibre_langcode_to_name, canonicalize_lang, get_lang
from polyglot.builtins import unicode_type
from ebook_converter import strftime
from ebook_converter.customize import CatalogPlugin
from ebook_converter.customize.conversion import OptionRecommendation, DummyReporter
from ebook_converter.library import current_library_name
from ebook_converter.library.catalogs import AuthorSortMismatchException, EmptyCatalogException
from ebook_converter.ptempfile import PersistentTemporaryFile
from ebook_converter.utils.localization import calibre_langcode_to_name, canonicalize_lang, get_lang
from ebook_converter.polyglot.builtins import unicode_type
Option = namedtuple('Option', 'option, default, dest, action, help')
@@ -191,9 +191,9 @@ class EPUB_MOBI(CatalogPlugin):
# }}}
def run(self, path_to_output, opts, db, notification=DummyReporter()):
from calibre.library.catalogs.epub_mobi_builder import CatalogBuilder
from calibre.utils.logging import default_log as log
from calibre.utils.config import JSONConfig
from ebook_converter.library.catalogs.epub_mobi_builder import CatalogBuilder
from ebook_converter.utils.logging import default_log as log
from ebook_converter.utils.config import JSONConfig
# If preset specified from the cli, insert stored options from JSON file
if hasattr(opts, 'preset') and opts.preset:
@@ -465,7 +465,7 @@ class EPUB_MOBI(CatalogPlugin):
recommendations.append(('cover', cpath, OptionRecommendation.HIGH))
log.info("using existing catalog cover")
else:
from calibre.ebooks.covers import calibre_cover2
from ebook_converter.ebooks.covers import calibre_cover2
log.info("replacing catalog cover")
new_cover_path = PersistentTemporaryFile(suffix='.jpg')
new_cover = calibre_cover2(opts.catalog_title, 'calibre')
@@ -474,7 +474,7 @@ class EPUB_MOBI(CatalogPlugin):
recommendations.append(('cover', new_cover_path.name, OptionRecommendation.HIGH))
# Run ebook-convert
from calibre.ebooks.conversion.plumber import Plumber
from ebook_converter.ebooks.conversion.plumber import Plumber
plumber = Plumber(os.path.join(catalog.catalog_path, opts.basename + '.opf'),
path_to_output, log, report_progress=notification,
abort_after_input_dump=False)
@@ -487,9 +487,9 @@ class EPUB_MOBI(CatalogPlugin):
pass
if GENERATE_DEBUG_EPUB:
from calibre.ebooks.epub import initialize_container
from calibre.ebooks.tweak import zip_rebuilder
from calibre.utils.zipfile import ZipFile
from ebook_converter.ebooks.epub import initialize_container
from ebook_converter.ebooks.tweak import zip_rebuilder
from ebook_converter.utils.zipfile import ZipFile
input_path = os.path.join(catalog_debug_path, 'input')
epub_shell = os.path.join(catalog_debug_path, 'epub_shell.zip')
initialize_container(epub_shell, opf_name='content.opf')

View File

@@ -6,14 +6,14 @@ from __future__ import absolute_import, division, print_function, unicode_litera
import re
from calibre import prepare_string_for_xml
from calibre.constants import preferred_encoding
from calibre.ebooks.BeautifulSoup import (
from ebook_converter import prepare_string_for_xml
from ebook_converter.constants import preferred_encoding
from ebook_converter.ebooks.BeautifulSoup import (
BeautifulSoup, CData, Comment, Declaration, NavigableString,
ProcessingInstruction
)
from calibre.utils.html2text import html2text
from polyglot.builtins import unicode_type
from ebook_converter.utils.html2text import html2text
from ebook_converter.polyglot.builtins import unicode_type
# Hackish - ignoring sentences ending or beginning in numbers to avoid
# confusion with decimal points.
@@ -135,7 +135,7 @@ def markdown(val):
try:
md = markdown.Markdown
except AttributeError:
from calibre.ebooks.markdown import Markdown
from ebook_converter.ebooks.markdown import Markdown
md = markdown.Markdown = Markdown()
return md.convert(val)
@@ -145,7 +145,7 @@ def merge_comments(one, two):
def sanitize_comments_html(html):
from calibre.ebooks.markdown import Markdown
from ebook_converter.ebooks.markdown import Markdown
text = html2text(html)
md = Markdown()
html = md.convert(text)

View File

@@ -9,8 +9,8 @@ Created on 25 May 2010
import traceback
from collections import OrderedDict
from calibre.utils.config_base import tweaks
from polyglot.builtins import iteritems, itervalues
from ebook_converter.utils.config_base import tweaks
from ebook_converter.polyglot.builtins import iteritems, itervalues
category_icon_map = {
'authors' : 'user_profile.png',