mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Delay load utils.date
This commit is contained in:
parent
edb84a621a
commit
0b88f9a399
@ -1761,7 +1761,8 @@ if __name__ == '__main__':
|
|||||||
|
|
||||||
for x in ('lxml', 'calibre.ebooks.BeautifulSoup', 'uuid',
|
for x in ('lxml', 'calibre.ebooks.BeautifulSoup', 'uuid',
|
||||||
'calibre.utils.terminal', 'calibre.utils.magick', 'PIL', 'Image',
|
'calibre.utils.terminal', 'calibre.utils.magick', 'PIL', 'Image',
|
||||||
'sqlite3', 'mechanize', 'httplib', 'xml', 'inspect', 'urllib'):
|
'sqlite3', 'mechanize', 'httplib', 'xml', 'inspect', 'urllib',
|
||||||
|
'calibre.utils.date'):
|
||||||
if x in sys.modules:
|
if x in sys.modules:
|
||||||
ret = 1
|
ret = 1
|
||||||
print (x, 'has been loaded by a plugin')
|
print (x, 'has been loaded by a plugin')
|
||||||
|
@ -18,12 +18,12 @@ from calibre.ebooks.metadata import (author_to_author_sort, authors_to_string,
|
|||||||
MetaInformation, title_sort)
|
MetaInformation, title_sort)
|
||||||
from calibre.ebooks.metadata.book.base import Metadata
|
from calibre.ebooks.metadata.book.base import Metadata
|
||||||
from calibre.utils.config import config_dir, dynamic, prefs
|
from calibre.utils.config import config_dir, dynamic, prefs
|
||||||
from calibre.utils.date import now, parse_date
|
|
||||||
from calibre.utils.zipfile import ZipFile
|
from calibre.utils.zipfile import ZipFile
|
||||||
|
|
||||||
DEBUG = CALIBRE_DEBUG
|
DEBUG = CALIBRE_DEBUG
|
||||||
|
|
||||||
def strftime(fmt='%Y/%m/%d %H:%M:%S', dt=None):
|
def strftime(fmt='%Y/%m/%d %H:%M:%S', dt=None):
|
||||||
|
from calibre.utils.date import now
|
||||||
|
|
||||||
if not hasattr(dt, 'timetuple'):
|
if not hasattr(dt, 'timetuple'):
|
||||||
dt = now()
|
dt = now()
|
||||||
@ -413,6 +413,7 @@ class ITUNES(DriverBase):
|
|||||||
list of device books.
|
list of device books.
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
from calibre.utils.date import parse_date
|
||||||
if not oncard:
|
if not oncard:
|
||||||
if DEBUG:
|
if DEBUG:
|
||||||
logger().info("%s.books():" % self.__class__.__name__)
|
logger().info("%s.books():" % self.__class__.__name__)
|
||||||
@ -1557,6 +1558,7 @@ class ITUNES(DriverBase):
|
|||||||
def _create_new_book(self, fpath, metadata, path, db_added, lb_added, thumb, format):
|
def _create_new_book(self, fpath, metadata, path, db_added, lb_added, thumb, format):
|
||||||
'''
|
'''
|
||||||
'''
|
'''
|
||||||
|
from calibre.utils.date import parse_date
|
||||||
if DEBUG:
|
if DEBUG:
|
||||||
logger().info(" %s._create_new_book()" % self.__class__.__name__)
|
logger().info(" %s._create_new_book()" % self.__class__.__name__)
|
||||||
|
|
||||||
@ -2776,6 +2778,7 @@ class ITUNES(DriverBase):
|
|||||||
def _update_epub_metadata(self, fpath, metadata):
|
def _update_epub_metadata(self, fpath, metadata):
|
||||||
'''
|
'''
|
||||||
'''
|
'''
|
||||||
|
from calibre.utils.date import parse_date, now
|
||||||
from calibre.ebooks.metadata.epub import set_metadata
|
from calibre.ebooks.metadata.epub import set_metadata
|
||||||
from lxml import etree
|
from lxml import etree
|
||||||
|
|
||||||
@ -3248,6 +3251,7 @@ class ITUNES_ASYNC(ITUNES):
|
|||||||
list of device books.
|
list of device books.
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
from calibre.utils.date import parse_date
|
||||||
if not oncard:
|
if not oncard:
|
||||||
if DEBUG:
|
if DEBUG:
|
||||||
logger().info("%s.books()" % self.__class__.__name__)
|
logger().info("%s.books()" % self.__class__.__name__)
|
||||||
|
@ -11,7 +11,6 @@ from calibre.utils.icu import sort_key
|
|||||||
from calibre.devices.usbms.books import Book as Book_
|
from calibre.devices.usbms.books import Book as Book_
|
||||||
from calibre.devices.usbms.books import CollectionsBookList
|
from calibre.devices.usbms.books import CollectionsBookList
|
||||||
from calibre.utils.config import prefs
|
from calibre.utils.config import prefs
|
||||||
from calibre.utils.date import parse_date
|
|
||||||
from calibre.devices.usbms.driver import debug_print
|
from calibre.devices.usbms.driver import debug_print
|
||||||
from calibre.ebooks.metadata import author_to_author_sort
|
from calibre.ebooks.metadata import author_to_author_sort
|
||||||
|
|
||||||
@ -19,6 +18,7 @@ class Book(Book_):
|
|||||||
|
|
||||||
def __init__(self, prefix, lpath, title=None, authors=None, mime=None, date=None, ContentType=None,
|
def __init__(self, prefix, lpath, title=None, authors=None, mime=None, date=None, ContentType=None,
|
||||||
thumbnail_name=None, size=None, other=None):
|
thumbnail_name=None, size=None, other=None):
|
||||||
|
from calibre.utils.date import parse_date
|
||||||
# debug_print('Book::__init__ - title=', title)
|
# debug_print('Book::__init__ - title=', title)
|
||||||
show_debug = title is not None and title.lower().find("xxxxx") >= 0
|
show_debug = title is not None and title.lower().find("xxxxx") >= 0
|
||||||
if show_debug:
|
if show_debug:
|
||||||
|
@ -18,7 +18,6 @@ from calibre.devices.mtp.base import debug
|
|||||||
from calibre.devices.mtp.defaults import DeviceDefaults
|
from calibre.devices.mtp.defaults import DeviceDefaults
|
||||||
from calibre.ptempfile import SpooledTemporaryFile, PersistentTemporaryDirectory
|
from calibre.ptempfile import SpooledTemporaryFile, PersistentTemporaryDirectory
|
||||||
from calibre.utils.config import from_json, to_json, JSONConfig
|
from calibre.utils.config import from_json, to_json, JSONConfig
|
||||||
from calibre.utils.date import now, isoformat, utcnow
|
|
||||||
from calibre.utils.filenames import shorten_components_to
|
from calibre.utils.filenames import shorten_components_to
|
||||||
|
|
||||||
BASE = importlib.import_module('calibre.devices.mtp.%s.driver'%(
|
BASE = importlib.import_module('calibre.devices.mtp.%s.driver'%(
|
||||||
@ -103,6 +102,7 @@ class MTP_DEVICE(BASE):
|
|||||||
del self.prefs[x]
|
del self.prefs[x]
|
||||||
|
|
||||||
def open(self, device, library_uuid):
|
def open(self, device, library_uuid):
|
||||||
|
from calibre.utils.date import isoformat, utcnow
|
||||||
self.current_library_uuid = library_uuid
|
self.current_library_uuid = library_uuid
|
||||||
self.location_paths = None
|
self.location_paths = None
|
||||||
self.driveinfo = {}
|
self.driveinfo = {}
|
||||||
@ -128,6 +128,7 @@ class MTP_DEVICE(BASE):
|
|||||||
|
|
||||||
# Device information {{{
|
# Device information {{{
|
||||||
def _update_drive_info(self, storage, location_code, name=None):
|
def _update_drive_info(self, storage, location_code, name=None):
|
||||||
|
from calibre.utils.date import isoformat, now
|
||||||
import uuid
|
import uuid
|
||||||
f = storage.find_path((self.DRIVEINFO,))
|
f = storage.find_path((self.DRIVEINFO,))
|
||||||
dinfo = {}
|
dinfo = {}
|
||||||
|
@ -35,7 +35,6 @@ from calibre.library.server import server_config as content_server_config
|
|||||||
from calibre.ptempfile import PersistentTemporaryFile
|
from calibre.ptempfile import PersistentTemporaryFile
|
||||||
from calibre.utils.ipc import eintr_retry_call
|
from calibre.utils.ipc import eintr_retry_call
|
||||||
from calibre.utils.config import from_json, tweaks
|
from calibre.utils.config import from_json, tweaks
|
||||||
from calibre.utils.date import isoformat, now
|
|
||||||
from calibre.utils.filenames import ascii_filename as sanitize, shorten_components_to
|
from calibre.utils.filenames import ascii_filename as sanitize, shorten_components_to
|
||||||
from calibre.utils.mdns import (publish as publish_zeroconf, unpublish as
|
from calibre.utils.mdns import (publish as publish_zeroconf, unpublish as
|
||||||
unpublish_zeroconf, get_all_ips)
|
unpublish_zeroconf, get_all_ips)
|
||||||
@ -374,6 +373,7 @@ class SMART_DEVICE_APP(DeviceConfig, DevicePlugin):
|
|||||||
|
|
||||||
# copied from USBMS. Perhaps this could be a classmethod in usbms?
|
# copied from USBMS. Perhaps this could be a classmethod in usbms?
|
||||||
def _update_driveinfo_record(self, dinfo, prefix, location_code, name=None):
|
def _update_driveinfo_record(self, dinfo, prefix, location_code, name=None):
|
||||||
|
from calibre.utils.date import isoformat, now
|
||||||
import uuid
|
import uuid
|
||||||
if not isinstance(dinfo, dict):
|
if not isinstance(dinfo, dict):
|
||||||
dinfo = {}
|
dinfo = {}
|
||||||
@ -817,6 +817,7 @@ class SMART_DEVICE_APP(DeviceConfig, DevicePlugin):
|
|||||||
|
|
||||||
@synchronous('sync_lock')
|
@synchronous('sync_lock')
|
||||||
def open(self, connected_device, library_uuid):
|
def open(self, connected_device, library_uuid):
|
||||||
|
from calibre.utils.date import isoformat, now
|
||||||
self._debug()
|
self._debug()
|
||||||
if not self.is_connected:
|
if not self.is_connected:
|
||||||
# We have been called to retry the connection. Give up immediately
|
# We have been called to retry the connection. Give up immediately
|
||||||
|
@ -21,7 +21,6 @@ from calibre.devices.usbms.device import Device
|
|||||||
from calibre.devices.usbms.books import BookList, Book
|
from calibre.devices.usbms.books import BookList, Book
|
||||||
from calibre.ebooks.metadata.book.json_codec import JsonCodec
|
from calibre.ebooks.metadata.book.json_codec import JsonCodec
|
||||||
from calibre.utils.config import from_json, to_json
|
from calibre.utils.config import from_json, to_json
|
||||||
from calibre.utils.date import now, isoformat
|
|
||||||
|
|
||||||
BASE_TIME = None
|
BASE_TIME = None
|
||||||
def debug_print(*args):
|
def debug_print(*args):
|
||||||
@ -58,6 +57,7 @@ class USBMS(CLI, Device):
|
|||||||
SCAN_FROM_ROOT = False
|
SCAN_FROM_ROOT = False
|
||||||
|
|
||||||
def _update_driveinfo_record(self, dinfo, prefix, location_code, name=None):
|
def _update_driveinfo_record(self, dinfo, prefix, location_code, name=None):
|
||||||
|
from calibre.utils.date import now, isoformat
|
||||||
import uuid
|
import uuid
|
||||||
if not isinstance(dinfo, dict):
|
if not isinstance(dinfo, dict):
|
||||||
dinfo = {}
|
dinfo = {}
|
||||||
|
@ -13,7 +13,6 @@ from calibre.ebooks.metadata.book import (SC_COPYABLE_FIELDS,
|
|||||||
SC_FIELDS_COPY_NOT_NULL, STANDARD_METADATA_FIELDS,
|
SC_FIELDS_COPY_NOT_NULL, STANDARD_METADATA_FIELDS,
|
||||||
TOP_LEVEL_IDENTIFIERS, ALL_METADATA_FIELDS)
|
TOP_LEVEL_IDENTIFIERS, ALL_METADATA_FIELDS)
|
||||||
from calibre.library.field_metadata import FieldMetadata
|
from calibre.library.field_metadata import FieldMetadata
|
||||||
from calibre.utils.date import isoformat, format_date, parse_only_date
|
|
||||||
from calibre.utils.icu import sort_key
|
from calibre.utils.icu import sort_key
|
||||||
|
|
||||||
# Special sets used to optimize the performance of getting and setting
|
# Special sets used to optimize the performance of getting and setting
|
||||||
@ -602,6 +601,7 @@ class Metadata(object):
|
|||||||
returns the tuple (display_name, formatted_value, original_value,
|
returns the tuple (display_name, formatted_value, original_value,
|
||||||
field_metadata)
|
field_metadata)
|
||||||
'''
|
'''
|
||||||
|
from calibre.utils.date import format_date
|
||||||
|
|
||||||
# Handle custom series index
|
# Handle custom series index
|
||||||
if key.startswith('#') and key.endswith('_index'):
|
if key.startswith('#') and key.endswith('_index'):
|
||||||
@ -686,6 +686,7 @@ class Metadata(object):
|
|||||||
A string representation of this object, suitable for printing to
|
A string representation of this object, suitable for printing to
|
||||||
console
|
console
|
||||||
'''
|
'''
|
||||||
|
from calibre.utils.date import isoformat
|
||||||
from calibre.ebooks.metadata import authors_to_string
|
from calibre.ebooks.metadata import authors_to_string
|
||||||
ans = []
|
ans = []
|
||||||
def fmt(x, y):
|
def fmt(x, y):
|
||||||
@ -778,6 +779,7 @@ def field_from_string(field, raw, field_metadata):
|
|||||||
elif dt == 'rating':
|
elif dt == 'rating':
|
||||||
val = float(raw) * 2
|
val = float(raw) * 2
|
||||||
elif dt == 'datetime':
|
elif dt == 'datetime':
|
||||||
|
from calibre.utils.date import parse_only_date
|
||||||
val = parse_only_date(raw)
|
val = parse_only_date(raw)
|
||||||
elif dt == 'bool':
|
elif dt == 'bool':
|
||||||
if raw.lower() in {'true', 'yes', 'y'}:
|
if raw.lower() in {'true', 'yes', 'y'}:
|
||||||
|
@ -11,17 +11,18 @@ from datetime import datetime, time
|
|||||||
from calibre.ebooks.metadata.book import SERIALIZABLE_FIELDS
|
from calibre.ebooks.metadata.book import SERIALIZABLE_FIELDS
|
||||||
from calibre.constants import filesystem_encoding, preferred_encoding
|
from calibre.constants import filesystem_encoding, preferred_encoding
|
||||||
from calibre.library.field_metadata import FieldMetadata
|
from calibre.library.field_metadata import FieldMetadata
|
||||||
from calibre.utils.date import parse_date, isoformat, UNDEFINED_DATE, local_tz
|
|
||||||
from calibre import isbytestring
|
from calibre import isbytestring
|
||||||
|
|
||||||
# Translate datetimes to and from strings. The string form is the datetime in
|
# Translate datetimes to and from strings. The string form is the datetime in
|
||||||
# UTC. The returned date is also UTC
|
# UTC. The returned date is also UTC
|
||||||
def string_to_datetime(src):
|
def string_to_datetime(src):
|
||||||
|
from calibre.utils.date import parse_date
|
||||||
if src == "None":
|
if src == "None":
|
||||||
return None
|
return None
|
||||||
return parse_date(src)
|
return parse_date(src)
|
||||||
|
|
||||||
def datetime_to_string(dateval):
|
def datetime_to_string(dateval):
|
||||||
|
from calibre.utils.date import isoformat, UNDEFINED_DATE, local_tz
|
||||||
if dateval is None:
|
if dateval is None:
|
||||||
return "None"
|
return "None"
|
||||||
if not isinstance(dateval, datetime):
|
if not isinstance(dateval, datetime):
|
||||||
|
@ -17,7 +17,6 @@ from calibre.ebooks.metadata import check_isbn
|
|||||||
from calibre.ebooks.metadata.sources.base import (Source, Option, fixcase,
|
from calibre.ebooks.metadata.sources.base import (Source, Option, fixcase,
|
||||||
fixauthors)
|
fixauthors)
|
||||||
from calibre.ebooks.metadata.book.base import Metadata
|
from calibre.ebooks.metadata.book.base import Metadata
|
||||||
from calibre.utils.date import parse_only_date
|
|
||||||
from calibre.utils.localization import canonicalize_lang
|
from calibre.utils.localization import canonicalize_lang
|
||||||
|
|
||||||
class Worker(Thread): # Get details {{{
|
class Worker(Thread): # Get details {{{
|
||||||
@ -494,6 +493,7 @@ class Worker(Thread): # Get details {{{
|
|||||||
def parse_pubdate(self, pd):
|
def parse_pubdate(self, pd):
|
||||||
for x in reversed(pd.xpath(self.publisher_xpath)):
|
for x in reversed(pd.xpath(self.publisher_xpath)):
|
||||||
if x.tail:
|
if x.tail:
|
||||||
|
from calibre.utils.date import parse_only_date
|
||||||
ans = x.tail
|
ans = x.tail
|
||||||
date = ans.rpartition('(')[-1].replace(')', '').strip()
|
date = ans.rpartition('(')[-1].replace(')', '').strip()
|
||||||
date = self.delocalize_datestr(date)
|
date = self.delocalize_datestr(date)
|
||||||
|
@ -13,7 +13,6 @@ from future_builtins import map
|
|||||||
from calibre import browser, random_user_agent
|
from calibre import browser, random_user_agent
|
||||||
from calibre.customize import Plugin
|
from calibre.customize import Plugin
|
||||||
from calibre.utils.config import JSONConfig
|
from calibre.utils.config import JSONConfig
|
||||||
from calibre.utils.titlecase import titlecase
|
|
||||||
from calibre.utils.icu import capitalize, lower, upper
|
from calibre.utils.icu import capitalize, lower, upper
|
||||||
from calibre.ebooks.metadata import check_isbn
|
from calibre.ebooks.metadata import check_isbn
|
||||||
|
|
||||||
@ -162,6 +161,7 @@ def fixauthors(authors):
|
|||||||
|
|
||||||
def fixcase(x):
|
def fixcase(x):
|
||||||
if x:
|
if x:
|
||||||
|
from calibre.utils.titlecase import titlecase
|
||||||
x = titlecase(x)
|
x = titlecase(x)
|
||||||
return x
|
return x
|
||||||
|
|
||||||
|
@ -15,7 +15,6 @@ from calibre.ebooks.metadata import check_isbn
|
|||||||
from calibre.ebooks.metadata.sources.base import Source
|
from calibre.ebooks.metadata.sources.base import Source
|
||||||
from calibre.ebooks.metadata.book.base import Metadata
|
from calibre.ebooks.metadata.book.base import Metadata
|
||||||
from calibre.ebooks.chardet import xml_to_unicode
|
from calibre.ebooks.chardet import xml_to_unicode
|
||||||
from calibre.utils.date import parse_date, utcnow
|
|
||||||
from calibre.utils.cleantext import clean_ascii_chars
|
from calibre.utils.cleantext import clean_ascii_chars
|
||||||
from calibre.utils.localization import canonicalize_lang
|
from calibre.utils.localization import canonicalize_lang
|
||||||
from calibre import as_unicode
|
from calibre import as_unicode
|
||||||
@ -130,6 +129,7 @@ def to_metadata(browser, log, entry_, timeout): # {{{
|
|||||||
# pubdate
|
# pubdate
|
||||||
pubdate = get_text(extra, date)
|
pubdate = get_text(extra, date)
|
||||||
if pubdate:
|
if pubdate:
|
||||||
|
from calibre.utils.date import parse_date, utcnow
|
||||||
try:
|
try:
|
||||||
default = utcnow().replace(day=15)
|
default = utcnow().replace(day=15)
|
||||||
mi.pubdate = parse_date(pubdate, assume_utc=True, default=default)
|
mi.pubdate = parse_date(pubdate, assume_utc=True, default=default)
|
||||||
|
@ -12,7 +12,6 @@ from calibre import as_unicode
|
|||||||
from calibre.ebooks.metadata import check_isbn
|
from calibre.ebooks.metadata import check_isbn
|
||||||
from calibre.ebooks.metadata.sources.base import Source
|
from calibre.ebooks.metadata.sources.base import Source
|
||||||
from calibre.ebooks.metadata.book.base import Metadata
|
from calibre.ebooks.metadata.book.base import Metadata
|
||||||
from calibre.utils.date import parse_only_date
|
|
||||||
|
|
||||||
class Ozon(Source):
|
class Ozon(Source):
|
||||||
name = 'OZON.ru'
|
name = 'OZON.ru'
|
||||||
@ -460,6 +459,7 @@ def _normalizeAuthorNameWithInitials(name): # {{{
|
|||||||
# }}}
|
# }}}
|
||||||
|
|
||||||
def toPubdate(log, yearAsString): # {{{
|
def toPubdate(log, yearAsString): # {{{
|
||||||
|
from calibre.utils.date import parse_only_date
|
||||||
res = None
|
res = None
|
||||||
if yearAsString:
|
if yearAsString:
|
||||||
try:
|
try:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user