mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Remove use of global P()
This commit is contained in:
parent
fb262b7b57
commit
0cf25eb724
@ -22,6 +22,7 @@ from calibre.startup import initialize_calibre
|
|||||||
initialize_calibre()
|
initialize_calibre()
|
||||||
from calibre.utils.icu import safe_chr
|
from calibre.utils.icu import safe_chr
|
||||||
from calibre.prints import prints
|
from calibre.prints import prints
|
||||||
|
from calibre.utils.resources import get_path as P
|
||||||
|
|
||||||
if False:
|
if False:
|
||||||
# Prevent pyflakes from complaining
|
# Prevent pyflakes from complaining
|
||||||
|
@ -20,7 +20,7 @@ from functools import partial
|
|||||||
|
|
||||||
from calibre import as_unicode, force_unicode, isbytestring, prints
|
from calibre import as_unicode, force_unicode, isbytestring, prints
|
||||||
from calibre.constants import (
|
from calibre.constants import (
|
||||||
filesystem_encoding, iswindows, plugins, preferred_encoding
|
filesystem_encoding, iswindows, plugins, preferred_encoding,
|
||||||
)
|
)
|
||||||
from calibre.db import SPOOL_SIZE, FTSQueryError
|
from calibre.db import SPOOL_SIZE, FTSQueryError
|
||||||
from calibre.db.annotations import annot_db_data, unicode_normalize
|
from calibre.db.annotations import annot_db_data, unicode_normalize
|
||||||
@ -29,7 +29,7 @@ from calibre.db.errors import NoSuchFormat
|
|||||||
from calibre.db.schema_upgrades import SchemaUpgrade
|
from calibre.db.schema_upgrades import SchemaUpgrade
|
||||||
from calibre.db.tables import (
|
from calibre.db.tables import (
|
||||||
AuthorsTable, CompositeTable, FormatsTable, IdentifiersTable, ManyToManyTable,
|
AuthorsTable, CompositeTable, FormatsTable, IdentifiersTable, ManyToManyTable,
|
||||||
ManyToOneTable, OneToOneTable, PathTable, RatingTable, SizeTable, UUIDTable
|
ManyToOneTable, OneToOneTable, PathTable, RatingTable, SizeTable, UUIDTable,
|
||||||
)
|
)
|
||||||
from calibre.ebooks.metadata import author_to_author_sort, title_sort
|
from calibre.ebooks.metadata import author_to_author_sort, title_sort
|
||||||
from calibre.library.field_metadata import FieldMetadata
|
from calibre.library.field_metadata import FieldMetadata
|
||||||
@ -40,15 +40,16 @@ from calibre.utils.date import EPOCH, parse_date, utcfromtimestamp, utcnow
|
|||||||
from calibre.utils.filenames import (
|
from calibre.utils.filenames import (
|
||||||
WindowsAtomicFolderMove, ascii_filename, atomic_rename, copyfile_using_links,
|
WindowsAtomicFolderMove, ascii_filename, atomic_rename, copyfile_using_links,
|
||||||
copytree_using_links, hardlink_file, is_case_sensitive, is_fat_filesystem,
|
copytree_using_links, hardlink_file, is_case_sensitive, is_fat_filesystem,
|
||||||
remove_dir_if_empty, samefile
|
remove_dir_if_empty, samefile,
|
||||||
)
|
)
|
||||||
from calibre.utils.formatter_functions import (
|
from calibre.utils.formatter_functions import (
|
||||||
compile_user_template_functions, formatter_functions,
|
compile_user_template_functions, formatter_functions, load_user_template_functions,
|
||||||
load_user_template_functions, unload_user_template_functions
|
unload_user_template_functions,
|
||||||
)
|
)
|
||||||
from calibre.utils.icu import sort_key
|
from calibre.utils.icu import sort_key
|
||||||
|
from calibre.utils.resources import get_path as P
|
||||||
from polyglot.builtins import (
|
from polyglot.builtins import (
|
||||||
cmp, iteritems, itervalues, native_string_type, reraise, string_or_bytes
|
cmp, iteritems, itervalues, native_string_type, reraise, string_or_bytes,
|
||||||
)
|
)
|
||||||
|
|
||||||
# }}}
|
# }}}
|
||||||
|
@ -2,6 +2,8 @@
|
|||||||
# vim:fileencoding=utf-8
|
# vim:fileencoding=utf-8
|
||||||
# License: GPL v3 Copyright: 2022, Kovid Goyal <kovid at kovidgoyal.net>
|
# License: GPL v3 Copyright: 2022, Kovid Goyal <kovid at kovidgoyal.net>
|
||||||
|
|
||||||
|
from calibre.utils.resources import get_path as P
|
||||||
|
|
||||||
|
|
||||||
class SchemaUpgrade:
|
class SchemaUpgrade:
|
||||||
|
|
||||||
|
@ -3,10 +3,12 @@ __copyright__ = '2008, Anatoly Shipitsin <norguhtar at gmail.com>'
|
|||||||
"""
|
"""
|
||||||
Convert .fb2 files to .lrf
|
Convert .fb2 files to .lrf
|
||||||
"""
|
"""
|
||||||
import os, re
|
import os
|
||||||
|
import re
|
||||||
|
|
||||||
from calibre.customize.conversion import InputFormatPlugin, OptionRecommendation
|
|
||||||
from calibre import guess_type
|
from calibre import guess_type
|
||||||
|
from calibre.customize.conversion import InputFormatPlugin, OptionRecommendation
|
||||||
|
from calibre.utils.resources import get_path as P
|
||||||
from polyglot.builtins import iteritems
|
from polyglot.builtins import iteritems
|
||||||
|
|
||||||
FB2NS = 'http://www.gribuser.ru/xml/fictionbook/2.0'
|
FB2NS = 'http://www.gribuser.ru/xml/fictionbook/2.0'
|
||||||
@ -37,12 +39,13 @@ class FB2Input(InputFormatPlugin):
|
|||||||
def convert(self, stream, options, file_ext, log,
|
def convert(self, stream, options, file_ext, log,
|
||||||
accelerators):
|
accelerators):
|
||||||
from lxml import etree
|
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 calibre.ebooks.chardet import xml_to_unicode
|
||||||
|
from calibre.ebooks.metadata.fb2 import ensure_namespace, get_fb2_data
|
||||||
|
from calibre.ebooks.metadata.meta import get_metadata
|
||||||
|
from calibre.ebooks.metadata.opf2 import OPFCreator
|
||||||
|
from calibre.ebooks.oeb.base import XHTML_NS, XLINK_NS
|
||||||
|
from calibre.utils.xml_parse import safe_xml_fromstring
|
||||||
self.log = log
|
self.log = log
|
||||||
log.debug('Parsing XML...')
|
log.debug('Parsing XML...')
|
||||||
raw = get_fb2_data(stream)[0]
|
raw = get_fb2_data(stream)[0]
|
||||||
@ -68,7 +71,8 @@ class FB2Input(InputFormatPlugin):
|
|||||||
css += etree.tostring(s, encoding='unicode', method='text',
|
css += etree.tostring(s, encoding='unicode', method='text',
|
||||||
with_tail=False) + '\n\n'
|
with_tail=False) + '\n\n'
|
||||||
if css:
|
if css:
|
||||||
import css_parser, logging
|
import css_parser
|
||||||
|
import logging
|
||||||
parser = css_parser.CSSParser(fetcher=None,
|
parser = css_parser.CSSParser(fetcher=None,
|
||||||
log=logging.getLogger('calibre.css'))
|
log=logging.getLogger('calibre.css'))
|
||||||
|
|
||||||
|
@ -2,12 +2,15 @@ __license__ = 'GPL 3'
|
|||||||
__copyright__ = '2010, Fabian Grassl <fg@jusmeum.de>'
|
__copyright__ = '2010, Fabian Grassl <fg@jusmeum.de>'
|
||||||
__docformat__ = 'restructuredtext en'
|
__docformat__ = 'restructuredtext en'
|
||||||
|
|
||||||
import os, re, shutil
|
import os
|
||||||
from os.path import dirname, abspath, relpath as _relpath, exists, basename
|
import re
|
||||||
|
import shutil
|
||||||
|
from os.path import abspath, basename, dirname, exists, relpath as _relpath
|
||||||
|
|
||||||
from calibre.customize.conversion import OutputFormatPlugin, OptionRecommendation
|
|
||||||
from calibre import CurrentDir
|
from calibre import CurrentDir
|
||||||
|
from calibre.customize.conversion import OptionRecommendation, OutputFormatPlugin
|
||||||
from calibre.ptempfile import PersistentTemporaryDirectory
|
from calibre.ptempfile import PersistentTemporaryDirectory
|
||||||
|
from calibre.utils.resources import get_path as P
|
||||||
|
|
||||||
|
|
||||||
def relpath(*args):
|
def relpath(*args):
|
||||||
@ -45,10 +48,10 @@ class HTMLOutput(OutputFormatPlugin):
|
|||||||
Generate table of contents
|
Generate table of contents
|
||||||
'''
|
'''
|
||||||
from lxml import etree
|
from lxml import etree
|
||||||
from polyglot.urllib import unquote
|
|
||||||
|
|
||||||
from calibre.ebooks.oeb.base import element
|
from calibre.ebooks.oeb.base import element
|
||||||
from calibre.utils.cleantext import clean_xml_chars
|
from calibre.utils.cleantext import clean_xml_chars
|
||||||
|
from polyglot.urllib import unquote
|
||||||
with CurrentDir(output_dir):
|
with CurrentDir(output_dir):
|
||||||
def build_node(current_node, parent=None):
|
def build_node(current_node, parent=None):
|
||||||
if parent is None:
|
if parent is None:
|
||||||
@ -82,10 +85,11 @@ class HTMLOutput(OutputFormatPlugin):
|
|||||||
|
|
||||||
def convert(self, oeb_book, output_path, input_plugin, opts, log):
|
def convert(self, oeb_book, output_path, input_plugin, opts, log):
|
||||||
from lxml import etree
|
from lxml import etree
|
||||||
from calibre.utils import zipfile
|
|
||||||
from templite import Templite
|
|
||||||
from polyglot.urllib import unquote
|
|
||||||
from calibre.ebooks.html.meta import EasyMeta
|
from calibre.ebooks.html.meta import EasyMeta
|
||||||
|
from calibre.utils import zipfile
|
||||||
|
from polyglot.urllib import unquote
|
||||||
|
from templite import Templite
|
||||||
|
|
||||||
# read template files
|
# read template files
|
||||||
if opts.template_html_index is not None:
|
if opts.template_html_index is not None:
|
||||||
@ -193,6 +197,7 @@ class HTMLOutput(OutputFormatPlugin):
|
|||||||
|
|
||||||
# render template
|
# render template
|
||||||
templite = Templite(template_html_data)
|
templite = Templite(template_html_data)
|
||||||
|
|
||||||
def toc():
|
def toc():
|
||||||
return self.generate_html_toc(oeb_book, path, output_dir)
|
return self.generate_html_toc(oeb_book, path, output_dir)
|
||||||
t = templite.render(ebookContent=ebook_content,
|
t = templite.render(ebookContent=ebook_content,
|
||||||
|
@ -7,6 +7,7 @@ __docformat__ = 'restructuredtext en'
|
|||||||
|
|
||||||
import os, sys
|
import os, sys
|
||||||
from calibre.customize.conversion import InputFormatPlugin
|
from calibre.customize.conversion import InputFormatPlugin
|
||||||
|
from calibre.utils.resources import get_path as P
|
||||||
|
|
||||||
|
|
||||||
class LRFInput(InputFormatPlugin):
|
class LRFInput(InputFormatPlugin):
|
||||||
|
@ -1,10 +1,14 @@
|
|||||||
__license__ = 'GPL v3'
|
__license__ = 'GPL v3'
|
||||||
__copyright__ = '2008, Kovid Goyal <kovid at kovidgoyal.net>'
|
__copyright__ = '2008, Kovid Goyal <kovid at kovidgoyal.net>'
|
||||||
|
|
||||||
import os, glob, re, textwrap
|
import glob
|
||||||
|
import os
|
||||||
|
import re
|
||||||
|
import textwrap
|
||||||
|
|
||||||
from calibre.customize.conversion import InputFormatPlugin, OptionRecommendation
|
from calibre.customize.conversion import InputFormatPlugin, OptionRecommendation
|
||||||
from polyglot.builtins import iteritems, as_bytes
|
from calibre.utils.resources import get_path as P
|
||||||
|
from polyglot.builtins import as_bytes, iteritems
|
||||||
|
|
||||||
border_style_map = {
|
border_style_map = {
|
||||||
'single' : 'solid',
|
'single' : 'solid',
|
||||||
@ -116,8 +120,9 @@ class RTFInput(InputFormatPlugin):
|
|||||||
return f.read()
|
return f.read()
|
||||||
|
|
||||||
def extract_images(self, picts):
|
def extract_images(self, picts):
|
||||||
from calibre.utils.imghdr import what
|
|
||||||
from binascii import unhexlify
|
from binascii import unhexlify
|
||||||
|
|
||||||
|
from calibre.utils.imghdr import what
|
||||||
self.log('Extracting images...')
|
self.log('Extracting images...')
|
||||||
|
|
||||||
with open(picts, 'rb') as f:
|
with open(picts, 'rb') as f:
|
||||||
@ -246,6 +251,7 @@ class RTFInput(InputFormatPlugin):
|
|||||||
def convert(self, stream, options, file_ext, log,
|
def convert(self, stream, options, file_ext, log,
|
||||||
accelerators):
|
accelerators):
|
||||||
from lxml import etree
|
from lxml import etree
|
||||||
|
|
||||||
from calibre.ebooks.metadata.meta import get_metadata
|
from calibre.ebooks.metadata.meta import get_metadata
|
||||||
from calibre.ebooks.metadata.opf2 import OPFCreator
|
from calibre.ebooks.metadata.opf2 import OPFCreator
|
||||||
from calibre.ebooks.rtf2xml.ParseRtf import RtfInvalidCodeException
|
from calibre.ebooks.rtf2xml.ParseRtf import RtfInvalidCodeException
|
||||||
|
@ -25,6 +25,7 @@ def get_font(name, size, encoding='unic'):
|
|||||||
@param encoding: Font encoding to use. E.g. 'unic', 'symbol', 'ADOB', 'ADBE', 'aprm'
|
@param encoding: Font encoding to use. E.g. 'unic', 'symbol', 'ADOB', 'ADBE', 'aprm'
|
||||||
@param manager: A dict that will store the PersistentTemporary
|
@param manager: A dict that will store the PersistentTemporary
|
||||||
'''
|
'''
|
||||||
|
from calibre.utils.resources import get_path as P
|
||||||
if name in LIBERATION_FONT_MAP:
|
if name in LIBERATION_FONT_MAP:
|
||||||
return ImageFont.truetype(P('fonts/liberation/%s.ttf' % LIBERATION_FONT_MAP[name]), size, encoding=encoding)
|
return ImageFont.truetype(P('fonts/liberation/%s.ttf' % LIBERATION_FONT_MAP[name]), size, encoding=encoding)
|
||||||
elif name in FONT_FILE_MAP:
|
elif name in FONT_FILE_MAP:
|
||||||
|
@ -5,9 +5,9 @@ __license__ = 'GPL v3'
|
|||||||
__copyright__ = '2009, Kovid Goyal <kovid@kovidgoyal.net>'
|
__copyright__ = '2009, Kovid Goyal <kovid@kovidgoyal.net>'
|
||||||
__docformat__ = 'restructuredtext en'
|
__docformat__ = 'restructuredtext en'
|
||||||
|
|
||||||
import textwrap, operator
|
import operator
|
||||||
from copy import deepcopy, copy
|
import textwrap
|
||||||
|
from copy import copy, deepcopy
|
||||||
from lxml import etree
|
from lxml import etree
|
||||||
|
|
||||||
from calibre import guess_type
|
from calibre import guess_type
|
||||||
|
@ -2,22 +2,22 @@
|
|||||||
# License: GPLv3 Copyright: 2016, Kovid Goyal <kovid at kovidgoyal.net>
|
# License: GPLv3 Copyright: 2016, Kovid Goyal <kovid at kovidgoyal.net>
|
||||||
|
|
||||||
|
|
||||||
|
import re
|
||||||
from collections import defaultdict, namedtuple
|
from collections import defaultdict, namedtuple
|
||||||
|
from css_parser.css import CSSRule, CSSStyleSheet, Property
|
||||||
from functools import partial
|
from functools import partial
|
||||||
from itertools import count
|
from itertools import count
|
||||||
from operator import itemgetter
|
from operator import itemgetter
|
||||||
import re
|
|
||||||
|
|
||||||
from css_parser.css import CSSStyleSheet, CSSRule, Property
|
|
||||||
|
|
||||||
from css_selectors import Select, INAPPROPRIATE_PSEUDO_CLASSES, SelectorError
|
|
||||||
from calibre import as_unicode
|
from calibre import as_unicode
|
||||||
from calibre.ebooks.css_transform_rules import all_properties
|
from calibre.ebooks.css_transform_rules import all_properties
|
||||||
from calibre.ebooks.oeb.base import OEB_STYLES, XHTML, css_text
|
from calibre.ebooks.oeb.base import OEB_STYLES, XHTML, css_text
|
||||||
from calibre.ebooks.oeb.normalize_css import normalizers, DEFAULTS
|
from calibre.ebooks.oeb.normalize_css import DEFAULTS, normalizers
|
||||||
from calibre.ebooks.oeb.stylizer import media_ok, INHERITED
|
from calibre.ebooks.oeb.stylizer import INHERITED, media_ok
|
||||||
from tinycss.fonts3 import serialize_font_family, parse_font_family
|
from calibre.utils.resources import get_path as P
|
||||||
|
from css_selectors import INAPPROPRIATE_PSEUDO_CLASSES, Select, SelectorError
|
||||||
from polyglot.builtins import iteritems, itervalues
|
from polyglot.builtins import iteritems, itervalues
|
||||||
|
from tinycss.fonts3 import parse_font_family, serialize_font_family
|
||||||
|
|
||||||
_html_css_stylesheet = None
|
_html_css_stylesheet = None
|
||||||
|
|
||||||
|
@ -7,15 +7,13 @@ import numbers
|
|||||||
import sys
|
import sys
|
||||||
from collections import namedtuple
|
from collections import namedtuple
|
||||||
from itertools import repeat
|
from itertools import repeat
|
||||||
|
|
||||||
from qt.core import QApplication, QEventLoop, pyqtSignal, sip
|
from qt.core import QApplication, QEventLoop, pyqtSignal, sip
|
||||||
from qt.webengine import (
|
from qt.webengine import QWebEnginePage, QWebEngineProfile, QWebEngineScript
|
||||||
QWebEnginePage, QWebEngineProfile, QWebEngineScript
|
|
||||||
)
|
|
||||||
|
|
||||||
from calibre import detect_ncpus as cpu_count, prints
|
from calibre import detect_ncpus as cpu_count, prints
|
||||||
from calibre.ebooks.oeb.polish.check.base import ERROR, WARN, BaseError
|
from calibre.ebooks.oeb.polish.check.base import ERROR, WARN, BaseError
|
||||||
from calibre.gui2 import must_use_qt
|
from calibre.gui2 import must_use_qt
|
||||||
|
from calibre.utils.resources import get_path as P
|
||||||
from calibre.utils.webengine import secure_webengine, setup_profile
|
from calibre.utils.webengine import secure_webengine, setup_profile
|
||||||
|
|
||||||
|
|
||||||
|
@ -4,23 +4,24 @@
|
|||||||
__license__ = 'GPL v3'
|
__license__ = 'GPL v3'
|
||||||
__copyright__ = '2013, Kovid Goyal <kovid at kovidgoyal.net>'
|
__copyright__ = '2013, Kovid Goyal <kovid at kovidgoyal.net>'
|
||||||
|
|
||||||
import sys, os
|
import os
|
||||||
|
import sys
|
||||||
from lxml import etree
|
from lxml import etree
|
||||||
|
|
||||||
from calibre import prepare_string_for_xml, CurrentDir
|
from calibre import CurrentDir, prepare_string_for_xml
|
||||||
from calibre.ptempfile import TemporaryDirectory
|
|
||||||
from calibre.ebooks.oeb.base import serialize
|
|
||||||
from calibre.ebooks.metadata import authors_to_string
|
from calibre.ebooks.metadata import authors_to_string
|
||||||
from calibre.ebooks.metadata.opf2 import metadata_to_opf
|
from calibre.ebooks.metadata.opf2 import metadata_to_opf
|
||||||
|
from calibre.ebooks.oeb.base import serialize
|
||||||
|
from calibre.ebooks.oeb.polish.container import OPF_NAMESPACES, Container, opf_to_azw3
|
||||||
from calibre.ebooks.oeb.polish.parsing import parse
|
from calibre.ebooks.oeb.polish.parsing import parse
|
||||||
from calibre.ebooks.oeb.polish.container import OPF_NAMESPACES, opf_to_azw3, Container
|
from calibre.ebooks.oeb.polish.pretty import pretty_html_tree, pretty_xml_tree
|
||||||
from calibre.ebooks.oeb.polish.utils import guess_type
|
|
||||||
from calibre.ebooks.oeb.polish.pretty import pretty_xml_tree, pretty_html_tree
|
|
||||||
from calibre.ebooks.oeb.polish.toc import TOC, create_ncx
|
from calibre.ebooks.oeb.polish.toc import TOC, create_ncx
|
||||||
|
from calibre.ebooks.oeb.polish.utils import guess_type
|
||||||
|
from calibre.ptempfile import TemporaryDirectory
|
||||||
from calibre.utils.localization import lang_as_iso639_1
|
from calibre.utils.localization import lang_as_iso639_1
|
||||||
from calibre.utils.logging import DevNull
|
from calibre.utils.logging import DevNull
|
||||||
from calibre.utils.zipfile import ZipFile, ZIP_STORED
|
from calibre.utils.resources import get_path as P
|
||||||
|
from calibre.utils.zipfile import ZIP_STORED, ZipFile
|
||||||
from polyglot.builtins import as_bytes
|
from polyglot.builtins import as_bytes
|
||||||
|
|
||||||
valid_empty_formats = {'epub', 'txt', 'docx', 'azw3', 'md'}
|
valid_empty_formats = {'epub', 'txt', 'docx', 'azw3', 'md'}
|
||||||
|
@ -4,13 +4,15 @@
|
|||||||
__license__ = 'GPL v3'
|
__license__ = 'GPL v3'
|
||||||
__copyright__ = '2013, Kovid Goyal <kovid at kovidgoyal.net>'
|
__copyright__ = '2013, Kovid Goyal <kovid at kovidgoyal.net>'
|
||||||
|
|
||||||
import os, unittest, shutil
|
import os
|
||||||
|
import shutil
|
||||||
|
import unittest
|
||||||
|
|
||||||
from calibre import CurrentDir
|
|
||||||
from calibre.ptempfile import TemporaryDirectory
|
|
||||||
from calibre.ptempfile import PersistentTemporaryDirectory
|
|
||||||
from calibre.utils.logging import DevNull
|
|
||||||
import calibre.ebooks.oeb.polish.container as pc
|
import calibre.ebooks.oeb.polish.container as pc
|
||||||
|
from calibre import CurrentDir
|
||||||
|
from calibre.ptempfile import PersistentTemporaryDirectory, TemporaryDirectory
|
||||||
|
from calibre.utils.logging import DevNull
|
||||||
|
from calibre.utils.resources import get_path as P
|
||||||
from polyglot.builtins import iteritems
|
from polyglot.builtins import iteritems
|
||||||
|
|
||||||
|
|
||||||
|
@ -4,16 +4,22 @@
|
|||||||
__license__ = 'GPL v3'
|
__license__ = 'GPL v3'
|
||||||
__copyright__ = '2013, Kovid Goyal <kovid at kovidgoyal.net>'
|
__copyright__ = '2013, Kovid Goyal <kovid at kovidgoyal.net>'
|
||||||
|
|
||||||
import os, subprocess
|
import os
|
||||||
|
import subprocess
|
||||||
from zipfile import ZipFile
|
from zipfile import ZipFile
|
||||||
|
|
||||||
from calibre import CurrentDir
|
from calibre import CurrentDir
|
||||||
from calibre.ebooks.oeb.polish.tests.base import BaseTest, get_simple_book, get_split_book
|
from calibre.ebooks.oeb.polish.container import (
|
||||||
from calibre.ebooks.oeb.polish.container import get_container as _gc, clone_container, OCF_NS
|
OCF_NS, clone_container, get_container as _gc,
|
||||||
from calibre.ebooks.oeb.polish.replace import rename_files, rationalize_folders
|
)
|
||||||
from calibre.ebooks.oeb.polish.split import split, merge
|
from calibre.ebooks.oeb.polish.replace import rationalize_folders, rename_files
|
||||||
|
from calibre.ebooks.oeb.polish.split import merge, split
|
||||||
|
from calibre.ebooks.oeb.polish.tests.base import (
|
||||||
|
BaseTest, get_simple_book, get_split_book,
|
||||||
|
)
|
||||||
|
from calibre.ptempfile import TemporaryDirectory, TemporaryFile
|
||||||
from calibre.utils.filenames import nlinks_file
|
from calibre.utils.filenames import nlinks_file
|
||||||
from calibre.ptempfile import TemporaryFile, TemporaryDirectory
|
from calibre.utils.resources import get_path as P
|
||||||
from polyglot.builtins import iteritems, itervalues
|
from polyglot.builtins import iteritems, itervalues
|
||||||
|
|
||||||
|
|
||||||
@ -193,7 +199,9 @@ class ContainerTests(BaseTest):
|
|||||||
|
|
||||||
def test_actual_case(self):
|
def test_actual_case(self):
|
||||||
' Test getting the actual case for files from names on case insensitive filesystems '
|
' Test getting the actual case for files from names on case insensitive filesystems '
|
||||||
from calibre.ebooks.oeb.polish.utils import actual_case_for_name, corrected_case_for_name
|
from calibre.ebooks.oeb.polish.utils import (
|
||||||
|
actual_case_for_name, corrected_case_for_name,
|
||||||
|
)
|
||||||
book = get_simple_book()
|
book = get_simple_book()
|
||||||
c = get_container(book)
|
c = get_container(book)
|
||||||
name = 'f1/f2/added file.html'
|
name = 'f1/f2/added file.html'
|
||||||
|
@ -8,20 +8,22 @@ __docformat__ = 'restructuredtext en'
|
|||||||
import re
|
import re
|
||||||
from collections import Counter, OrderedDict
|
from collections import Counter, OrderedDict
|
||||||
from functools import partial
|
from functools import partial
|
||||||
from operator import itemgetter
|
|
||||||
|
|
||||||
from lxml import etree
|
from lxml import etree
|
||||||
from lxml.builder import ElementMaker
|
from lxml.builder import ElementMaker
|
||||||
|
from operator import itemgetter
|
||||||
|
|
||||||
from calibre import __version__
|
from calibre import __version__
|
||||||
from calibre.ebooks.oeb.base import (
|
from calibre.ebooks.oeb.base import (
|
||||||
XPath, uuid_id, xml2text, NCX, NCX_NS, XML, XHTML, XHTML_NS, serialize, EPUB_NS, XML_NS, OEB_DOCS)
|
EPUB_NS, NCX, NCX_NS, OEB_DOCS, XHTML, XHTML_NS, XML, XML_NS, XPath, serialize,
|
||||||
|
uuid_id, xml2text,
|
||||||
|
)
|
||||||
from calibre.ebooks.oeb.polish.errors import MalformedMarkup
|
from calibre.ebooks.oeb.polish.errors import MalformedMarkup
|
||||||
from calibre.ebooks.oeb.polish.utils import guess_type, extract
|
from calibre.ebooks.oeb.polish.opf import get_book_language, set_guide_item
|
||||||
from calibre.ebooks.oeb.polish.opf import set_guide_item, get_book_language
|
|
||||||
from calibre.ebooks.oeb.polish.pretty import pretty_html_tree, pretty_xml_tree
|
from calibre.ebooks.oeb.polish.pretty import pretty_html_tree, pretty_xml_tree
|
||||||
|
from calibre.ebooks.oeb.polish.utils import extract, guess_type
|
||||||
from calibre.translations.dynamic import translate
|
from calibre.translations.dynamic import translate
|
||||||
from calibre.utils.localization import get_lang, canonicalize_lang, lang_as_iso639_1
|
from calibre.utils.localization import canonicalize_lang, get_lang, lang_as_iso639_1
|
||||||
|
from calibre.utils.resources import get_path as P
|
||||||
from polyglot.builtins import iteritems
|
from polyglot.builtins import iteritems
|
||||||
from polyglot.urllib import urlparse
|
from polyglot.urllib import urlparse
|
||||||
|
|
||||||
|
@ -5,19 +5,29 @@ CSS property propagation class.
|
|||||||
__license__ = 'GPL v3'
|
__license__ = 'GPL v3'
|
||||||
__copyright__ = '2008, Marshall T. Vandegrift <llasram@gmail.com>'
|
__copyright__ = '2008, Marshall T. Vandegrift <llasram@gmail.com>'
|
||||||
|
|
||||||
import os, re, logging, copy, unicodedata, numbers
|
import copy
|
||||||
|
import logging
|
||||||
|
import numbers
|
||||||
|
import os
|
||||||
|
import re
|
||||||
|
import unicodedata
|
||||||
|
from css_parser import (
|
||||||
|
CSSParser, log as css_parser_log, parseString, parseStyle, profile as cssprofiles,
|
||||||
|
profiles, replaceUrls,
|
||||||
|
)
|
||||||
|
from css_parser.css import CSSFontFaceRule, CSSPageRule, CSSStyleRule, cssproperties
|
||||||
from operator import itemgetter
|
from operator import itemgetter
|
||||||
from weakref import WeakKeyDictionary
|
from weakref import WeakKeyDictionary
|
||||||
from xml.dom import SyntaxErr as CSSSyntaxError
|
from xml.dom import SyntaxErr as CSSSyntaxError
|
||||||
from css_parser.css import (CSSStyleRule, CSSPageRule, CSSFontFaceRule,
|
|
||||||
cssproperties)
|
from calibre import as_unicode, force_unicode
|
||||||
from css_parser import (profile as cssprofiles, parseString, parseStyle, log as
|
|
||||||
css_parser_log, CSSParser, profiles, replaceUrls)
|
|
||||||
from calibre import force_unicode, as_unicode
|
|
||||||
from calibre.ebooks import unit_convert
|
from calibre.ebooks import unit_convert
|
||||||
from calibre.ebooks.oeb.base import XHTML, XHTML_NS, CSS_MIME, OEB_STYLES, xpath, urlnormalize
|
from calibre.ebooks.oeb.base import (
|
||||||
|
CSS_MIME, OEB_STYLES, XHTML, XHTML_NS, urlnormalize, xpath,
|
||||||
|
)
|
||||||
from calibre.ebooks.oeb.normalize_css import DEFAULTS, normalizers
|
from calibre.ebooks.oeb.normalize_css import DEFAULTS, normalizers
|
||||||
from css_selectors import Select, SelectorError, INAPPROPRIATE_PSEUDO_CLASSES
|
from calibre.utils.resources import get_path as P
|
||||||
|
from css_selectors import INAPPROPRIATE_PSEUDO_CLASSES, Select, SelectorError
|
||||||
from polyglot.builtins import iteritems
|
from polyglot.builtins import iteritems
|
||||||
from tinycss.media3 import CSSMedia3Parser
|
from tinycss.media3 import CSSMedia3Parser
|
||||||
|
|
||||||
|
@ -18,12 +18,13 @@ from calibre.ebooks.chardet import strip_encoding_declarations
|
|||||||
from calibre.ebooks.metadata import fmt_sidx, rating_to_stars
|
from calibre.ebooks.metadata import fmt_sidx, rating_to_stars
|
||||||
from calibre.ebooks.metadata.sources.identify import urls_from_identifiers
|
from calibre.ebooks.metadata.sources.identify import urls_from_identifiers
|
||||||
from calibre.ebooks.oeb.base import (
|
from calibre.ebooks.oeb.base import (
|
||||||
XHTML, XHTML_NS, XPath, urldefrag, urlnormalize, xml2text
|
XHTML, XHTML_NS, XPath, urldefrag, urlnormalize, xml2text,
|
||||||
)
|
)
|
||||||
from calibre.library.comments import comments_to_html, markdown
|
from calibre.library.comments import comments_to_html, markdown
|
||||||
from calibre.utils.config import tweaks
|
from calibre.utils.config import tweaks
|
||||||
from calibre.utils.date import as_local_time, format_date, is_date_undefined
|
from calibre.utils.date import as_local_time, format_date, is_date_undefined
|
||||||
from calibre.utils.icu import sort_key
|
from calibre.utils.icu import sort_key
|
||||||
|
from calibre.utils.resources import get_path as P
|
||||||
|
|
||||||
JACKET_XPATH = '//h:meta[@name="calibre-content" and @content="jacket"]'
|
JACKET_XPATH = '//h:meta[@name="calibre-content" and @content="jacket"]'
|
||||||
|
|
||||||
|
@ -2,8 +2,6 @@
|
|||||||
# License: GPL v3 Copyright: 2019, Kovid Goyal <kovid at kovidgoyal.net>
|
# License: GPL v3 Copyright: 2019, Kovid Goyal <kovid at kovidgoyal.net>
|
||||||
|
|
||||||
# Imports {{{
|
# Imports {{{
|
||||||
|
|
||||||
|
|
||||||
import copy
|
import copy
|
||||||
import json
|
import json
|
||||||
import os
|
import os
|
||||||
@ -16,25 +14,23 @@ from io import BytesIO
|
|||||||
from itertools import count, repeat
|
from itertools import count, repeat
|
||||||
from qt.core import (
|
from qt.core import (
|
||||||
QApplication, QByteArray, QMarginsF, QObject, QPageLayout, Qt, QTimer, QUrl,
|
QApplication, QByteArray, QMarginsF, QObject, QPageLayout, Qt, QTimer, QUrl,
|
||||||
pyqtSignal, sip
|
pyqtSignal, sip,
|
||||||
)
|
)
|
||||||
from qt.webengine import (
|
from qt.webengine import (
|
||||||
QWebEnginePage, QWebEngineProfile, QWebEngineSettings,
|
QWebEnginePage, QWebEngineProfile, QWebEngineSettings,
|
||||||
QWebEngineUrlRequestInterceptor, QWebEngineUrlRequestJob,
|
QWebEngineUrlRequestInterceptor, QWebEngineUrlRequestJob,
|
||||||
QWebEngineUrlSchemeHandler
|
QWebEngineUrlSchemeHandler,
|
||||||
)
|
)
|
||||||
|
|
||||||
from calibre import detect_ncpus, human_readable, prepare_string_for_xml
|
from calibre import detect_ncpus, human_readable, prepare_string_for_xml
|
||||||
from calibre.constants import (
|
from calibre.constants import FAKE_HOST, FAKE_PROTOCOL, __version__, ismacos, iswindows
|
||||||
FAKE_HOST, FAKE_PROTOCOL, __version__, ismacos, iswindows
|
|
||||||
)
|
|
||||||
from calibre.ebooks.metadata.xmp import metadata_to_xmp_packet
|
from calibre.ebooks.metadata.xmp import metadata_to_xmp_packet
|
||||||
from calibre.ebooks.oeb.base import XHTML, XPath
|
from calibre.ebooks.oeb.base import XHTML, XPath
|
||||||
from calibre.ebooks.oeb.polish.container import Container as ContainerBase
|
from calibre.ebooks.oeb.polish.container import Container as ContainerBase
|
||||||
from calibre.ebooks.oeb.polish.toc import get_toc
|
from calibre.ebooks.oeb.polish.toc import get_toc
|
||||||
from calibre.ebooks.oeb.polish.utils import guess_type
|
from calibre.ebooks.oeb.polish.utils import guess_type
|
||||||
from calibre.ebooks.pdf.image_writer import (
|
from calibre.ebooks.pdf.image_writer import (
|
||||||
Image, PDFMetadata, draw_image_page, get_page_layout
|
Image, PDFMetadata, draw_image_page, get_page_layout,
|
||||||
)
|
)
|
||||||
from calibre.ebooks.pdf.render.serialize import PDFStream
|
from calibre.ebooks.pdf.render.serialize import PDFStream
|
||||||
from calibre.gui2 import setup_unix_signals
|
from calibre.gui2 import setup_unix_signals
|
||||||
@ -46,8 +42,10 @@ from calibre.utils.fonts.sfnt.subset import pdf_subset
|
|||||||
from calibre.utils.logging import default_log
|
from calibre.utils.logging import default_log
|
||||||
from calibre.utils.monotonic import monotonic
|
from calibre.utils.monotonic import monotonic
|
||||||
from calibre.utils.podofo import (
|
from calibre.utils.podofo import (
|
||||||
dedup_type3_fonts, get_podofo, remove_unused_fonts, set_metadata_implementation
|
dedup_type3_fonts, get_podofo, remove_unused_fonts, set_metadata_implementation,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
from calibre.utils.resources import get_path as P
|
||||||
from calibre.utils.short_uuid import uuid4
|
from calibre.utils.short_uuid import uuid4
|
||||||
from calibre.utils.webengine import secure_webengine, send_reply, setup_profile
|
from calibre.utils.webengine import secure_webengine, send_reply, setup_profile
|
||||||
from polyglot.builtins import as_bytes, iteritems
|
from polyglot.builtins import as_bytes, iteritems
|
||||||
|
@ -22,6 +22,7 @@ class jisyo :
|
|||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
from calibre.utils.serialize import msgpack_loads
|
from calibre.utils.serialize import msgpack_loads
|
||||||
|
from calibre.utils.resources import get_path as P
|
||||||
if self.kanwadict is None:
|
if self.kanwadict is None:
|
||||||
self.kanwadict = msgpack_loads(
|
self.kanwadict = msgpack_loads(
|
||||||
P('localization/pykakasi/kanwadict2.calibre_msgpack', data=True))
|
P('localization/pykakasi/kanwadict2.calibre_msgpack', data=True))
|
||||||
|
@ -12,11 +12,11 @@ from contextlib import contextmanager, suppress
|
|||||||
from functools import lru_cache
|
from functools import lru_cache
|
||||||
from qt.core import (
|
from qt.core import (
|
||||||
QApplication, QBuffer, QByteArray, QColor, QDateTime, QDesktopServices, QDialog,
|
QApplication, QBuffer, QByteArray, QColor, QDateTime, QDesktopServices, QDialog,
|
||||||
QDialogButtonBox, QEvent, QFile, QFileDialog, QFileIconProvider, QFileInfo,
|
QDialogButtonBox, QEvent, QFile, QFileDialog, QFileIconProvider, QFileInfo, QFont,
|
||||||
QFont, QFontDatabase, QFontInfo, QFontMetrics, QGuiApplication, QIcon,
|
QFontDatabase, QFontInfo, QFontMetrics, QGuiApplication, QIcon, QImageReader,
|
||||||
QImageReader, QImageWriter, QIODevice, QLocale, QNetworkProxyFactory, QObject,
|
QImageWriter, QIODevice, QLocale, QNetworkProxyFactory, QObject, QPalette,
|
||||||
QPalette, QResource, QSettings, QSocketNotifier, QStringListModel, Qt, QThread,
|
QResource, QSettings, QSocketNotifier, QStringListModel, Qt, QThread, QTimer,
|
||||||
QTimer, QTranslator, QUrl, pyqtSignal, pyqtSlot
|
QTranslator, QUrl, pyqtSignal, pyqtSlot,
|
||||||
)
|
)
|
||||||
from threading import Lock, RLock
|
from threading import Lock, RLock
|
||||||
|
|
||||||
@ -24,13 +24,13 @@ import calibre.gui2.pyqt6_compat as pqc
|
|||||||
from calibre import as_unicode, prints
|
from calibre import as_unicode, prints
|
||||||
from calibre.constants import (
|
from calibre.constants import (
|
||||||
DEBUG, __appname__ as APP_UID, __version__, builtin_colors_dark,
|
DEBUG, __appname__ as APP_UID, __version__, builtin_colors_dark,
|
||||||
builtin_colors_light, config_dir, is_running_from_develop, isbsd, isfrozen,
|
builtin_colors_light, config_dir, is_running_from_develop, isbsd, isfrozen, islinux,
|
||||||
islinux, ismacos, iswindows, isxp, numeric_version, plugins_loc
|
ismacos, iswindows, isxp, numeric_version, plugins_loc,
|
||||||
)
|
)
|
||||||
from calibre.ebooks.metadata import MetaInformation
|
from calibre.ebooks.metadata import MetaInformation
|
||||||
from calibre.gui2.geometry import geometry_for_restore_as_dict
|
from calibre.gui2.geometry import geometry_for_restore_as_dict
|
||||||
from calibre.gui2.linux_file_dialogs import (
|
from calibre.gui2.linux_file_dialogs import (
|
||||||
check_for_linux_native_dialogs, linux_native_dialog
|
check_for_linux_native_dialogs, linux_native_dialog,
|
||||||
)
|
)
|
||||||
from calibre.gui2.palette import PaletteManager
|
from calibre.gui2.palette import PaletteManager
|
||||||
from calibre.gui2.qt_file_dialogs import FileDialog
|
from calibre.gui2.qt_file_dialogs import FileDialog
|
||||||
@ -41,7 +41,7 @@ from calibre.utils.date import UNDEFINED_DATE
|
|||||||
from calibre.utils.file_type_icons import EXT_MAP
|
from calibre.utils.file_type_icons import EXT_MAP
|
||||||
from calibre.utils.img import set_image_allocation_limit
|
from calibre.utils.img import set_image_allocation_limit
|
||||||
from calibre.utils.localization import get_lang
|
from calibre.utils.localization import get_lang
|
||||||
from calibre.utils.resources import user_dir
|
from calibre.utils.resources import get_path as P, user_dir
|
||||||
from polyglot import queue
|
from polyglot import queue
|
||||||
from polyglot.builtins import iteritems, string_or_bytes
|
from polyglot.builtins import iteritems, string_or_bytes
|
||||||
|
|
||||||
@ -888,14 +888,14 @@ if not iswindows and not ismacos and 'CALIBRE_NO_NATIVE_FILEDIALOGS' not in os.e
|
|||||||
|
|
||||||
if has_windows_file_dialog_helper:
|
if has_windows_file_dialog_helper:
|
||||||
from calibre.gui2.win_file_dialogs import (
|
from calibre.gui2.win_file_dialogs import (
|
||||||
choose_dir, choose_files, choose_images, choose_save_file
|
choose_dir, choose_files, choose_images, choose_save_file,
|
||||||
)
|
)
|
||||||
elif has_linux_file_dialog_helper:
|
elif has_linux_file_dialog_helper:
|
||||||
choose_dir, choose_files, choose_save_file, choose_images = map(
|
choose_dir, choose_files, choose_save_file, choose_images = map(
|
||||||
linux_native_dialog, 'dir files save_file images'.split())
|
linux_native_dialog, 'dir files save_file images'.split())
|
||||||
else:
|
else:
|
||||||
from calibre.gui2.qt_file_dialogs import (
|
from calibre.gui2.qt_file_dialogs import (
|
||||||
choose_dir, choose_files, choose_images, choose_save_file
|
choose_dir, choose_files, choose_images, choose_save_file,
|
||||||
)
|
)
|
||||||
choose_files, choose_images, choose_dir, choose_save_file
|
choose_files, choose_images, choose_dir, choose_save_file
|
||||||
|
|
||||||
|
@ -5,12 +5,11 @@
|
|||||||
import os
|
import os
|
||||||
import re
|
import re
|
||||||
from collections import namedtuple
|
from collections import namedtuple
|
||||||
from functools import partial, lru_cache
|
from functools import lru_cache, partial
|
||||||
from qt.core import (
|
from qt.core import (
|
||||||
QAction, QApplication, QClipboard, QColor, QDialog, QEasingCurve, QIcon,
|
QAction, QApplication, QClipboard, QColor, QDialog, QEasingCurve, QIcon,
|
||||||
QKeySequence, QMenu, QMimeData, QPainter, QPen, QPixmap, QSplitter,
|
QKeySequence, QMenu, QMimeData, QPainter, QPen, QPixmap, QPropertyAnimation, QRect,
|
||||||
QPropertyAnimation, QRect, QSize, QSizePolicy, Qt, QUrl, QWidget, pyqtProperty,
|
QSize, QSizePolicy, QSplitter, Qt, QTimer, QUrl, QWidget, pyqtProperty, pyqtSignal,
|
||||||
QTimer, pyqtSignal
|
|
||||||
)
|
)
|
||||||
|
|
||||||
from calibre import fit_image, sanitize_file_name
|
from calibre import fit_image, sanitize_file_name
|
||||||
@ -20,20 +19,21 @@ from calibre.ebooks.metadata.book.base import Metadata, field_metadata
|
|||||||
from calibre.ebooks.metadata.book.render import mi_to_html
|
from calibre.ebooks.metadata.book.render import mi_to_html
|
||||||
from calibre.ebooks.metadata.search_internet import (
|
from calibre.ebooks.metadata.search_internet import (
|
||||||
all_author_searches, all_book_searches, name_for, url_for_author_search,
|
all_author_searches, all_book_searches, name_for, url_for_author_search,
|
||||||
url_for_book_search
|
url_for_book_search,
|
||||||
)
|
)
|
||||||
from calibre.gui2 import (
|
from calibre.gui2 import (
|
||||||
NO_URL_FORMATTING, choose_save_file, config, default_author_link, gprefs,
|
NO_URL_FORMATTING, choose_save_file, config, default_author_link, gprefs,
|
||||||
pixmap_to_data, rating_font, safe_open_url
|
pixmap_to_data, rating_font, safe_open_url,
|
||||||
)
|
)
|
||||||
from calibre.gui2.dialogs.confirm_delete import confirm, confirm as confirm_delete
|
from calibre.gui2.dialogs.confirm_delete import confirm, confirm as confirm_delete
|
||||||
from calibre.gui2.dnd import (
|
from calibre.gui2.dnd import (
|
||||||
dnd_get_files, dnd_get_image, dnd_has_extension, dnd_has_image, image_extensions
|
dnd_get_files, dnd_get_image, dnd_has_extension, dnd_has_image, image_extensions,
|
||||||
)
|
)
|
||||||
from calibre.gui2.widgets2 import HTMLDisplay
|
from calibre.gui2.widgets2 import HTMLDisplay
|
||||||
from calibre.utils.config import tweaks
|
from calibre.utils.config import tweaks
|
||||||
from calibre.utils.img import blend_image, image_from_x
|
from calibre.utils.img import blend_image, image_from_x
|
||||||
from calibre.utils.localization import is_rtl, langnames_to_langcodes
|
from calibre.utils.localization import is_rtl, langnames_to_langcodes
|
||||||
|
from calibre.utils.resources import get_path as P
|
||||||
from calibre.utils.serialize import json_loads
|
from calibre.utils.serialize import json_loads
|
||||||
from polyglot.binary import from_hex_bytes
|
from polyglot.binary import from_hex_bytes
|
||||||
|
|
||||||
|
@ -5,30 +5,36 @@ __copyright__ = '2008, Kovid Goyal kovid@kovidgoyal.net'
|
|||||||
__docformat__ = 'restructuredtext en'
|
__docformat__ = 'restructuredtext en'
|
||||||
__license__ = 'GPL v3'
|
__license__ = 'GPL v3'
|
||||||
|
|
||||||
import json, os, traceback, re
|
import json
|
||||||
from functools import partial
|
import os
|
||||||
|
import re
|
||||||
import sys
|
import sys
|
||||||
|
import traceback
|
||||||
from qt.core import (Qt, QDialog, QDialogButtonBox, QSyntaxHighlighter, QFont,
|
from functools import partial
|
||||||
QApplication, QTextCharFormat, QColor, QCursor,
|
from qt.core import (
|
||||||
QIcon, QSize, QPalette, QLineEdit, QFontInfo,
|
QAbstractItemView, QApplication, QColor, QComboBox, QCursor, QDialog,
|
||||||
QFontDatabase, QVBoxLayout, QTableWidget, QTableWidgetItem,
|
QDialogButtonBox, QFont, QFontDatabase, QFontInfo, QFontMetrics, QIcon, QLineEdit,
|
||||||
QComboBox, QAbstractItemView, QTextOption, QFontMetrics)
|
QPalette, QSize, QSyntaxHighlighter, Qt, QTableWidget, QTableWidgetItem,
|
||||||
|
QTextCharFormat, QTextOption, QVBoxLayout,
|
||||||
|
)
|
||||||
|
|
||||||
from calibre import sanitize_file_name
|
from calibre import sanitize_file_name
|
||||||
from calibre.constants import config_dir
|
from calibre.constants import config_dir
|
||||||
from calibre.ebooks.metadata.book.base import Metadata
|
from calibre.ebooks.metadata.book.base import Metadata
|
||||||
from calibre.ebooks.metadata.book.formatter import SafeFormat
|
from calibre.ebooks.metadata.book.formatter import SafeFormat
|
||||||
from calibre.gui2 import (gprefs, error_dialog, choose_files, choose_save_file,
|
from calibre.gui2 import (
|
||||||
pixmap_to_data, question_dialog)
|
choose_files, choose_save_file, error_dialog, gprefs, pixmap_to_data,
|
||||||
|
question_dialog,
|
||||||
|
)
|
||||||
from calibre.gui2.dialogs.template_dialog_ui import Ui_TemplateDialog
|
from calibre.gui2.dialogs.template_dialog_ui import Ui_TemplateDialog
|
||||||
from calibre.library.coloring import (displayable_columns, color_row_key)
|
from calibre.library.coloring import color_row_key, displayable_columns
|
||||||
from calibre.utils.config_base import tweaks
|
from calibre.utils.config_base import tweaks
|
||||||
from calibre.utils.date import DEFAULT_DATE
|
from calibre.utils.date import DEFAULT_DATE
|
||||||
from calibre.utils.formatter_functions import formatter_functions, StoredObjectType
|
from calibre.utils.formatter import PythonTemplateContext, StopException
|
||||||
from calibre.utils.formatter import StopException, PythonTemplateContext
|
from calibre.utils.formatter_functions import StoredObjectType, formatter_functions
|
||||||
from calibre.utils.icu import sort_key
|
from calibre.utils.icu import sort_key
|
||||||
from calibre.utils.localization import localize_user_manual_link
|
from calibre.utils.localization import localize_user_manual_link
|
||||||
|
from calibre.utils.resources import get_path as P
|
||||||
|
|
||||||
|
|
||||||
class ParenPosition:
|
class ParenPosition:
|
||||||
|
@ -20,10 +20,10 @@ from multiprocessing.pool import ThreadPool
|
|||||||
from qt.core import (
|
from qt.core import (
|
||||||
QAbstractItemView, QApplication, QCheckBox, QComboBox, QDialog, QDialogButtonBox,
|
QAbstractItemView, QApplication, QCheckBox, QComboBox, QDialog, QDialogButtonBox,
|
||||||
QFormLayout, QGroupBox, QHBoxLayout, QIcon, QImage, QImageReader,
|
QFormLayout, QGroupBox, QHBoxLayout, QIcon, QImage, QImageReader,
|
||||||
QItemSelectionModel, QLabel, QLineEdit, QListWidget, QListWidgetItem, QPen,
|
QItemSelectionModel, QLabel, QLineEdit, QListWidget, QListWidgetItem, QPen, QPixmap,
|
||||||
QPixmap, QProgressDialog, QSize, QSpinBox, QSplitter, QStackedLayout,
|
QProgressDialog, QSize, QSpinBox, QSplitter, QStackedLayout, QStaticText, QStyle,
|
||||||
QStaticText, QStyle, QStyledItemDelegate, Qt, QTabWidget, QTextEdit, QVBoxLayout,
|
QStyledItemDelegate, Qt, QTabWidget, QTextEdit, QVBoxLayout, QWidget, pyqtSignal,
|
||||||
QWidget, pyqtSignal, sip
|
sip,
|
||||||
)
|
)
|
||||||
from threading import Event, Thread
|
from threading import Event, Thread
|
||||||
|
|
||||||
@ -32,7 +32,7 @@ from calibre.constants import cache_dir
|
|||||||
from calibre.customize.ui import interface_actions
|
from calibre.customize.ui import interface_actions
|
||||||
from calibre.gui2 import (
|
from calibre.gui2 import (
|
||||||
choose_dir, choose_save_file, empty_index, error_dialog, gprefs,
|
choose_dir, choose_save_file, empty_index, error_dialog, gprefs,
|
||||||
icon_resource_manager, must_use_qt, safe_open_url
|
icon_resource_manager, must_use_qt, safe_open_url,
|
||||||
)
|
)
|
||||||
from calibre.gui2.dialogs.progress import ProgressDialog
|
from calibre.gui2.dialogs.progress import ProgressDialog
|
||||||
from calibre.gui2.progress_indicator import ProgressIndicator
|
from calibre.gui2.progress_indicator import ProgressIndicator
|
||||||
@ -42,6 +42,7 @@ from calibre.utils.filenames import ascii_filename, atomic_rename
|
|||||||
from calibre.utils.https import HTTPError, get_https_resource_securely
|
from calibre.utils.https import HTTPError, get_https_resource_securely
|
||||||
from calibre.utils.icu import numeric_sort_key as sort_key
|
from calibre.utils.icu import numeric_sort_key as sort_key
|
||||||
from calibre.utils.img import Canvas, image_from_data, optimize_jpeg, optimize_png
|
from calibre.utils.img import Canvas, image_from_data, optimize_jpeg, optimize_png
|
||||||
|
from calibre.utils.resources import get_path as P
|
||||||
from calibre.utils.zipfile import ZIP_STORED, ZipFile
|
from calibre.utils.zipfile import ZIP_STORED, ZipFile
|
||||||
from polyglot import http_client
|
from polyglot import http_client
|
||||||
from polyglot.builtins import as_bytes, iteritems, reraise
|
from polyglot.builtins import as_bytes, iteritems, reraise
|
||||||
@ -127,6 +128,7 @@ def read_theme_from_folder(path):
|
|||||||
return int(x)
|
return int(x)
|
||||||
except Exception:
|
except Exception:
|
||||||
return -1
|
return -1
|
||||||
|
|
||||||
def g(x, defval=''):
|
def g(x, defval=''):
|
||||||
return metadata.get(x, defval)
|
return metadata.get(x, defval)
|
||||||
theme = Theme(g('title'), g('author'), safe_int(g('version', -1)), g('description'), g('license', 'Unknown'), g('url', None))
|
theme = Theme(g('title'), g('author'), safe_int(g('version', -1)), g('description'), g('license', 'Unknown'), g('url', None))
|
||||||
|
@ -14,10 +14,14 @@ import time
|
|||||||
import traceback
|
import traceback
|
||||||
from collections import defaultdict, namedtuple
|
from collections import defaultdict, namedtuple
|
||||||
from itertools import groupby
|
from itertools import groupby
|
||||||
|
from qt.core import (
|
||||||
|
QAbstractTableModel, QApplication, QColor, QDateTime, QFont, QFontMetrics, QIcon,
|
||||||
|
QImage, QModelIndex, QPainter, QPixmap, Qt, pyqtSignal,
|
||||||
|
)
|
||||||
|
|
||||||
from calibre import (
|
from calibre import (
|
||||||
fit_image, force_unicode, human_readable, isbytestring, prepare_string_for_xml,
|
fit_image, force_unicode, human_readable, isbytestring, prepare_string_for_xml,
|
||||||
strftime
|
strftime,
|
||||||
)
|
)
|
||||||
from calibre.constants import DEBUG, config_dir, dark_link_color, filesystem_encoding
|
from calibre.constants import DEBUG, config_dir, dark_link_color, filesystem_encoding
|
||||||
from calibre.db.search import CONTAINS_MATCH, EQUALS_MATCH, REGEXP_MATCH, _match
|
from calibre.db.search import CONTAINS_MATCH, EQUALS_MATCH, REGEXP_MATCH, _match
|
||||||
@ -30,15 +34,14 @@ from calibre.library.coloring import color_row_key
|
|||||||
from calibre.library.save_to_disk import find_plugboard
|
from calibre.library.save_to_disk import find_plugboard
|
||||||
from calibre.ptempfile import PersistentTemporaryFile
|
from calibre.ptempfile import PersistentTemporaryFile
|
||||||
from calibre.utils.config import device_prefs, prefs, tweaks
|
from calibre.utils.config import device_prefs, prefs, tweaks
|
||||||
from calibre.utils.date import (UNDEFINED_DATE, as_local_time, dt_factory,
|
from calibre.utils.date import (
|
||||||
is_date_undefined, qt_to_dt)
|
UNDEFINED_DATE, as_local_time, dt_factory, is_date_undefined, qt_to_dt,
|
||||||
|
)
|
||||||
from calibre.utils.icu import sort_key
|
from calibre.utils.icu import sort_key
|
||||||
from calibre.utils.localization import calibre_langcode_to_name
|
from calibre.utils.localization import calibre_langcode_to_name
|
||||||
|
from calibre.utils.resources import get_path as P
|
||||||
from calibre.utils.search_query_parser import ParseException, SearchQueryParser
|
from calibre.utils.search_query_parser import ParseException, SearchQueryParser
|
||||||
from polyglot.builtins import iteritems, itervalues, string_or_bytes
|
from polyglot.builtins import iteritems, itervalues, string_or_bytes
|
||||||
from qt.core import (QAbstractTableModel, QApplication, QColor, QDateTime,
|
|
||||||
QFont, QFontMetrics, QIcon, QImage, QModelIndex, QPainter,
|
|
||||||
QPixmap, Qt, pyqtSignal)
|
|
||||||
|
|
||||||
Counts = namedtuple('Counts', 'library_total total current')
|
Counts = namedtuple('Counts', 'library_total total current')
|
||||||
|
|
||||||
|
@ -1,15 +1,17 @@
|
|||||||
__license__ = 'GPL v3'
|
__license__ = 'GPL v3'
|
||||||
__copyright__ = '2008, Kovid Goyal <kovid at kovidgoyal.net>'
|
__copyright__ = '2008, Kovid Goyal <kovid at kovidgoyal.net>'
|
||||||
|
|
||||||
import collections, itertools, glob
|
import collections
|
||||||
|
import glob
|
||||||
|
import itertools
|
||||||
from qt.core import (
|
from qt.core import (
|
||||||
Qt, QByteArray, pyqtSignal, QGraphicsRectItem, QGraphicsScene, QPen,
|
QBrush, QByteArray, QColor, QFontDatabase, QGraphicsItem, QGraphicsLineItem,
|
||||||
QBrush, QColor, QFontDatabase, QGraphicsItem, QGraphicsLineItem)
|
QGraphicsRectItem, QGraphicsScene, QPen, Qt, pyqtSignal,
|
||||||
|
)
|
||||||
|
|
||||||
from calibre.gui2.lrf_renderer.text import TextBlock, FontLoader, COLOR, PixmapItem
|
from calibre.ebooks.lrf.objects import Canvas as __Canvas, RuledLine as _RuledLine
|
||||||
from calibre.ebooks.lrf.objects import RuledLine as _RuledLine
|
from calibre.gui2.lrf_renderer.text import COLOR, FontLoader, PixmapItem, TextBlock
|
||||||
from calibre.ebooks.lrf.objects import Canvas as __Canvas
|
from calibre.utils.resources import get_path as P
|
||||||
|
|
||||||
|
|
||||||
class Color(QColor):
|
class Color(QColor):
|
||||||
|
@ -7,39 +7,40 @@ __docformat__ = 'restructuredtext en'
|
|||||||
|
|
||||||
import json
|
import json
|
||||||
from collections import defaultdict
|
from collections import defaultdict
|
||||||
from threading import Thread
|
|
||||||
from functools import partial
|
from functools import partial
|
||||||
|
|
||||||
from qt.core import (
|
from qt.core import (
|
||||||
QApplication, QFont, QFontInfo, QFontDialog, QColorDialog, QPainter, QDialog,
|
QAbstractListModel, QApplication, QBrush, QColor, QColorDialog, QComboBox, QDialog,
|
||||||
QAbstractListModel, Qt, QIcon, QKeySequence, QColor, pyqtSignal, QHeaderView, QListWidgetItem,
|
QDialogButtonBox, QFont, QFontDialog, QFontInfo, QFormLayout, QHeaderView, QIcon,
|
||||||
QWidget, QSizePolicy, QBrush, QPixmap, QSize, QPushButton, QVBoxLayout, QItemSelectionModel,
|
QItemSelectionModel, QKeySequence, QLabel, QLineEdit, QListWidgetItem, QPainter,
|
||||||
QTableWidget, QTableWidgetItem, QLabel, QFormLayout, QLineEdit, QComboBox, QDialogButtonBox
|
QPixmap, QPushButton, QSize, QSizePolicy, Qt, QTableWidget, QTableWidgetItem,
|
||||||
|
QVBoxLayout, QWidget, pyqtSignal,
|
||||||
)
|
)
|
||||||
|
from threading import Thread
|
||||||
|
|
||||||
from calibre import human_readable
|
from calibre import human_readable
|
||||||
from calibre.constants import ismacos, iswindows
|
from calibre.constants import ismacos, iswindows
|
||||||
from calibre.db.categories import is_standard_category
|
from calibre.db.categories import is_standard_category
|
||||||
from calibre.ebooks.metadata.book.render import DEFAULT_AUTHOR_LINK
|
from calibre.ebooks.metadata.book.render import DEFAULT_AUTHOR_LINK
|
||||||
from calibre.ebooks.metadata.sources.prefs import msprefs
|
from calibre.ebooks.metadata.sources.prefs import msprefs
|
||||||
from calibre.gui2.custom_column_widgets import get_field_list as em_get_field_list
|
from calibre.gui2 import (
|
||||||
from calibre.gui2 import default_author_link, icon_resource_manager, choose_save_file, choose_files
|
choose_files, choose_save_file, config, default_author_link, error_dialog, gprefs,
|
||||||
from calibre.gui2.dialogs.template_dialog import TemplateDialog
|
icon_resource_manager, open_local_file, qt_app, question_dialog,
|
||||||
from calibre.gui2.preferences import ConfigWidgetBase, test_widget
|
)
|
||||||
from calibre.gui2.preferences.look_feel_ui import Ui_Form
|
from calibre.gui2.actions.show_quickview import get_quickview_action_plugin
|
||||||
from calibre.gui2 import config, gprefs, qt_app, open_local_file, question_dialog, error_dialog
|
|
||||||
from calibre.utils.localization import (available_translations,
|
|
||||||
get_language, get_lang)
|
|
||||||
from calibre.utils.config import prefs
|
|
||||||
from calibre.utils.icu import sort_key
|
|
||||||
from calibre.gui2.book_details import get_field_list
|
from calibre.gui2.book_details import get_field_list
|
||||||
|
from calibre.gui2.custom_column_widgets import get_field_list as em_get_field_list
|
||||||
from calibre.gui2.dialogs.quickview import get_qv_field_list
|
from calibre.gui2.dialogs.quickview import get_qv_field_list
|
||||||
|
from calibre.gui2.dialogs.template_dialog import TemplateDialog
|
||||||
|
from calibre.gui2.library.alternate_views import CM_TO_INCH, auto_height
|
||||||
|
from calibre.gui2.preferences import ConfigWidgetBase, test_widget
|
||||||
from calibre.gui2.preferences.coloring import EditRules
|
from calibre.gui2.preferences.coloring import EditRules
|
||||||
from calibre.gui2.library.alternate_views import auto_height, CM_TO_INCH
|
from calibre.gui2.preferences.look_feel_ui import Ui_Form
|
||||||
from calibre.gui2.widgets import BusyCursor
|
from calibre.gui2.widgets import BusyCursor
|
||||||
from calibre.gui2.widgets2 import Dialog
|
from calibre.gui2.widgets2 import Dialog
|
||||||
from calibre.gui2.actions.show_quickview import get_quickview_action_plugin
|
from calibre.utils.config import prefs
|
||||||
from calibre.utils.resources import set_data
|
from calibre.utils.icu import sort_key
|
||||||
|
from calibre.utils.localization import available_translations, get_lang, get_language
|
||||||
|
from calibre.utils.resources import get_path as P, set_data
|
||||||
from polyglot.builtins import iteritems
|
from polyglot.builtins import iteritems
|
||||||
|
|
||||||
|
|
||||||
|
@ -12,10 +12,11 @@ from calibre.gui2.preferences import AbortInitialize, ConfigWidgetBase, test_wid
|
|||||||
from calibre.gui2.preferences.template_functions_ui import Ui_Form
|
from calibre.gui2.preferences.template_functions_ui import Ui_Form
|
||||||
from calibre.gui2.widgets import PythonHighlighter
|
from calibre.gui2.widgets import PythonHighlighter
|
||||||
from calibre.utils.formatter_functions import (
|
from calibre.utils.formatter_functions import (
|
||||||
compile_user_function, compile_user_template_functions, formatter_functions,
|
StoredObjectType, compile_user_function, compile_user_template_functions,
|
||||||
function_object_type, function_pref_name, load_user_template_functions,
|
formatter_functions, function_object_type, function_pref_name,
|
||||||
StoredObjectType
|
load_user_template_functions,
|
||||||
)
|
)
|
||||||
|
from calibre.utils.resources import get_path as P
|
||||||
from polyglot.builtins import iteritems
|
from polyglot.builtins import iteritems
|
||||||
|
|
||||||
|
|
||||||
|
@ -10,12 +10,12 @@ from functools import lru_cache
|
|||||||
from qt.core import (
|
from qt.core import (
|
||||||
QApplication, QByteArray, QFrame, QGridLayout, QIcon, QLabel, QLineEdit,
|
QApplication, QByteArray, QFrame, QGridLayout, QIcon, QLabel, QLineEdit,
|
||||||
QListWidget, QPushButton, QSize, QSplitter, Qt, QUrl, QVBoxLayout, QWidget,
|
QListWidget, QPushButton, QSize, QSplitter, Qt, QUrl, QVBoxLayout, QWidget,
|
||||||
pyqtSignal
|
pyqtSignal,
|
||||||
)
|
)
|
||||||
from qt.webengine import (
|
from qt.webengine import (
|
||||||
QWebEnginePage, QWebEngineProfile, QWebEngineScript,
|
QWebEnginePage, QWebEngineProfile, QWebEngineScript,
|
||||||
QWebEngineUrlRequestInterceptor, QWebEngineUrlRequestJob,
|
QWebEngineUrlRequestInterceptor, QWebEngineUrlRequestJob,
|
||||||
QWebEngineUrlSchemeHandler, QWebEngineView
|
QWebEngineUrlSchemeHandler, QWebEngineView,
|
||||||
)
|
)
|
||||||
|
|
||||||
from calibre.constants import FAKE_HOST, FAKE_PROTOCOL
|
from calibre.constants import FAKE_HOST, FAKE_PROTOCOL
|
||||||
@ -23,6 +23,7 @@ from calibre.ebooks.oeb.polish.utils import guess_type
|
|||||||
from calibre.gui2 import error_dialog, gprefs, is_dark_theme, question_dialog
|
from calibre.gui2 import error_dialog, gprefs, is_dark_theme, question_dialog
|
||||||
from calibre.gui2.palette import dark_color, dark_link_color, dark_text_color
|
from calibre.gui2.palette import dark_color, dark_link_color, dark_text_color
|
||||||
from calibre.utils.logging import default_log
|
from calibre.utils.logging import default_log
|
||||||
|
from calibre.utils.resources import get_path as P
|
||||||
from calibre.utils.short_uuid import uuid4
|
from calibre.utils.short_uuid import uuid4
|
||||||
from calibre.utils.webengine import secure_webengine, send_reply, setup_profile
|
from calibre.utils.webengine import secure_webengine, send_reply, setup_profile
|
||||||
from polyglot.builtins import as_bytes
|
from polyglot.builtins import as_bytes
|
||||||
|
@ -12,6 +12,7 @@ from lxml import html
|
|||||||
from calibre import browser
|
from calibre import browser
|
||||||
from calibre.ebooks.oeb.polish.container import OEB_DOCS
|
from calibre.ebooks.oeb.polish.container import OEB_DOCS
|
||||||
from calibre.ebooks.oeb.polish.utils import guess_type
|
from calibre.ebooks.oeb.polish.utils import guess_type
|
||||||
|
from calibre.utils.resources import get_path as P
|
||||||
|
|
||||||
|
|
||||||
class URLMap:
|
class URLMap:
|
||||||
|
@ -4,13 +4,17 @@
|
|||||||
__license__ = 'GPL v3'
|
__license__ = 'GPL v3'
|
||||||
__copyright__ = '2014, Kovid Goyal <kovid at kovidgoyal.net>'
|
__copyright__ = '2014, Kovid Goyal <kovid at kovidgoyal.net>'
|
||||||
|
|
||||||
import re
|
|
||||||
|
|
||||||
from pygments.lexer import RegexLexer, default, include
|
|
||||||
from pygments.token import Comment, Punctuation, Number, Keyword, Text, String, Operator, Name
|
|
||||||
import pygments.unistring as uni
|
import pygments.unistring as uni
|
||||||
|
import re
|
||||||
|
from pygments.lexer import RegexLexer, default, include
|
||||||
|
from pygments.token import (
|
||||||
|
Comment, Keyword, Name, Number, Operator, Punctuation, String, Text,
|
||||||
|
)
|
||||||
|
|
||||||
from calibre.gui2.tweak_book.editor.syntax.pygments_highlighter import create_highlighter
|
from calibre.gui2.tweak_book.editor.syntax.pygments_highlighter import (
|
||||||
|
create_highlighter,
|
||||||
|
)
|
||||||
|
from calibre.utils.resources import get_path as P
|
||||||
from polyglot.builtins import native_string_type
|
from polyglot.builtins import native_string_type
|
||||||
|
|
||||||
JS_IDENT_START = ('(?:[$_' + uni.combine('Lu', 'Ll', 'Lt', 'Lm', 'Lo', 'Nl') +
|
JS_IDENT_START = ('(?:[$_' + uni.combine('Lu', 'Ll', 'Lt', 'Lm', 'Lo', 'Nl') +
|
||||||
|
@ -4,22 +4,28 @@
|
|||||||
__license__ = 'GPL v3'
|
__license__ = 'GPL v3'
|
||||||
__copyright__ = '2014, Kovid Goyal <kovid at kovidgoyal.net>'
|
__copyright__ = '2014, Kovid Goyal <kovid at kovidgoyal.net>'
|
||||||
|
|
||||||
import re, io, weakref, sys
|
import io
|
||||||
|
import re
|
||||||
|
import sys
|
||||||
|
import weakref
|
||||||
from qt.core import (
|
from qt.core import (
|
||||||
pyqtSignal, QVBoxLayout, QHBoxLayout, QPlainTextEdit, QLabel, QFontMetrics,
|
QApplication, QDialogButtonBox, QFontMetrics, QHBoxLayout, QIcon, QLabel,
|
||||||
QSize, Qt, QApplication, QIcon, QDialogButtonBox)
|
QPlainTextEdit, QSize, Qt, QVBoxLayout, pyqtSignal,
|
||||||
|
)
|
||||||
|
|
||||||
from calibre.ebooks.oeb.polish.utils import apply_func_to_match_groups, apply_func_to_html_text
|
from calibre.ebooks.oeb.polish.utils import (
|
||||||
|
apply_func_to_html_text, apply_func_to_match_groups,
|
||||||
|
)
|
||||||
from calibre.gui2 import error_dialog
|
from calibre.gui2 import error_dialog
|
||||||
from calibre.gui2.complete2 import EditWithComplete
|
from calibre.gui2.complete2 import EditWithComplete
|
||||||
from calibre.gui2.tweak_book import dictionaries
|
from calibre.gui2.tweak_book import dictionaries
|
||||||
from calibre.gui2.tweak_book.widgets import Dialog
|
|
||||||
from calibre.gui2.tweak_book.editor.text import TextEdit
|
from calibre.gui2.tweak_book.editor.text import TextEdit
|
||||||
|
from calibre.gui2.tweak_book.widgets import Dialog
|
||||||
from calibre.utils.config import JSONConfig
|
from calibre.utils.config import JSONConfig
|
||||||
from calibre.utils.icu import capitalize, upper, lower, swapcase
|
from calibre.utils.icu import capitalize, lower, swapcase, upper
|
||||||
from calibre.utils.titlecase import titlecase
|
|
||||||
from calibre.utils.localization import localize_user_manual_link
|
from calibre.utils.localization import localize_user_manual_link
|
||||||
|
from calibre.utils.resources import get_path as P
|
||||||
|
from calibre.utils.titlecase import titlecase
|
||||||
from polyglot.builtins import iteritems
|
from polyglot.builtins import iteritems
|
||||||
from polyglot.io import PolyglotStringIO
|
from polyglot.io import PolyglotStringIO
|
||||||
|
|
||||||
|
@ -9,25 +9,24 @@ from functools import partial
|
|||||||
from qt.core import (
|
from qt.core import (
|
||||||
QAction, QApplication, QByteArray, QHBoxLayout, QIcon, QLabel, QMenu, QSize,
|
QAction, QApplication, QByteArray, QHBoxLayout, QIcon, QLabel, QMenu, QSize,
|
||||||
QSizePolicy, QStackedLayout, Qt, QTimer, QToolBar, QUrl, QVBoxLayout, QWidget,
|
QSizePolicy, QStackedLayout, Qt, QTimer, QToolBar, QUrl, QVBoxLayout, QWidget,
|
||||||
pyqtSignal
|
pyqtSignal,
|
||||||
)
|
)
|
||||||
from qt.webengine import (
|
from qt.webengine import (
|
||||||
QWebEngineContextMenuRequest, QWebEnginePage, QWebEngineProfile,
|
QWebEngineContextMenuRequest, QWebEnginePage, QWebEngineProfile, QWebEngineScript,
|
||||||
QWebEngineScript, QWebEngineSettings, QWebEngineUrlRequestJob,
|
QWebEngineSettings, QWebEngineUrlRequestJob, QWebEngineUrlSchemeHandler,
|
||||||
QWebEngineUrlSchemeHandler, QWebEngineView
|
QWebEngineView,
|
||||||
)
|
)
|
||||||
from threading import Thread
|
from threading import Thread
|
||||||
|
|
||||||
from calibre import prints
|
from calibre import prints
|
||||||
from calibre.constants import (
|
from calibre.constants import (
|
||||||
FAKE_HOST, FAKE_PROTOCOL, __version__, is_running_from_develop, ismacos,
|
FAKE_HOST, FAKE_PROTOCOL, __version__, is_running_from_develop, ismacos, iswindows,
|
||||||
iswindows
|
|
||||||
)
|
)
|
||||||
from calibre.ebooks.oeb.base import OEB_DOCS, XHTML_MIME, serialize
|
from calibre.ebooks.oeb.base import OEB_DOCS, XHTML_MIME, serialize
|
||||||
from calibre.ebooks.oeb.polish.parsing import parse
|
from calibre.ebooks.oeb.polish.parsing import parse
|
||||||
from calibre.gui2 import (
|
from calibre.gui2 import (
|
||||||
NO_URL_FORMATTING, QT_HIDDEN_CLEAR_ACTION, error_dialog, is_dark_theme,
|
NO_URL_FORMATTING, QT_HIDDEN_CLEAR_ACTION, error_dialog, is_dark_theme,
|
||||||
safe_open_url
|
safe_open_url,
|
||||||
)
|
)
|
||||||
from calibre.gui2.palette import dark_color, dark_link_color, dark_text_color
|
from calibre.gui2.palette import dark_color, dark_link_color, dark_text_color
|
||||||
from calibre.gui2.tweak_book import TOP, actions, current_container, editors, tprefs
|
from calibre.gui2.tweak_book import TOP, actions, current_container, editors, tprefs
|
||||||
@ -36,9 +35,10 @@ from calibre.gui2.viewer.web_view import handle_mathjax_request, send_reply
|
|||||||
from calibre.gui2.webengine import RestartingWebEngineView
|
from calibre.gui2.webengine import RestartingWebEngineView
|
||||||
from calibre.gui2.widgets2 import HistoryLineEdit2
|
from calibre.gui2.widgets2 import HistoryLineEdit2
|
||||||
from calibre.utils.ipc.simple_worker import offload_worker
|
from calibre.utils.ipc.simple_worker import offload_worker
|
||||||
|
from calibre.utils.resources import get_path as P
|
||||||
from calibre.utils.webengine import (
|
from calibre.utils.webengine import (
|
||||||
Bridge, create_script, from_js, insert_scripts, secure_webengine, setup_profile,
|
Bridge, create_script, from_js, insert_scripts, secure_webengine, setup_profile,
|
||||||
to_js
|
to_js,
|
||||||
)
|
)
|
||||||
from polyglot.builtins import iteritems
|
from polyglot.builtins import iteritems
|
||||||
from polyglot.queue import Empty, Queue
|
from polyglot.queue import Empty, Queue
|
||||||
|
@ -10,27 +10,27 @@ from collections import OrderedDict, defaultdict
|
|||||||
from functools import partial
|
from functools import partial
|
||||||
from itertools import chain
|
from itertools import chain
|
||||||
from qt.core import (
|
from qt.core import (
|
||||||
QT_VERSION_STR, QAbstractTableModel, QApplication, QCheckBox, QComboBox, QDialog,
|
QT_VERSION_STR, QAbstractItemView, QAbstractTableModel, QApplication, QCheckBox,
|
||||||
QDialogButtonBox, QFont, QFormLayout, QGridLayout, QHBoxLayout, QIcon,
|
QComboBox, QDialog, QDialogButtonBox, QFont, QFormLayout, QGridLayout, QHBoxLayout,
|
||||||
QInputDialog, QKeySequence, QLabel, QLineEdit, QListWidget, QListWidgetItem,
|
QIcon, QInputDialog, QKeySequence, QLabel, QLineEdit, QListWidget, QListWidgetItem,
|
||||||
QMenu, QModelIndex, QPlainTextEdit, QPushButton, QSize, QStackedLayout, Qt,
|
QMenu, QModelIndex, QPlainTextEdit, QPushButton, QSize, QStackedLayout, Qt,
|
||||||
QTableView, QTimer, QToolButton, QTreeWidget, QTreeWidgetItem, QVBoxLayout,
|
QTableView, QTimer, QToolButton, QTreeWidget, QTreeWidgetItem, QVBoxLayout, QWidget,
|
||||||
QWidget, pyqtSignal, QAbstractItemView
|
pyqtSignal,
|
||||||
)
|
)
|
||||||
from threading import Thread
|
from threading import Thread
|
||||||
|
|
||||||
from calibre.constants import __appname__
|
from calibre.constants import __appname__
|
||||||
from calibre.ebooks.oeb.base import OEB_DOCS, NCX_MIME, OPF_MIME
|
from calibre.ebooks.oeb.base import NCX_MIME, OEB_DOCS, OPF_MIME
|
||||||
from calibre.ebooks.oeb.polish.spell import (
|
from calibre.ebooks.oeb.polish.spell import (
|
||||||
get_all_words, get_checkable_file_names, merge_locations, replace_word,
|
get_all_words, get_checkable_file_names, merge_locations, replace_word,
|
||||||
undo_replace_word
|
undo_replace_word,
|
||||||
)
|
)
|
||||||
from calibre.gui2 import choose_files, error_dialog
|
from calibre.gui2 import choose_files, error_dialog
|
||||||
from calibre.gui2.complete2 import LineEdit
|
from calibre.gui2.complete2 import LineEdit
|
||||||
from calibre.gui2.languages import LanguagesEdit
|
from calibre.gui2.languages import LanguagesEdit
|
||||||
from calibre.gui2.progress_indicator import ProgressIndicator
|
from calibre.gui2.progress_indicator import ProgressIndicator
|
||||||
from calibre.gui2.tweak_book import (
|
from calibre.gui2.tweak_book import (
|
||||||
current_container, dictionaries, editors, set_book_locale, tprefs
|
current_container, dictionaries, editors, set_book_locale, tprefs,
|
||||||
)
|
)
|
||||||
from calibre.gui2.tweak_book.widgets import Dialog
|
from calibre.gui2.tweak_book.widgets import Dialog
|
||||||
from calibre.gui2.widgets2 import FlowLayout
|
from calibre.gui2.widgets2 import FlowLayout
|
||||||
@ -38,13 +38,14 @@ from calibre.spell import DictionaryLocale
|
|||||||
from calibre.spell.break_iterator import split_into_words
|
from calibre.spell.break_iterator import split_into_words
|
||||||
from calibre.spell.dictionary import (
|
from calibre.spell.dictionary import (
|
||||||
best_locale_for_language, builtin_dictionaries, custom_dictionaries, dprefs,
|
best_locale_for_language, builtin_dictionaries, custom_dictionaries, dprefs,
|
||||||
get_dictionary, remove_dictionary, rename_dictionary
|
get_dictionary, remove_dictionary, rename_dictionary,
|
||||||
)
|
)
|
||||||
from calibre.spell.import_from import import_from_oxt
|
from calibre.spell.import_from import import_from_oxt
|
||||||
from calibre.utils.icu import contains, primary_contains, primary_sort_key, sort_key
|
from calibre.utils.icu import contains, primary_contains, primary_sort_key, sort_key
|
||||||
from calibre.utils.localization import (
|
from calibre.utils.localization import (
|
||||||
calibre_langcode_to_name, canonicalize_lang, get_lang, get_language
|
calibre_langcode_to_name, canonicalize_lang, get_lang, get_language,
|
||||||
)
|
)
|
||||||
|
from calibre.utils.resources import get_path as P
|
||||||
from calibre_extensions.progress_indicator import set_no_activate_on_click
|
from calibre_extensions.progress_indicator import set_no_activate_on_click
|
||||||
from polyglot.builtins import iteritems
|
from polyglot.builtins import iteritems
|
||||||
|
|
||||||
|
@ -20,19 +20,19 @@ from collections import OrderedDict, deque
|
|||||||
from io import BytesIO
|
from io import BytesIO
|
||||||
from qt.core import (
|
from qt.core import (
|
||||||
QAction, QApplication, QDialog, QFont, QIcon, QMenu, QSystemTrayIcon, Qt, QTimer,
|
QAction, QApplication, QDialog, QFont, QIcon, QMenu, QSystemTrayIcon, Qt, QTimer,
|
||||||
QUrl, pyqtSignal
|
QUrl, pyqtSignal,
|
||||||
)
|
)
|
||||||
|
|
||||||
from calibre import detect_ncpus, force_unicode, prints
|
from calibre import detect_ncpus, force_unicode, prints
|
||||||
from calibre.constants import (
|
from calibre.constants import (
|
||||||
DEBUG, __appname__, config_dir, filesystem_encoding, ismacos, iswindows
|
DEBUG, __appname__, config_dir, filesystem_encoding, ismacos, iswindows,
|
||||||
)
|
)
|
||||||
from calibre.customize import PluginInstallationType
|
from calibre.customize import PluginInstallationType
|
||||||
from calibre.customize.ui import available_store_plugins, interface_actions
|
from calibre.customize.ui import available_store_plugins, interface_actions
|
||||||
from calibre.db.legacy import LibraryDatabase
|
from calibre.db.legacy import LibraryDatabase
|
||||||
from calibre.gui2 import (
|
from calibre.gui2 import (
|
||||||
Dispatcher, GetMetadata, config, error_dialog, gprefs, info_dialog,
|
Dispatcher, GetMetadata, config, error_dialog, gprefs, info_dialog,
|
||||||
max_available_height, open_url, question_dialog, warning_dialog
|
max_available_height, open_url, question_dialog, warning_dialog,
|
||||||
)
|
)
|
||||||
from calibre.gui2.auto_add import AutoAdder
|
from calibre.gui2.auto_add import AutoAdder
|
||||||
from calibre.gui2.changes import handle_changes
|
from calibre.gui2.changes import handle_changes
|
||||||
@ -59,6 +59,7 @@ from calibre.library import current_library_name
|
|||||||
from calibre.srv.library_broker import GuiLibraryBroker, db_matches
|
from calibre.srv.library_broker import GuiLibraryBroker, db_matches
|
||||||
from calibre.utils.config import dynamic, prefs
|
from calibre.utils.config import dynamic, prefs
|
||||||
from calibre.utils.ipc.pool import Pool
|
from calibre.utils.ipc.pool import Pool
|
||||||
|
from calibre.utils.resources import get_path as P
|
||||||
from polyglot.builtins import string_or_bytes
|
from polyglot.builtins import string_or_bytes
|
||||||
from polyglot.queue import Empty, Queue
|
from polyglot.queue import Empty, Queue
|
||||||
|
|
||||||
@ -625,7 +626,7 @@ class Main(MainWindow, MainWindowMixin, DeviceMixin, EmailMixin, # {{{
|
|||||||
self.tags_view.recount()
|
self.tags_view.recount()
|
||||||
|
|
||||||
def handle_cli_args(self, args):
|
def handle_cli_args(self, args):
|
||||||
from urllib.parse import unquote, urlparse, parse_qs
|
from urllib.parse import parse_qs, unquote, urlparse
|
||||||
if isinstance(args, string_or_bytes):
|
if isinstance(args, string_or_bytes):
|
||||||
args = [args]
|
args = [args]
|
||||||
files, urls = [], []
|
files, urls = [], []
|
||||||
@ -870,7 +871,7 @@ class Main(MainWindow, MainWindowMixin, DeviceMixin, EmailMixin, # {{{
|
|||||||
)
|
)
|
||||||
if repair:
|
if repair:
|
||||||
from calibre.gui2.dialogs.restore_library import (
|
from calibre.gui2.dialogs.restore_library import (
|
||||||
repair_library_at
|
repair_library_at,
|
||||||
)
|
)
|
||||||
if repair_library_at(newloc, parent=self):
|
if repair_library_at(newloc, parent=self):
|
||||||
db = LibraryDatabase(newloc, default_prefs=default_prefs)
|
db = LibraryDatabase(newloc, default_prefs=default_prefs)
|
||||||
|
@ -8,10 +8,10 @@ from functools import lru_cache
|
|||||||
from qt.core import (
|
from qt.core import (
|
||||||
QAbstractItemView, QApplication, QCheckBox, QComboBox, QDialog, QDialogButtonBox,
|
QAbstractItemView, QApplication, QCheckBox, QComboBox, QDialog, QDialogButtonBox,
|
||||||
QFormLayout, QHBoxLayout, QIcon, QLabel, QLineEdit, QListWidget, QListWidgetItem,
|
QFormLayout, QHBoxLayout, QIcon, QLabel, QLineEdit, QListWidget, QListWidgetItem,
|
||||||
QPalette, QPushButton, QSize, Qt, QTimer, QUrl, QVBoxLayout, QWidget, pyqtSignal
|
QPalette, QPushButton, QSize, Qt, QTimer, QUrl, QVBoxLayout, QWidget, pyqtSignal,
|
||||||
)
|
)
|
||||||
from qt.webengine import (
|
from qt.webengine import (
|
||||||
QWebEnginePage, QWebEngineProfile, QWebEngineScript, QWebEngineView
|
QWebEnginePage, QWebEngineProfile, QWebEngineScript, QWebEngineView,
|
||||||
)
|
)
|
||||||
|
|
||||||
from calibre import prints, random_user_agent
|
from calibre import prints, random_user_agent
|
||||||
@ -19,8 +19,9 @@ from calibre.gui2 import error_dialog
|
|||||||
from calibre.gui2.viewer.web_view import apply_font_settings, vprefs
|
from calibre.gui2.viewer.web_view import apply_font_settings, vprefs
|
||||||
from calibre.gui2.widgets2 import Dialog
|
from calibre.gui2.widgets2 import Dialog
|
||||||
from calibre.utils.localization import canonicalize_lang, get_lang, lang_as_iso639_1
|
from calibre.utils.localization import canonicalize_lang, get_lang, lang_as_iso639_1
|
||||||
|
from calibre.utils.resources import get_path as P
|
||||||
from calibre.utils.webengine import (
|
from calibre.utils.webengine import (
|
||||||
create_script, insert_scripts, secure_webengine, setup_profile
|
create_script, insert_scripts, secure_webengine, setup_profile,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@ -7,19 +7,18 @@ import shutil
|
|||||||
import sys
|
import sys
|
||||||
from itertools import count
|
from itertools import count
|
||||||
from qt.core import (
|
from qt.core import (
|
||||||
QT_VERSION, QApplication, QByteArray, QEvent, QFontDatabase, QFontInfo,
|
QT_VERSION, QApplication, QByteArray, QEvent, QFontDatabase, QFontInfo, QHBoxLayout,
|
||||||
QHBoxLayout, QLocale, QMimeData, QPalette, QSize, Qt, QTimer, QUrl, QWidget,
|
QLocale, QMimeData, QPalette, QSize, Qt, QTimer, QUrl, QWidget, pyqtSignal, sip,
|
||||||
pyqtSignal, sip
|
|
||||||
)
|
)
|
||||||
from qt.webengine import (
|
from qt.webengine import (
|
||||||
QWebEnginePage, QWebEngineProfile, QWebEngineScript, QWebEngineSettings,
|
QWebEnginePage, QWebEngineProfile, QWebEngineScript, QWebEngineSettings,
|
||||||
QWebEngineUrlRequestJob, QWebEngineUrlSchemeHandler, QWebEngineView
|
QWebEngineUrlRequestJob, QWebEngineUrlSchemeHandler, QWebEngineView,
|
||||||
)
|
)
|
||||||
|
|
||||||
from calibre import as_unicode, prints
|
from calibre import as_unicode, prints
|
||||||
from calibre.constants import (
|
from calibre.constants import (
|
||||||
FAKE_HOST, FAKE_PROTOCOL, __version__, in_develop_mode, is_running_from_develop,
|
FAKE_HOST, FAKE_PROTOCOL, __version__, in_develop_mode, is_running_from_develop,
|
||||||
ismacos, iswindows
|
ismacos, iswindows,
|
||||||
)
|
)
|
||||||
from calibre.ebooks.metadata.book.base import field_metadata
|
from calibre.ebooks.metadata.book.base import field_metadata
|
||||||
from calibre.ebooks.oeb.polish.utils import guess_type
|
from calibre.ebooks.oeb.polish.utils import guess_type
|
||||||
@ -30,11 +29,12 @@ from calibre.gui2.viewer.tts import TTS
|
|||||||
from calibre.gui2.webengine import RestartingWebEngineView
|
from calibre.gui2.webengine import RestartingWebEngineView
|
||||||
from calibre.srv.code import get_translations_data
|
from calibre.srv.code import get_translations_data
|
||||||
from calibre.utils.localization import localize_user_manual_link
|
from calibre.utils.localization import localize_user_manual_link
|
||||||
|
from calibre.utils.resources import get_path as P
|
||||||
from calibre.utils.serialize import json_loads
|
from calibre.utils.serialize import json_loads
|
||||||
from calibre.utils.shared_file import share_open
|
from calibre.utils.shared_file import share_open
|
||||||
from calibre.utils.webengine import (
|
from calibre.utils.webengine import (
|
||||||
Bridge, create_script, from_js, insert_scripts, secure_webengine, send_reply,
|
Bridge, create_script, from_js, insert_scripts, secure_webengine, send_reply,
|
||||||
to_js, setup_profile
|
setup_profile, to_js,
|
||||||
)
|
)
|
||||||
from polyglot.builtins import as_bytes, iteritems
|
from polyglot.builtins import as_bytes, iteritems
|
||||||
from polyglot.functools import lru_cache
|
from polyglot.functools import lru_cache
|
||||||
|
@ -11,16 +11,14 @@ import time
|
|||||||
import unicodedata
|
import unicodedata
|
||||||
import zlib
|
import zlib
|
||||||
from copy import deepcopy
|
from copy import deepcopy
|
||||||
|
from lxml import etree
|
||||||
from xml.sax.saxutils import escape
|
from xml.sax.saxutils import escape
|
||||||
|
|
||||||
from lxml import etree
|
|
||||||
|
|
||||||
from calibre import (
|
from calibre import (
|
||||||
as_unicode, force_unicode, isbytestring, prepare_string_for_xml,
|
as_unicode, force_unicode, isbytestring, prepare_string_for_xml, replace_entities,
|
||||||
replace_entities, strftime, xml_replace_entities
|
strftime, xml_replace_entities,
|
||||||
)
|
)
|
||||||
from calibre.constants import cache_dir, ismacos
|
from calibre.constants import cache_dir, ismacos
|
||||||
from calibre.utils.xml_parse import safe_xml_fromstring
|
|
||||||
from calibre.customize.conversion import DummyReporter
|
from calibre.customize.conversion import DummyReporter
|
||||||
from calibre.customize.ui import output_profiles
|
from calibre.customize.ui import output_profiles
|
||||||
from calibre.ebooks.BeautifulSoup import BeautifulSoup, NavigableString, prettify
|
from calibre.ebooks.BeautifulSoup import BeautifulSoup, NavigableString, prettify
|
||||||
@ -29,17 +27,19 @@ from calibre.ebooks.metadata import author_to_author_sort
|
|||||||
from calibre.ebooks.oeb.polish.pretty import pretty_opf, pretty_xml_tree
|
from calibre.ebooks.oeb.polish.pretty import pretty_opf, pretty_xml_tree
|
||||||
from calibre.library.catalogs import (
|
from calibre.library.catalogs import (
|
||||||
AuthorSortMismatchException, EmptyCatalogException,
|
AuthorSortMismatchException, EmptyCatalogException,
|
||||||
InvalidGenresSourceFieldException
|
InvalidGenresSourceFieldException,
|
||||||
)
|
)
|
||||||
from calibre.library.comments import comments_to_html
|
from calibre.library.comments import comments_to_html
|
||||||
from calibre.ptempfile import PersistentTemporaryDirectory
|
from calibre.ptempfile import PersistentTemporaryDirectory
|
||||||
from calibre.utils.date import (
|
from calibre.utils.date import (
|
||||||
as_local_time, format_date, is_date_undefined, now as nowf
|
as_local_time, format_date, is_date_undefined, now as nowf,
|
||||||
)
|
)
|
||||||
from calibre.utils.filenames import ascii_text, shorten_components_to
|
from calibre.utils.filenames import ascii_text, shorten_components_to
|
||||||
from calibre.utils.formatter import TemplateFormatter
|
from calibre.utils.formatter import TemplateFormatter
|
||||||
from calibre.utils.icu import capitalize, collation_order, sort_key
|
from calibre.utils.icu import capitalize, collation_order, sort_key
|
||||||
from calibre.utils.localization import get_lang, lang_as_iso639_1
|
from calibre.utils.localization import get_lang, lang_as_iso639_1
|
||||||
|
from calibre.utils.resources import get_path as P
|
||||||
|
from calibre.utils.xml_parse import safe_xml_fromstring
|
||||||
from calibre.utils.zipfile import ZipFile
|
from calibre.utils.zipfile import ZipFile
|
||||||
from polyglot.builtins import iteritems
|
from polyglot.builtins import iteritems
|
||||||
|
|
||||||
@ -1096,8 +1096,8 @@ class CatalogBuilder:
|
|||||||
bookmarked_books (dict): dict of Bookmarks
|
bookmarked_books (dict): dict of Bookmarks
|
||||||
"""
|
"""
|
||||||
|
|
||||||
from calibre.devices.usbms.device import Device
|
|
||||||
from calibre.devices.kindle.bookmark import Bookmark
|
from calibre.devices.kindle.bookmark import Bookmark
|
||||||
|
from calibre.devices.usbms.device import Device
|
||||||
from calibre.ebooks.metadata import MetaInformation
|
from calibre.ebooks.metadata import MetaInformation
|
||||||
|
|
||||||
MBP_FORMATS = ['azw', 'mobi', 'prc', 'txt']
|
MBP_FORMATS = ['azw', 'mobi', 'prc', 'txt']
|
||||||
|
@ -6,47 +6,64 @@ __docformat__ = 'restructuredtext en'
|
|||||||
The database used to store ebook metadata
|
The database used to store ebook metadata
|
||||||
'''
|
'''
|
||||||
|
|
||||||
import os, sys, shutil, glob, time, functools, traceback, re, \
|
import copy
|
||||||
json, uuid, hashlib, copy, numbers
|
import functools
|
||||||
|
import glob
|
||||||
|
import hashlib
|
||||||
|
import json
|
||||||
|
import numbers
|
||||||
|
import os
|
||||||
|
import random
|
||||||
|
import re
|
||||||
|
import shutil
|
||||||
|
import sys
|
||||||
|
import threading
|
||||||
|
import time
|
||||||
|
import traceback
|
||||||
|
import uuid
|
||||||
from collections import defaultdict, namedtuple
|
from collections import defaultdict, namedtuple
|
||||||
import threading, random
|
|
||||||
|
|
||||||
from calibre import prints, force_unicode
|
from calibre import force_unicode, isbytestring, prints
|
||||||
from calibre.ebooks.metadata import (title_sort, author_to_author_sort,
|
from calibre.constants import filesystem_encoding, iswindows, preferred_encoding
|
||||||
string_to_authors, get_title_sort_pat)
|
from calibre.customize.ui import run_plugins_on_import, run_plugins_on_postimport
|
||||||
from calibre.ebooks.metadata.opf2 import metadata_to_opf
|
from calibre.db import (
|
||||||
from calibre.library.database import LibraryDatabase
|
_get_next_series_num_for_list, _get_series_values, get_data_as_dict,
|
||||||
from calibre.library.field_metadata import FieldMetadata
|
)
|
||||||
from calibre.library.schema_upgrades import SchemaUpgrade
|
from calibre.db.adding import (
|
||||||
from calibre.library.caches import ResultCache
|
find_books_in_directory, import_book_directory, import_book_directory_multiple,
|
||||||
from calibre.library.custom_columns import CustomColumns
|
recursive_import,
|
||||||
from calibre.library.sqlite import connect, IntegrityError
|
)
|
||||||
from calibre.library.prefs import DBPrefs
|
from calibre.db.categories import CATEGORY_SORTS, Tag
|
||||||
from calibre.ebooks.metadata.book.base import Metadata
|
|
||||||
from calibre.constants import preferred_encoding, iswindows, filesystem_encoding
|
|
||||||
from calibre.ptempfile import (PersistentTemporaryFile,
|
|
||||||
base_dir, SpooledTemporaryFile)
|
|
||||||
from calibre.customize.ui import (run_plugins_on_import,
|
|
||||||
run_plugins_on_postimport)
|
|
||||||
from calibre import isbytestring
|
|
||||||
from calibre.utils.filenames import (ascii_filename, samefile,
|
|
||||||
WindowsAtomicFolderMove, hardlink_file)
|
|
||||||
from calibre.utils.date import (utcnow, now as nowf, utcfromtimestamp,
|
|
||||||
parse_only_date, UNDEFINED_DATE, parse_date)
|
|
||||||
from calibre.utils.config import prefs, tweaks, from_json, to_json
|
|
||||||
from calibre.utils.icu import sort_key, strcmp, lower
|
|
||||||
from calibre.utils.search_query_parser import saved_searches, set_saved_searches
|
|
||||||
from calibre.ebooks import check_ebook_format
|
|
||||||
from calibre.utils.img import save_cover_data_to
|
|
||||||
from calibre.utils.recycle_bin import delete_file, delete_tree
|
|
||||||
from calibre.utils.formatter_functions import load_user_template_functions
|
|
||||||
from calibre.db import _get_next_series_num_for_list, _get_series_values, get_data_as_dict
|
|
||||||
from calibre.db.adding import find_books_in_directory, import_book_directory_multiple, import_book_directory, recursive_import
|
|
||||||
from calibre.db.errors import NoSuchFormat
|
from calibre.db.errors import NoSuchFormat
|
||||||
from calibre.db.lazy import FormatMetadata, FormatsList
|
from calibre.db.lazy import FormatMetadata, FormatsList
|
||||||
from calibre.db.categories import Tag, CATEGORY_SORTS
|
from calibre.ebooks import check_ebook_format
|
||||||
from calibre.utils.localization import (canonicalize_lang,
|
from calibre.ebooks.metadata import (
|
||||||
calibre_langcode_to_name)
|
author_to_author_sort, get_title_sort_pat, string_to_authors, title_sort,
|
||||||
|
)
|
||||||
|
from calibre.ebooks.metadata.book.base import Metadata
|
||||||
|
from calibre.ebooks.metadata.opf2 import metadata_to_opf
|
||||||
|
from calibre.library.caches import ResultCache
|
||||||
|
from calibre.library.custom_columns import CustomColumns
|
||||||
|
from calibre.library.database import LibraryDatabase
|
||||||
|
from calibre.library.field_metadata import FieldMetadata
|
||||||
|
from calibre.library.prefs import DBPrefs
|
||||||
|
from calibre.library.schema_upgrades import SchemaUpgrade
|
||||||
|
from calibre.library.sqlite import IntegrityError, connect
|
||||||
|
from calibre.ptempfile import PersistentTemporaryFile, SpooledTemporaryFile, base_dir
|
||||||
|
from calibre.utils.config import from_json, prefs, to_json, tweaks
|
||||||
|
from calibre.utils.date import (
|
||||||
|
UNDEFINED_DATE, now as nowf, parse_date, parse_only_date, utcfromtimestamp, utcnow,
|
||||||
|
)
|
||||||
|
from calibre.utils.filenames import (
|
||||||
|
WindowsAtomicFolderMove, ascii_filename, hardlink_file, samefile,
|
||||||
|
)
|
||||||
|
from calibre.utils.formatter_functions import load_user_template_functions
|
||||||
|
from calibre.utils.icu import lower, sort_key, strcmp
|
||||||
|
from calibre.utils.img import save_cover_data_to
|
||||||
|
from calibre.utils.localization import calibre_langcode_to_name, canonicalize_lang
|
||||||
|
from calibre.utils.recycle_bin import delete_file, delete_tree
|
||||||
|
from calibre.utils.resources import get_path as P
|
||||||
|
from calibre.utils.search_query_parser import saved_searches, set_saved_searches
|
||||||
from polyglot.builtins import iteritems, string_or_bytes
|
from polyglot.builtins import iteritems, string_or_bytes
|
||||||
|
|
||||||
copyfile = os.link if hasattr(os, 'link') else shutil.copyfile
|
copyfile = os.link if hasattr(os, 'link') else shutil.copyfile
|
||||||
|
@ -3,18 +3,21 @@
|
|||||||
|
|
||||||
''' Post installation script for linux '''
|
''' Post installation script for linux '''
|
||||||
|
|
||||||
import sys, os, textwrap, stat, errno
|
import errno
|
||||||
from subprocess import check_call, check_output
|
import os
|
||||||
|
import stat
|
||||||
|
import sys
|
||||||
|
import textwrap
|
||||||
from functools import partial
|
from functools import partial
|
||||||
|
from subprocess import check_call, check_output
|
||||||
|
|
||||||
from calibre import __appname__, prints, guess_type
|
from calibre import CurrentDir, __appname__, guess_type, prints
|
||||||
from calibre.constants import islinux, isbsd
|
from calibre.constants import isbsd, islinux
|
||||||
from calibre.customize.ui import all_input_formats
|
from calibre.customize.ui import all_input_formats
|
||||||
from calibre.ptempfile import TemporaryDirectory
|
from calibre.ptempfile import TemporaryDirectory
|
||||||
from calibre import CurrentDir
|
from calibre.utils.resources import get_path as P
|
||||||
from polyglot.builtins import iteritems
|
from polyglot.builtins import iteritems
|
||||||
|
|
||||||
|
|
||||||
entry_points = {
|
entry_points = {
|
||||||
'console_scripts': [
|
'console_scripts': [
|
||||||
'ebook-device = calibre.devices.cli:main',
|
'ebook-device = calibre.devices.cli:main',
|
||||||
@ -322,11 +325,11 @@ class ZshCompleter: # {{{
|
|||||||
self.commands[name] = txt
|
self.commands[name] = txt
|
||||||
|
|
||||||
def do_ebook_convert(self, f):
|
def do_ebook_convert(self, f):
|
||||||
from calibre.ebooks.conversion.plumber import supported_input_formats
|
|
||||||
from calibre.web.feeds.recipes.collection import get_builtin_recipe_titles
|
|
||||||
from calibre.customize.ui import available_output_formats
|
from calibre.customize.ui import available_output_formats
|
||||||
from calibre.ebooks.conversion.cli import create_option_parser, group_titles
|
from calibre.ebooks.conversion.cli import create_option_parser, group_titles
|
||||||
|
from calibre.ebooks.conversion.plumber import supported_input_formats
|
||||||
from calibre.utils.logging import DevNull
|
from calibre.utils.logging import DevNull
|
||||||
|
from calibre.web.feeds.recipes.collection import get_builtin_recipe_titles
|
||||||
input_fmts = set(supported_input_formats())
|
input_fmts = set(supported_input_formats())
|
||||||
output_fmts = set(available_output_formats())
|
output_fmts = set(available_output_formats())
|
||||||
iexts = {x.upper() for x in input_fmts}.union(input_fmts)
|
iexts = {x.upper() for x in input_fmts}.union(input_fmts)
|
||||||
@ -417,8 +420,8 @@ class ZshCompleter: # {{{
|
|||||||
w('\n}\n')
|
w('\n}\n')
|
||||||
|
|
||||||
def do_ebook_edit(self, f):
|
def do_ebook_edit(self, f):
|
||||||
from calibre.ebooks.oeb.polish.main import SUPPORTED
|
|
||||||
from calibre.ebooks.oeb.polish.import_book import IMPORTABLE
|
from calibre.ebooks.oeb.polish.import_book import IMPORTABLE
|
||||||
|
from calibre.ebooks.oeb.polish.main import SUPPORTED
|
||||||
from calibre.gui2.tweak_book.main import option_parser
|
from calibre.gui2.tweak_book.main import option_parser
|
||||||
tweakable_fmts = SUPPORTED | IMPORTABLE
|
tweakable_fmts = SUPPORTED | IMPORTABLE
|
||||||
parser = option_parser()
|
parser = option_parser()
|
||||||
@ -468,8 +471,8 @@ _ebook_edit() {{
|
|||||||
'''.format(opt_lines, '|'.join(tweakable_fmts)) + '\n\n')
|
'''.format(opt_lines, '|'.join(tweakable_fmts)) + '\n\n')
|
||||||
|
|
||||||
def do_calibredb(self, f):
|
def do_calibredb(self, f):
|
||||||
from calibre.db.cli.main import COMMANDS, option_parser_for
|
|
||||||
from calibre.customize.ui import available_catalog_formats
|
from calibre.customize.ui import available_catalog_formats
|
||||||
|
from calibre.db.cli.main import COMMANDS, option_parser_for
|
||||||
parsers, descs = {}, {}
|
parsers, descs = {}, {}
|
||||||
for command in COMMANDS:
|
for command in COMMANDS:
|
||||||
p = option_parser_for(command)()
|
p = option_parser_for(command)()
|
||||||
@ -568,20 +571,22 @@ def get_bash_completion_path(root, share, info):
|
|||||||
|
|
||||||
|
|
||||||
def write_completion(self, bash_comp_dest, zsh):
|
def write_completion(self, bash_comp_dest, zsh):
|
||||||
from calibre.ebooks.metadata.cli import option_parser as metaop, filetypes as meta_filetypes
|
from calibre.customize.ui import available_input_formats
|
||||||
from calibre.ebooks.lrf.lrfparser import option_parser as lrf2lrsop
|
|
||||||
from calibre.gui2.lrf_renderer.main import option_parser as lrfviewerop
|
|
||||||
from calibre.gui2.viewer.main import option_parser as viewer_op
|
|
||||||
from calibre.gui2.tweak_book.main import option_parser as tweak_op
|
|
||||||
from calibre.ebooks.metadata.sources.cli import option_parser as fem_op
|
|
||||||
from calibre.gui2.main import option_parser as guiop
|
|
||||||
from calibre.utils.smtp import option_parser as smtp_op
|
|
||||||
from calibre.srv.standalone import create_option_parser as serv_op
|
|
||||||
from calibre.ebooks.oeb.polish.main import option_parser as polish_op, SUPPORTED
|
|
||||||
from calibre.ebooks.oeb.polish.import_book import IMPORTABLE
|
|
||||||
from calibre.debug import option_parser as debug_op
|
from calibre.debug import option_parser as debug_op
|
||||||
from calibre.ebooks import BOOK_EXTENSIONS
|
from calibre.ebooks import BOOK_EXTENSIONS
|
||||||
from calibre.customize.ui import available_input_formats
|
from calibre.ebooks.lrf.lrfparser import option_parser as lrf2lrsop
|
||||||
|
from calibre.ebooks.metadata.cli import (
|
||||||
|
filetypes as meta_filetypes, option_parser as metaop,
|
||||||
|
)
|
||||||
|
from calibre.ebooks.metadata.sources.cli import option_parser as fem_op
|
||||||
|
from calibre.ebooks.oeb.polish.import_book import IMPORTABLE
|
||||||
|
from calibre.ebooks.oeb.polish.main import SUPPORTED, option_parser as polish_op
|
||||||
|
from calibre.gui2.lrf_renderer.main import option_parser as lrfviewerop
|
||||||
|
from calibre.gui2.main import option_parser as guiop
|
||||||
|
from calibre.gui2.tweak_book.main import option_parser as tweak_op
|
||||||
|
from calibre.gui2.viewer.main import option_parser as viewer_op
|
||||||
|
from calibre.srv.standalone import create_option_parser as serv_op
|
||||||
|
from calibre.utils.smtp import option_parser as smtp_op
|
||||||
input_formats = sorted(all_input_formats())
|
input_formats = sorted(all_input_formats())
|
||||||
tweak_formats = sorted(x.lower() for x in SUPPORTED|IMPORTABLE)
|
tweak_formats = sorted(x.lower() for x in SUPPORTED|IMPORTABLE)
|
||||||
|
|
||||||
@ -917,8 +922,8 @@ class PostInstall:
|
|||||||
line += extra + ';'
|
line += extra + ';'
|
||||||
f.write(line.encode('utf-8') + b'\n')
|
f.write(line.encode('utf-8') + b'\n')
|
||||||
|
|
||||||
from calibre.ebooks.oeb.polish.main import SUPPORTED
|
|
||||||
from calibre.ebooks.oeb.polish.import_book import IMPORTABLE
|
from calibre.ebooks.oeb.polish.import_book import IMPORTABLE
|
||||||
|
from calibre.ebooks.oeb.polish.main import SUPPORTED
|
||||||
with open('calibre-lrfviewer.desktop', 'wb') as f:
|
with open('calibre-lrfviewer.desktop', 'wb') as f:
|
||||||
f.write(VIEWER.encode('utf-8'))
|
f.write(VIEWER.encode('utf-8'))
|
||||||
with open('calibre-ebook-viewer.desktop', 'wb') as f:
|
with open('calibre-ebook-viewer.desktop', 'wb') as f:
|
||||||
@ -1208,8 +1213,8 @@ def changelog_bullet_to_text(bullet):
|
|||||||
|
|
||||||
|
|
||||||
def make_appdata_releases():
|
def make_appdata_releases():
|
||||||
from lxml.builder import E
|
|
||||||
import json
|
import json
|
||||||
|
from lxml.builder import E
|
||||||
changelog = json.loads(P('changelog.json', data=True))
|
changelog = json.loads(P('changelog.json', data=True))
|
||||||
|
|
||||||
releases = E.releases()
|
releases = E.releases()
|
||||||
@ -1247,8 +1252,8 @@ def make_appdata_releases():
|
|||||||
|
|
||||||
|
|
||||||
def write_appdata(key, entry, base, translators):
|
def write_appdata(key, entry, base, translators):
|
||||||
from lxml.etree import tostring
|
|
||||||
from lxml.builder import E
|
from lxml.builder import E
|
||||||
|
from lxml.etree import tostring
|
||||||
fpath = os.path.join(base, '%s.metainfo.xml' % key)
|
fpath = os.path.join(base, '%s.metainfo.xml' % key)
|
||||||
screenshots = E.screenshots()
|
screenshots = E.screenshots()
|
||||||
for w, h, url in entry['screenshots']:
|
for w, h, url in entry['screenshots']:
|
||||||
|
@ -13,6 +13,7 @@ from calibre.constants import iswindows
|
|||||||
from calibre.ptempfile import PersistentTemporaryFile
|
from calibre.ptempfile import PersistentTemporaryFile
|
||||||
from calibre.utils.filenames import retry_on_fail
|
from calibre.utils.filenames import retry_on_fail
|
||||||
from calibre.utils.ipc.simple_worker import start_pipe_worker
|
from calibre.utils.ipc.simple_worker import start_pipe_worker
|
||||||
|
from calibre.utils.resources import get_path as P
|
||||||
|
|
||||||
|
|
||||||
def worker_main(source):
|
def worker_main(source):
|
||||||
|
@ -10,6 +10,7 @@ from functools import lru_cache
|
|||||||
from qt.core import QApplication, QEventLoop, QUrl
|
from qt.core import QApplication, QEventLoop, QUrl
|
||||||
from qt.webengine import QWebEnginePage, QWebEngineProfile, QWebEngineSettings
|
from qt.webengine import QWebEnginePage, QWebEngineProfile, QWebEngineSettings
|
||||||
|
|
||||||
|
from calibre.utils.resources import get_path as P
|
||||||
from calibre.utils.webengine import create_script, insert_scripts, setup_profile
|
from calibre.utils.webengine import create_script, insert_scripts, setup_profile
|
||||||
|
|
||||||
|
|
||||||
|
@ -7,6 +7,7 @@ __copyright__ = '2014, Kovid Goyal <kovid at kovidgoyal.net>'
|
|||||||
from collections import namedtuple
|
from collections import namedtuple
|
||||||
|
|
||||||
from calibre.utils.localization import canonicalize_lang
|
from calibre.utils.localization import canonicalize_lang
|
||||||
|
from calibre.utils.resources import get_path as P
|
||||||
|
|
||||||
DictionaryLocale = namedtuple('DictionaryLocale', 'langcode countrycode')
|
DictionaryLocale = namedtuple('DictionaryLocale', 'langcode countrycode')
|
||||||
|
|
||||||
|
@ -17,6 +17,7 @@ from calibre.spell import parse_lang_code
|
|||||||
from calibre.utils.config import JSONConfig
|
from calibre.utils.config import JSONConfig
|
||||||
from calibre.utils.icu import capitalize
|
from calibre.utils.icu import capitalize
|
||||||
from calibre.utils.localization import get_lang, get_system_locale
|
from calibre.utils.localization import get_lang, get_system_locale
|
||||||
|
from calibre.utils.resources import get_path as P
|
||||||
from polyglot.builtins import iteritems, itervalues
|
from polyglot.builtins import iteritems, itervalues
|
||||||
|
|
||||||
Dictionary = namedtuple('Dictionary', 'primary_locale locales dicpath affpath builtin name id')
|
Dictionary = namedtuple('Dictionary', 'primary_locale locales dicpath affpath builtin name id')
|
||||||
|
@ -11,6 +11,7 @@ from lxml import etree
|
|||||||
from calibre.constants import config_dir
|
from calibre.constants import config_dir
|
||||||
from calibre.utils.xml_parse import safe_xml_fromstring
|
from calibre.utils.xml_parse import safe_xml_fromstring
|
||||||
from calibre.utils.zipfile import ZipFile
|
from calibre.utils.zipfile import ZipFile
|
||||||
|
from calibre.utils.resources import get_path as P
|
||||||
from polyglot.builtins import iteritems
|
from polyglot.builtins import iteritems
|
||||||
|
|
||||||
NS_MAP = {
|
NS_MAP = {
|
||||||
@ -19,8 +20,11 @@ NS_MAP = {
|
|||||||
'manifest': 'http://openoffice.org/2001/manifest',
|
'manifest': 'http://openoffice.org/2001/manifest',
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
def XPath(x):
|
def XPath(x):
|
||||||
return etree.XPath(x, namespaces=NS_MAP)
|
return etree.XPath(x, namespaces=NS_MAP)
|
||||||
|
|
||||||
|
|
||||||
BUILTIN_LOCALES = {'en-US', 'en-GB', 'es-ES'}
|
BUILTIN_LOCALES = {'en-US', 'en-GB', 'es-ES'}
|
||||||
|
|
||||||
|
|
||||||
|
@ -21,6 +21,7 @@ from calibre.srv.render_book import RENDER_VERSION
|
|||||||
from calibre.srv.routes import endpoint, json
|
from calibre.srv.routes import endpoint, json
|
||||||
from calibre.srv.utils import get_db, get_library_data
|
from calibre.srv.utils import get_db, get_library_data
|
||||||
from calibre.utils.filenames import rmtree
|
from calibre.utils.filenames import rmtree
|
||||||
|
from calibre.utils.resources import get_path as P
|
||||||
from calibre.utils.serialize import json_dumps
|
from calibre.utils.serialize import json_dumps
|
||||||
from polyglot.builtins import as_unicode, itervalues
|
from polyglot.builtins import as_unicode, itervalues
|
||||||
|
|
||||||
|
@ -29,6 +29,7 @@ from calibre.utils.icu import numeric_sort_key, sort_key
|
|||||||
from calibre.utils.localization import (
|
from calibre.utils.localization import (
|
||||||
get_lang, lang_code_for_user_manual, lang_map_for_ui, localize_website_link,
|
get_lang, lang_code_for_user_manual, lang_map_for_ui, localize_website_link,
|
||||||
)
|
)
|
||||||
|
from calibre.utils.resources import get_path as P
|
||||||
from calibre.utils.search_query_parser import ParseException
|
from calibre.utils.search_query_parser import ParseException
|
||||||
from calibre.utils.serialize import json_dumps
|
from calibre.utils.serialize import json_dumps
|
||||||
from polyglot.builtins import iteritems, itervalues
|
from polyglot.builtins import iteritems, itervalues
|
||||||
|
@ -4,30 +4,34 @@
|
|||||||
__license__ = 'GPL v3'
|
__license__ = 'GPL v3'
|
||||||
__copyright__ = '2015, Kovid Goyal <kovid at kovidgoyal.net>'
|
__copyright__ = '2015, Kovid Goyal <kovid at kovidgoyal.net>'
|
||||||
|
|
||||||
import os, errno
|
import errno
|
||||||
from io import BytesIO
|
import os
|
||||||
from threading import Lock
|
|
||||||
from contextlib import suppress
|
from contextlib import suppress
|
||||||
from functools import partial
|
from functools import partial
|
||||||
|
from io import BytesIO
|
||||||
|
from threading import Lock
|
||||||
|
|
||||||
from calibre import fit_image, sanitize_file_name
|
from calibre import fit_image, sanitize_file_name
|
||||||
from calibre.constants import config_dir, iswindows
|
from calibre.constants import config_dir, iswindows
|
||||||
from calibre.db.errors import NoSuchFormat
|
from calibre.db.errors import NoSuchFormat
|
||||||
from calibre.ebooks.covers import cprefs, override_prefs, scale_cover, generate_cover, set_use_roman
|
from calibre.ebooks.covers import (
|
||||||
|
cprefs, generate_cover, override_prefs, scale_cover, set_use_roman,
|
||||||
|
)
|
||||||
from calibre.ebooks.metadata import authors_to_string
|
from calibre.ebooks.metadata import authors_to_string
|
||||||
from calibre.ebooks.metadata.meta import set_metadata
|
from calibre.ebooks.metadata.meta import set_metadata
|
||||||
from calibre.ebooks.metadata.opf2 import metadata_to_opf
|
from calibre.ebooks.metadata.opf2 import metadata_to_opf
|
||||||
from calibre.library.save_to_disk import find_plugboard
|
from calibre.library.save_to_disk import find_plugboard
|
||||||
from calibre.srv.errors import HTTPNotFound, BookNotFound
|
from calibre.srv.errors import BookNotFound, HTTPNotFound
|
||||||
from calibre.srv.routes import endpoint, json
|
from calibre.srv.routes import endpoint, json
|
||||||
from calibre.srv.utils import http_date, get_db, get_use_roman
|
from calibre.srv.utils import get_db, get_use_roman, http_date
|
||||||
from calibre.utils.config_base import tweaks
|
from calibre.utils.config_base import tweaks
|
||||||
from calibre.utils.date import timestampfromdt
|
from calibre.utils.date import timestampfromdt
|
||||||
from calibre.utils.img import scale_image, image_from_data
|
|
||||||
from calibre.utils.filenames import ascii_filename, atomic_rename
|
from calibre.utils.filenames import ascii_filename, atomic_rename
|
||||||
|
from calibre.utils.img import image_from_data, scale_image
|
||||||
|
from calibre.utils.resources import get_path as P
|
||||||
from calibre.utils.shared_file import share_open
|
from calibre.utils.shared_file import share_open
|
||||||
from polyglot.urllib import quote
|
|
||||||
from polyglot.binary import as_hex_unicode
|
from polyglot.binary import as_hex_unicode
|
||||||
|
from polyglot.urllib import quote
|
||||||
|
|
||||||
plugboard_content_server_value = 'content_server'
|
plugboard_content_server_value = 'content_server'
|
||||||
plugboard_content_server_formats = ['epub', 'mobi', 'azw3']
|
plugboard_content_server_formats = ['epub', 'mobi', 'azw3']
|
||||||
|
@ -5,12 +5,19 @@ __license__ = 'GPL v3'
|
|||||||
__copyright__ = '2011, Kovid Goyal <kovid@kovidgoyal.net>'
|
__copyright__ = '2011, Kovid Goyal <kovid@kovidgoyal.net>'
|
||||||
__docformat__ = 'restructuredtext en'
|
__docformat__ = 'restructuredtext en'
|
||||||
|
|
||||||
import unittest, time, shutil, gc, tempfile, atexit, os
|
import atexit
|
||||||
from io import BytesIO
|
import gc
|
||||||
|
import os
|
||||||
|
import shutil
|
||||||
|
import tempfile
|
||||||
|
import time
|
||||||
|
import unittest
|
||||||
from functools import partial
|
from functools import partial
|
||||||
|
from io import BytesIO
|
||||||
from threading import Thread
|
from threading import Thread
|
||||||
|
|
||||||
from calibre.srv.utils import ServerLog
|
from calibre.srv.utils import ServerLog
|
||||||
|
from calibre.utils.resources import get_path as P
|
||||||
from polyglot import http_client
|
from polyglot import http_client
|
||||||
|
|
||||||
rmtree = partial(shutil.rmtree, ignore_errors=True)
|
rmtree = partial(shutil.rmtree, ignore_errors=True)
|
||||||
@ -70,8 +77,8 @@ class LibraryBaseTest(BaseTest):
|
|||||||
return ans
|
return ans
|
||||||
|
|
||||||
def create_db(self, library_path):
|
def create_db(self, library_path):
|
||||||
from calibre.db.legacy import create_backend
|
|
||||||
from calibre.db.cache import Cache
|
from calibre.db.cache import Cache
|
||||||
|
from calibre.db.legacy import create_backend
|
||||||
d = os.path.dirname
|
d = os.path.dirname
|
||||||
src = os.path.join(d(d(d(os.path.abspath(__file__)))), 'db', 'tests', 'metadata.db')
|
src = os.path.join(d(d(d(os.path.abspath(__file__)))), 'db', 'tests', 'metadata.db')
|
||||||
dest = os.path.join(library_path, 'metadata.db')
|
dest = os.path.join(library_path, 'metadata.db')
|
||||||
@ -98,9 +105,9 @@ class TestServer(Thread):
|
|||||||
|
|
||||||
def __init__(self, handler, plugins=(), **kwargs):
|
def __init__(self, handler, plugins=(), **kwargs):
|
||||||
Thread.__init__(self, name='ServerMain')
|
Thread.__init__(self, name='ServerMain')
|
||||||
from calibre.srv.opts import Options
|
|
||||||
from calibre.srv.loop import ServerLoop
|
|
||||||
from calibre.srv.http_response import create_http_handler
|
from calibre.srv.http_response import create_http_handler
|
||||||
|
from calibre.srv.loop import ServerLoop
|
||||||
|
from calibre.srv.opts import Options
|
||||||
self.setup_defaults(kwargs)
|
self.setup_defaults(kwargs)
|
||||||
self.loop = ServerLoop(
|
self.loop = ServerLoop(
|
||||||
create_http_handler(handler),
|
create_http_handler(handler),
|
||||||
@ -155,10 +162,10 @@ class LibraryServer(TestServer):
|
|||||||
|
|
||||||
def __init__(self, library_path, libraries=(), plugins=(), **kwargs):
|
def __init__(self, library_path, libraries=(), plugins=(), **kwargs):
|
||||||
Thread.__init__(self, name='ServerMain')
|
Thread.__init__(self, name='ServerMain')
|
||||||
from calibre.srv.opts import Options
|
|
||||||
from calibre.srv.loop import ServerLoop
|
|
||||||
from calibre.srv.handler import Handler
|
from calibre.srv.handler import Handler
|
||||||
from calibre.srv.http_response import create_http_handler
|
from calibre.srv.http_response import create_http_handler
|
||||||
|
from calibre.srv.loop import ServerLoop
|
||||||
|
from calibre.srv.opts import Options
|
||||||
self.setup_defaults(kwargs)
|
self.setup_defaults(kwargs)
|
||||||
opts = Options(**kwargs)
|
opts = Options(**kwargs)
|
||||||
self.libraries = libraries or (library_path,)
|
self.libraries = libraries or (library_path,)
|
||||||
|
@ -4,13 +4,17 @@
|
|||||||
__license__ = 'GPL v3'
|
__license__ = 'GPL v3'
|
||||||
__copyright__ = '2015, Kovid Goyal <kovid at kovidgoyal.net>'
|
__copyright__ = '2015, Kovid Goyal <kovid at kovidgoyal.net>'
|
||||||
|
|
||||||
import zlib, json, time, os
|
import json
|
||||||
|
import os
|
||||||
|
import time
|
||||||
|
import zlib
|
||||||
from io import BytesIO
|
from io import BytesIO
|
||||||
|
|
||||||
from calibre.ebooks.metadata.epub import get_metadata
|
from calibre.ebooks.metadata.epub import get_metadata
|
||||||
from calibre.ebooks.metadata.opf2 import OPF
|
from calibre.ebooks.metadata.opf2 import OPF
|
||||||
from calibre.srv.tests.base import LibraryBaseTest
|
from calibre.srv.tests.base import LibraryBaseTest
|
||||||
from calibre.utils.imghdr import identify
|
from calibre.utils.imghdr import identify
|
||||||
|
from calibre.utils.resources import get_path as P
|
||||||
from calibre.utils.shared_file import share_open
|
from calibre.utils.shared_file import share_open
|
||||||
from polyglot import http_client
|
from polyglot import http_client
|
||||||
from polyglot.binary import from_hex_unicode
|
from polyglot.binary import from_hex_unicode
|
||||||
@ -226,8 +230,8 @@ class ContentTest(LibraryBaseTest):
|
|||||||
# }}}
|
# }}}
|
||||||
|
|
||||||
def test_char_count(self): # {{{
|
def test_char_count(self): # {{{
|
||||||
from calibre.srv.render_book import get_length
|
|
||||||
from calibre.ebooks.oeb.parse_utils import html5_parse
|
from calibre.ebooks.oeb.parse_utils import html5_parse
|
||||||
|
from calibre.srv.render_book import get_length
|
||||||
|
|
||||||
root = html5_parse('<p>a b\nc\td\re')
|
root = html5_parse('<p>a b\nc\td\re')
|
||||||
self.ae(get_length(root), 5)
|
self.ae(get_length(root), 5)
|
||||||
@ -238,8 +242,8 @@ class ContentTest(LibraryBaseTest):
|
|||||||
# }}}
|
# }}}
|
||||||
|
|
||||||
def test_html_as_json(self): # {{{
|
def test_html_as_json(self): # {{{
|
||||||
from calibre.srv.render_book import html_as_json
|
|
||||||
from calibre.ebooks.oeb.parse_utils import html5_parse
|
from calibre.ebooks.oeb.parse_utils import html5_parse
|
||||||
|
from calibre.srv.render_book import html_as_json
|
||||||
|
|
||||||
def t(html, body_children, nsmap=('http://www.w3.org/1999/xhtml',)):
|
def t(html, body_children, nsmap=('http://www.w3.org/1999/xhtml',)):
|
||||||
root = html5_parse(html)
|
root = html5_parse(html)
|
||||||
|
@ -4,7 +4,11 @@
|
|||||||
__license__ = 'GPL v3'
|
__license__ = 'GPL v3'
|
||||||
__copyright__ = '2015, Kovid Goyal <kovid at kovidgoyal.net>'
|
__copyright__ = '2015, Kovid Goyal <kovid at kovidgoyal.net>'
|
||||||
|
|
||||||
import hashlib, zlib, string, time, os
|
import hashlib
|
||||||
|
import os
|
||||||
|
import string
|
||||||
|
import time
|
||||||
|
import zlib
|
||||||
from io import BytesIO
|
from io import BytesIO
|
||||||
from tempfile import NamedTemporaryFile
|
from tempfile import NamedTemporaryFile
|
||||||
|
|
||||||
@ -12,8 +16,9 @@ from calibre import guess_type
|
|||||||
from calibre.srv.tests.base import BaseTest, TestServer
|
from calibre.srv.tests.base import BaseTest, TestServer
|
||||||
from calibre.srv.utils import eintr_retry_call
|
from calibre.srv.utils import eintr_retry_call
|
||||||
from calibre.utils.monotonic import monotonic
|
from calibre.utils.monotonic import monotonic
|
||||||
from polyglot.builtins import iteritems
|
from calibre.utils.resources import get_path as P
|
||||||
from polyglot import http_client
|
from polyglot import http_client
|
||||||
|
from polyglot.builtins import iteritems
|
||||||
|
|
||||||
is_ci = os.environ.get('CI', '').lower() == 'true'
|
is_ci = os.environ.get('CI', '').lower() == 'true'
|
||||||
|
|
||||||
|
@ -18,6 +18,7 @@ import time
|
|||||||
import unittest
|
import unittest
|
||||||
|
|
||||||
from calibre.constants import islinux, ismacos, iswindows, plugins_loc
|
from calibre.constants import islinux, ismacos, iswindows, plugins_loc
|
||||||
|
from calibre.utils.resources import get_path as P
|
||||||
from polyglot.builtins import iteritems
|
from polyglot.builtins import iteritems
|
||||||
|
|
||||||
is_ci = os.environ.get('CI', '').lower() == 'true'
|
is_ci = os.environ.get('CI', '').lower() == 'true'
|
||||||
@ -304,7 +305,8 @@ class BuildTest(unittest.TestCase):
|
|||||||
if is_sanitized:
|
if is_sanitized:
|
||||||
raise unittest.SkipTest('Skipping Qt build test as sanitizer is enabled')
|
raise unittest.SkipTest('Skipping Qt build test as sanitizer is enabled')
|
||||||
from qt.core import (
|
from qt.core import (
|
||||||
QApplication, QFontDatabase, QImageReader, QNetworkAccessManager, QTimer, QSslSocket
|
QApplication, QFontDatabase, QImageReader, QNetworkAccessManager,
|
||||||
|
QSslSocket, QTimer,
|
||||||
)
|
)
|
||||||
from qt.webengine import QWebEnginePage
|
from qt.webengine import QWebEnginePage
|
||||||
|
|
||||||
|
@ -15,8 +15,9 @@ from functools import partial
|
|||||||
|
|
||||||
from calibre.constants import (
|
from calibre.constants import (
|
||||||
CONFIG_DIR_MODE, config_dir, filesystem_encoding, get_umask, iswindows,
|
CONFIG_DIR_MODE, config_dir, filesystem_encoding, get_umask, iswindows,
|
||||||
preferred_encoding
|
preferred_encoding,
|
||||||
)
|
)
|
||||||
|
from calibre.utils.resources import get_path as P
|
||||||
from polyglot.builtins import iteritems
|
from polyglot.builtins import iteritems
|
||||||
|
|
||||||
plugin_dir = os.path.join(config_dir, 'plugins')
|
plugin_dir = os.path.join(config_dir, 'plugins')
|
||||||
|
@ -9,11 +9,13 @@ import os
|
|||||||
from collections import defaultdict
|
from collections import defaultdict
|
||||||
from threading import Thread
|
from threading import Thread
|
||||||
|
|
||||||
from calibre import walk, prints, as_unicode
|
from calibre import as_unicode, prints, walk
|
||||||
from calibre.constants import (config_dir, iswindows, ismacos, DEBUG,
|
from calibre.constants import (
|
||||||
isworker, filesystem_encoding)
|
DEBUG, config_dir, filesystem_encoding, ismacos, iswindows, isworker,
|
||||||
|
)
|
||||||
from calibre.utils.fonts.metadata import FontMetadata, UnsupportedFont
|
from calibre.utils.fonts.metadata import FontMetadata, UnsupportedFont
|
||||||
from calibre.utils.icu import sort_key
|
from calibre.utils.icu import sort_key
|
||||||
|
from calibre.utils.resources import get_path as P
|
||||||
from polyglot.builtins import itervalues
|
from polyglot.builtins import itervalues
|
||||||
|
|
||||||
|
|
||||||
@ -267,8 +269,9 @@ class FontScanner(Thread):
|
|||||||
|
|
||||||
:return: (family name, faces) or None, None
|
:return: (family name, faces) or None, None
|
||||||
'''
|
'''
|
||||||
from calibre.utils.fonts.utils import (supports_text,
|
from calibre.utils.fonts.utils import (
|
||||||
panose_to_css_generic_family, get_printable_characters)
|
get_printable_characters, panose_to_css_generic_family, supports_text,
|
||||||
|
)
|
||||||
if not isinstance(text, str):
|
if not isinstance(text, str):
|
||||||
raise TypeError('%r is not unicode'%text)
|
raise TypeError('%r is not unicode'%text)
|
||||||
text = get_printable_characters(text)
|
text = get_printable_characters(text)
|
||||||
|
@ -13,12 +13,13 @@ from calibre.utils.fonts.sfnt.errors import UnsupportedFont
|
|||||||
from calibre.utils.fonts.sfnt.glyf import GlyfTable
|
from calibre.utils.fonts.sfnt.glyf import GlyfTable
|
||||||
from calibre.utils.fonts.sfnt.gsub import GSUBTable
|
from calibre.utils.fonts.sfnt.gsub import GSUBTable
|
||||||
from calibre.utils.fonts.sfnt.head import (
|
from calibre.utils.fonts.sfnt.head import (
|
||||||
HeadTable, HorizontalHeader, OS2Table, PostTable, VerticalHeader
|
HeadTable, HorizontalHeader, OS2Table, PostTable, VerticalHeader,
|
||||||
)
|
)
|
||||||
from calibre.utils.fonts.sfnt.kern import KernTable
|
from calibre.utils.fonts.sfnt.kern import KernTable
|
||||||
from calibre.utils.fonts.sfnt.loca import LocaTable
|
from calibre.utils.fonts.sfnt.loca import LocaTable
|
||||||
from calibre.utils.fonts.sfnt.maxp import MaxpTable
|
from calibre.utils.fonts.sfnt.maxp import MaxpTable
|
||||||
from calibre.utils.fonts.utils import checksum_of_block, get_tables, verify_checksums
|
from calibre.utils.fonts.utils import checksum_of_block, get_tables, verify_checksums
|
||||||
|
from calibre.utils.resources import get_path as P
|
||||||
|
|
||||||
# OpenType spec: http://www.microsoft.com/typography/otspec/otff.htm
|
# OpenType spec: http://www.microsoft.com/typography/otspec/otff.htm
|
||||||
|
|
||||||
@ -105,7 +106,7 @@ class Sfnt:
|
|||||||
return ans
|
return ans
|
||||||
|
|
||||||
def get_all_font_names(self):
|
def get_all_font_names(self):
|
||||||
from calibre.utils.fonts.metadata import get_font_names2, FontNames
|
from calibre.utils.fonts.metadata import FontNames, get_font_names2
|
||||||
name_table = self.get(b'name')
|
name_table = self.get(b'name')
|
||||||
if name_table is not None:
|
if name_table is not None:
|
||||||
return FontNames(*get_font_names2(name_table.raw, raw_is_table=True))
|
return FontNames(*get_font_names2(name_table.raw, raw_is_table=True))
|
||||||
|
@ -7,12 +7,13 @@ __docformat__ = 'restructuredtext en'
|
|||||||
|
|
||||||
import traceback
|
import traceback
|
||||||
from collections import OrderedDict
|
from collections import OrderedDict
|
||||||
from operator import itemgetter
|
|
||||||
from functools import partial
|
from functools import partial
|
||||||
|
from operator import itemgetter
|
||||||
|
|
||||||
from calibre.utils.icu import safe_chr, ord_string
|
|
||||||
from calibre.utils.fonts.sfnt.container import Sfnt
|
from calibre.utils.fonts.sfnt.container import Sfnt
|
||||||
from calibre.utils.fonts.sfnt.errors import UnsupportedFont, NoGlyphs
|
from calibre.utils.fonts.sfnt.errors import NoGlyphs, UnsupportedFont
|
||||||
|
from calibre.utils.icu import ord_string, safe_chr
|
||||||
|
from calibre.utils.resources import get_path as P
|
||||||
from polyglot.builtins import iteritems, itervalues
|
from polyglot.builtins import iteritems, itervalues
|
||||||
|
|
||||||
# TrueType outlines {{{
|
# TrueType outlines {{{
|
||||||
@ -197,6 +198,7 @@ def subset(raw, individual_chars, ranges=(), warnings=None):
|
|||||||
|
|
||||||
def option_parser():
|
def option_parser():
|
||||||
import textwrap
|
import textwrap
|
||||||
|
|
||||||
from calibre.utils.config import OptionParser
|
from calibre.utils.config import OptionParser
|
||||||
parser = OptionParser(usage=textwrap.dedent('''\
|
parser = OptionParser(usage=textwrap.dedent('''\
|
||||||
%prog [options] input_font_file output_font_file characters_to_keep
|
%prog [options] input_font_file output_font_file characters_to_keep
|
||||||
@ -239,7 +241,9 @@ def print_stats(old_stats, new_stats):
|
|||||||
|
|
||||||
|
|
||||||
def main(args):
|
def main(args):
|
||||||
import sys, time
|
import sys
|
||||||
|
import time
|
||||||
|
|
||||||
from calibre import prints
|
from calibre import prints
|
||||||
parser = option_parser()
|
parser = option_parser()
|
||||||
opts, args = parser.parse_args(args)
|
opts, args = parser.parse_args(args)
|
||||||
@ -308,8 +312,9 @@ if __name__ == '__main__':
|
|||||||
|
|
||||||
|
|
||||||
def test_mem():
|
def test_mem():
|
||||||
from calibre.utils.mem import memory
|
|
||||||
import gc
|
import gc
|
||||||
|
|
||||||
|
from calibre.utils.mem import memory
|
||||||
gc.collect()
|
gc.collect()
|
||||||
start_mem = memory()
|
start_mem = memory()
|
||||||
raw = P('fonts/liberation/LiberationSerif-Regular.ttf', data=True)
|
raw = P('fonts/liberation/LiberationSerif-Regular.ttf', data=True)
|
||||||
|
@ -6,10 +6,11 @@ __copyright__ = '2012, Kovid Goyal <kovid at kovidgoyal.net>'
|
|||||||
__docformat__ = 'restructuredtext en'
|
__docformat__ = 'restructuredtext en'
|
||||||
|
|
||||||
import struct
|
import struct
|
||||||
from io import BytesIO
|
|
||||||
from collections import defaultdict
|
from collections import defaultdict
|
||||||
|
from io import BytesIO
|
||||||
|
|
||||||
from polyglot.builtins import iteritems, itervalues, as_bytes
|
from calibre.utils.resources import get_path as P
|
||||||
|
from polyglot.builtins import as_bytes, iteritems, itervalues
|
||||||
|
|
||||||
|
|
||||||
class UnsupportedFont(ValueError):
|
class UnsupportedFont(ValueError):
|
||||||
@ -484,7 +485,8 @@ def test():
|
|||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
import sys, os
|
import os
|
||||||
|
import sys
|
||||||
for arg in sys.argv[1:]:
|
for arg in sys.argv[1:]:
|
||||||
print(os.path.basename(arg))
|
print(os.path.basename(arg))
|
||||||
with open(arg, 'rb') as f:
|
with open(arg, 'rb') as f:
|
||||||
|
@ -9,6 +9,7 @@ import os, sys, atexit
|
|||||||
from itertools import product
|
from itertools import product
|
||||||
|
|
||||||
from calibre import prints, isbytestring
|
from calibre import prints, isbytestring
|
||||||
|
from calibre.utils.resources import get_path as P
|
||||||
from calibre.constants import filesystem_encoding
|
from calibre.constants import filesystem_encoding
|
||||||
from calibre.utils.fonts.utils import (is_truetype_font, get_font_names,
|
from calibre.utils.fonts.utils import (is_truetype_font, get_font_names,
|
||||||
get_font_characteristics)
|
get_font_characteristics)
|
||||||
|
@ -8,6 +8,7 @@ import ssl, socket, re
|
|||||||
from contextlib import closing
|
from contextlib import closing
|
||||||
|
|
||||||
from calibre import get_proxies
|
from calibre import get_proxies
|
||||||
|
from calibre.utils.resources import get_path as P
|
||||||
from polyglot import http_client
|
from polyglot import http_client
|
||||||
from polyglot.urllib import urlsplit
|
from polyglot.urllib import urlsplit
|
||||||
has_ssl_verify = hasattr(ssl, 'create_default_context') and hasattr(ssl, '_create_unverified_context')
|
has_ssl_verify = hasattr(ssl, 'create_default_context') and hasattr(ssl, '_create_unverified_context')
|
||||||
|
@ -10,6 +10,7 @@ from io import BytesIO
|
|||||||
|
|
||||||
from calibre.constants import cache_dir
|
from calibre.constants import cache_dir
|
||||||
from calibre.ptempfile import TemporaryDirectory
|
from calibre.ptempfile import TemporaryDirectory
|
||||||
|
from calibre.utils.resources import get_path as P
|
||||||
from calibre.utils.localization import lang_as_iso639_1
|
from calibre.utils.localization import lang_as_iso639_1
|
||||||
from calibre.utils.lock import ExclusiveFile
|
from calibre.utils.lock import ExclusiveFile
|
||||||
from polyglot.builtins import iteritems
|
from polyglot.builtins import iteritems
|
||||||
|
@ -4,6 +4,7 @@
|
|||||||
|
|
||||||
import json
|
import json
|
||||||
import random
|
import random
|
||||||
|
from calibre.utils.resources import get_path as P
|
||||||
|
|
||||||
|
|
||||||
def user_agent_data():
|
def user_agent_data():
|
||||||
|
@ -17,6 +17,7 @@ from calibre.constants import (
|
|||||||
)
|
)
|
||||||
from calibre.ptempfile import TemporaryDirectory
|
from calibre.ptempfile import TemporaryDirectory
|
||||||
from calibre.utils.filenames import atomic_rename
|
from calibre.utils.filenames import atomic_rename
|
||||||
|
from calibre.utils.resources import get_path as P
|
||||||
from polyglot.builtins import as_bytes, as_unicode, exec_path
|
from polyglot.builtins import as_bytes, as_unicode, exec_path
|
||||||
|
|
||||||
COMPILER_PATH = 'rapydscript/compiler.js.xz'
|
COMPILER_PATH = 'rapydscript/compiler.js.xz'
|
||||||
|
@ -20,7 +20,7 @@ If this module is run, it will perform a series of unit tests.
|
|||||||
import weakref, re
|
import weakref, re
|
||||||
|
|
||||||
from calibre.constants import preferred_encoding
|
from calibre.constants import preferred_encoding
|
||||||
from calibre.utils.icu import sort_key
|
from calibre.utils.icu import sort_key, lower as icu_lower
|
||||||
from calibre.utils.localization import _
|
from calibre.utils.localization import _
|
||||||
from calibre import prints
|
from calibre import prints
|
||||||
from polyglot.binary import as_hex_unicode, from_hex_unicode
|
from polyglot.binary import as_hex_unicode, from_hex_unicode
|
||||||
|
@ -10,7 +10,7 @@ License: http://www.opensource.org/licenses/mit-license.php
|
|||||||
|
|
||||||
import re
|
import re
|
||||||
|
|
||||||
from calibre.utils.icu import capitalize, upper
|
from calibre.utils.icu import capitalize, lower as icu_lower, upper as icu_upper
|
||||||
|
|
||||||
__all__ = ['titlecase']
|
__all__ = ['titlecase']
|
||||||
__version__ = '0.5'
|
__version__ = '0.5'
|
||||||
@ -52,7 +52,7 @@ def titlecase(text):
|
|||||||
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
all_caps = upper(text) == text
|
all_caps = icu_upper(text) == text
|
||||||
|
|
||||||
pat = re.compile(r'(\s+)')
|
pat = re.compile(r'(\s+)')
|
||||||
line = []
|
line = []
|
||||||
|
@ -28,7 +28,7 @@ from calibre.ptempfile import PersistentTemporaryFile
|
|||||||
from calibre.utils.date import now as nowf
|
from calibre.utils.date import now as nowf
|
||||||
from calibre.utils.icu import numeric_sort_key
|
from calibre.utils.icu import numeric_sort_key
|
||||||
from calibre.utils.img import add_borders_to_image, image_to_data, save_cover_data_to
|
from calibre.utils.img import add_borders_to_image, image_to_data, save_cover_data_to
|
||||||
from calibre.utils.localization import _, canonicalize_lang
|
from calibre.utils.localization import _, canonicalize_lang, ngettext
|
||||||
from calibre.utils.logging import ThreadSafeWrapper
|
from calibre.utils.logging import ThreadSafeWrapper
|
||||||
from calibre.utils.threadpool import NoResultsPending, ThreadPool, WorkRequest
|
from calibre.utils.threadpool import NoResultsPending, ThreadPool, WorkRequest
|
||||||
from calibre.web import Recipe
|
from calibre.web import Recipe
|
||||||
|
Loading…
x
Reference in New Issue
Block a user