mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Move constants used by db backend into a separate module so we dont need to import the full backend everywhere else
This commit is contained in:
parent
dba94e1b5b
commit
a91889f390
@ -16,9 +16,7 @@ import sys
|
|||||||
import time
|
import time
|
||||||
import uuid
|
import uuid
|
||||||
from contextlib import closing, suppress
|
from contextlib import closing, suppress
|
||||||
from dataclasses import dataclass
|
|
||||||
from functools import partial
|
from functools import partial
|
||||||
from typing import Sequence
|
|
||||||
|
|
||||||
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 (
|
||||||
@ -26,6 +24,10 @@ from calibre.constants import (
|
|||||||
)
|
)
|
||||||
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
|
||||||
|
from calibre.db.constants import (
|
||||||
|
BOOK_ID_PATH_TEMPLATE, COVER_FILE_NAME, DEFAULT_TRASH_EXPIRY_TIME_SECONDS,
|
||||||
|
METADATA_FILE_NAME, TRASH_DIR_NAME, TrashEntry,
|
||||||
|
)
|
||||||
from calibre.db.errors import NoSuchFormat
|
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 (
|
||||||
@ -56,27 +58,11 @@ from polyglot.builtins import (
|
|||||||
|
|
||||||
# }}}
|
# }}}
|
||||||
|
|
||||||
COVER_FILE_NAME = 'cover.jpg'
|
|
||||||
METADATA_FILE_NAME = 'metadata.opf'
|
|
||||||
DEFAULT_TRASH_EXPIRY_TIME_SECONDS = 14 * 86400
|
|
||||||
TRASH_DIR_NAME = '.caltrash'
|
|
||||||
DATA_DIR_NAME = 'data'
|
|
||||||
BOOK_ID_PATH_TEMPLATE = ' ({})'
|
|
||||||
CUSTOM_DATA_TYPES = frozenset(('rating', 'text', 'comments', 'datetime',
|
CUSTOM_DATA_TYPES = frozenset(('rating', 'text', 'comments', 'datetime',
|
||||||
'int', 'float', 'bool', 'series', 'composite', 'enumeration'))
|
'int', 'float', 'bool', 'series', 'composite', 'enumeration'))
|
||||||
WINDOWS_RESERVED_NAMES = frozenset('CON PRN AUX NUL COM1 COM2 COM3 COM4 COM5 COM6 COM7 COM8 COM9 LPT1 LPT2 LPT3 LPT4 LPT5 LPT6 LPT7 LPT8 LPT9'.split())
|
WINDOWS_RESERVED_NAMES = frozenset('CON PRN AUX NUL COM1 COM2 COM3 COM4 COM5 COM6 COM7 COM8 COM9 LPT1 LPT2 LPT3 LPT4 LPT5 LPT6 LPT7 LPT8 LPT9'.split())
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
|
||||||
class TrashEntry:
|
|
||||||
book_id: int
|
|
||||||
title: str
|
|
||||||
author: str
|
|
||||||
cover_path: str
|
|
||||||
mtime: float
|
|
||||||
formats: Sequence[str] = ()
|
|
||||||
|
|
||||||
|
|
||||||
class DynamicFilter: # {{{
|
class DynamicFilter: # {{{
|
||||||
|
|
||||||
'No longer used, present for legacy compatibility'
|
'No longer used, present for legacy compatibility'
|
||||||
|
22
src/calibre/db/constants.py
Normal file
22
src/calibre/db/constants.py
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
#!/usr/bin/env python
|
||||||
|
# License: GPLv3 Copyright: 2023, Kovid Goyal <kovid at kovidgoyal.net>
|
||||||
|
|
||||||
|
from dataclasses import dataclass
|
||||||
|
from typing import Sequence
|
||||||
|
|
||||||
|
COVER_FILE_NAME = 'cover.jpg'
|
||||||
|
METADATA_FILE_NAME = 'metadata.opf'
|
||||||
|
DEFAULT_TRASH_EXPIRY_TIME_SECONDS = 14 * 86400
|
||||||
|
TRASH_DIR_NAME = '.caltrash'
|
||||||
|
DATA_DIR_NAME = 'data'
|
||||||
|
BOOK_ID_PATH_TEMPLATE = ' ({})'
|
||||||
|
|
||||||
|
|
||||||
|
@dataclass
|
||||||
|
class TrashEntry:
|
||||||
|
book_id: int
|
||||||
|
title: str
|
||||||
|
author: str
|
||||||
|
cover_path: str
|
||||||
|
mtime: float
|
||||||
|
formats: Sequence[str] = ()
|
@ -17,7 +17,8 @@ from threading import Thread
|
|||||||
|
|
||||||
from calibre import force_unicode, isbytestring
|
from calibre import force_unicode, isbytestring
|
||||||
from calibre.constants import filesystem_encoding
|
from calibre.constants import filesystem_encoding
|
||||||
from calibre.db.backend import DB, METADATA_FILE_NAME, TRASH_DIR_NAME, DBPrefs
|
from calibre.db.backend import DB, DBPrefs
|
||||||
|
from calibre.db.constants import METADATA_FILE_NAME, TRASH_DIR_NAME
|
||||||
from calibre.db.cache import Cache
|
from calibre.db.cache import Cache
|
||||||
from calibre.ebooks.metadata.opf2 import OPF
|
from calibre.ebooks.metadata.opf2 import OPF
|
||||||
from calibre.ptempfile import TemporaryDirectory
|
from calibre.ptempfile import TemporaryDirectory
|
||||||
|
@ -12,7 +12,7 @@ from datetime import timedelta
|
|||||||
from io import BytesIO
|
from io import BytesIO
|
||||||
from tempfile import NamedTemporaryFile
|
from tempfile import NamedTemporaryFile
|
||||||
|
|
||||||
from calibre.db.backend import METADATA_FILE_NAME
|
from calibre.db.constants import METADATA_FILE_NAME
|
||||||
from calibre.db.tests.base import IMG, BaseTest
|
from calibre.db.tests.base import IMG, BaseTest
|
||||||
from calibre.ptempfile import PersistentTemporaryFile
|
from calibre.ptempfile import PersistentTemporaryFile
|
||||||
from calibre.utils.date import UNDEFINED_DATE, now, utcnow
|
from calibre.utils.date import UNDEFINED_DATE, now, utcnow
|
||||||
|
@ -10,7 +10,7 @@ from functools import partial
|
|||||||
|
|
||||||
from calibre import force_unicode, prepare_string_for_xml
|
from calibre import force_unicode, prepare_string_for_xml
|
||||||
from calibre.constants import filesystem_encoding
|
from calibre.constants import filesystem_encoding
|
||||||
from calibre.db.backend import DATA_DIR_NAME
|
from calibre.db.constants import DATA_DIR_NAME
|
||||||
from calibre.ebooks.metadata import fmt_sidx, rating_to_stars
|
from calibre.ebooks.metadata import fmt_sidx, rating_to_stars
|
||||||
from calibre.ebooks.metadata.search_internet import (
|
from calibre.ebooks.metadata.search_internet import (
|
||||||
DEFAULT_AUTHOR_SOURCE, name_for, qquote, url_for_author_search, url_for_book_search,
|
DEFAULT_AUTHOR_SOURCE, name_for, qquote, url_for_author_search, url_for_book_search,
|
||||||
|
@ -12,7 +12,7 @@ from functools import partial
|
|||||||
from qt.core import QAction, QDialog, QIcon, pyqtSignal
|
from qt.core import QAction, QDialog, QIcon, pyqtSignal
|
||||||
|
|
||||||
from calibre.constants import ismacos, iswindows
|
from calibre.constants import ismacos, iswindows
|
||||||
from calibre.db.backend import DATA_DIR_NAME
|
from calibre.db.constants import DATA_DIR_NAME
|
||||||
from calibre.gui2 import (
|
from calibre.gui2 import (
|
||||||
Dispatcher, config, elided_text, error_dialog, info_dialog, open_local_file,
|
Dispatcher, config, elided_text, error_dialog, info_dialog, open_local_file,
|
||||||
question_dialog,
|
question_dialog,
|
||||||
|
@ -15,7 +15,7 @@ from qt.core import (
|
|||||||
|
|
||||||
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.backend import DATA_DIR_NAME
|
from calibre.db.constants import DATA_DIR_NAME
|
||||||
from calibre.ebooks import BOOK_EXTENSIONS
|
from calibre.ebooks import BOOK_EXTENSIONS
|
||||||
from calibre.ebooks.metadata.book.base import Metadata, field_metadata
|
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
|
||||||
|
@ -19,7 +19,7 @@ from qt.core import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
from calibre import xml_replace_entities
|
from calibre import xml_replace_entities
|
||||||
from calibre.db.backend import DATA_DIR_NAME
|
from calibre.db.constants import DATA_DIR_NAME
|
||||||
from calibre.ebooks.chardet import xml_to_unicode
|
from calibre.ebooks.chardet import xml_to_unicode
|
||||||
from calibre.gui2 import (
|
from calibre.gui2 import (
|
||||||
NO_URL_FORMATTING, choose_dir, choose_files, error_dialog, gprefs, is_dark_theme,
|
NO_URL_FORMATTING, choose_dir, choose_files, error_dialog, gprefs, is_dark_theme,
|
||||||
|
@ -12,7 +12,7 @@ from qt.core import (
|
|||||||
from typing import Iterator, List
|
from typing import Iterator, List
|
||||||
|
|
||||||
from calibre import fit_image
|
from calibre import fit_image
|
||||||
from calibre.db.backend import DEFAULT_TRASH_EXPIRY_TIME_SECONDS, TrashEntry
|
from calibre.db.constants import DEFAULT_TRASH_EXPIRY_TIME_SECONDS, TrashEntry
|
||||||
from calibre.gui2 import error_dialog
|
from calibre.gui2 import error_dialog
|
||||||
from calibre.gui2.dialogs.confirm_delete import confirm
|
from calibre.gui2.dialogs.confirm_delete import confirm
|
||||||
from calibre.gui2.widgets import BusyCursor
|
from calibre.gui2.widgets import BusyCursor
|
||||||
|
@ -12,7 +12,7 @@ import traceback
|
|||||||
|
|
||||||
from calibre import isbytestring
|
from calibre import isbytestring
|
||||||
from calibre.constants import filesystem_encoding
|
from calibre.constants import filesystem_encoding
|
||||||
from calibre.db.backend import (
|
from calibre.db.constants import (
|
||||||
COVER_FILE_NAME, DATA_DIR_NAME, METADATA_FILE_NAME, TRASH_DIR_NAME,
|
COVER_FILE_NAME, DATA_DIR_NAME, METADATA_FILE_NAME, TRASH_DIR_NAME,
|
||||||
)
|
)
|
||||||
from calibre.ebooks import BOOK_EXTENSIONS
|
from calibre.ebooks import BOOK_EXTENSIONS
|
||||||
|
Loading…
x
Reference in New Issue
Block a user