mirror of
https://github.com/gryf/ebook-converter.git
synced 2026-02-22 01:45:58 +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:
@@ -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,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.')
|
||||
|
||||
@@ -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),
|
||||
|
||||
@@ -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:
|
||||
|
||||
@@ -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:
|
||||
|
||||
Reference in New Issue
Block a user