mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Speed up import of device plugins
This commit is contained in:
parent
e02c57c71b
commit
a3286903df
@ -8,21 +8,29 @@ __docformat__ = 'restructuredtext en'
|
|||||||
import cStringIO, ctypes, datetime, os, re, shutil, sys, tempfile, time
|
import cStringIO, ctypes, datetime, os, re, shutil, sys, tempfile, time
|
||||||
|
|
||||||
from calibre.constants import __appname__, __version__, DEBUG
|
from calibre.constants import __appname__, __version__, DEBUG
|
||||||
from calibre import fit_image, confirm_config_name
|
from calibre import fit_image, confirm_config_name, strftime as _strftime
|
||||||
from calibre.constants import isosx, iswindows
|
from calibre.constants import isosx, iswindows
|
||||||
from calibre.devices.errors import OpenFeedback, UserFeedback
|
from calibre.devices.errors import OpenFeedback, UserFeedback
|
||||||
from calibre.devices.usbms.deviceconfig import DeviceConfig
|
from calibre.devices.usbms.deviceconfig import DeviceConfig
|
||||||
from calibre.devices.interface import DevicePlugin
|
from calibre.devices.interface import DevicePlugin
|
||||||
from calibre.ebooks.BeautifulSoup import BeautifulSoup
|
|
||||||
from calibre.ebooks.metadata import authors_to_string, MetaInformation, title_sort
|
from calibre.ebooks.metadata import authors_to_string, MetaInformation, title_sort
|
||||||
from calibre.ebooks.metadata.book.base import Metadata
|
from calibre.ebooks.metadata.book.base import Metadata
|
||||||
from calibre.ebooks.metadata.epub import set_metadata
|
|
||||||
from calibre.library.server.utils import strftime
|
|
||||||
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.date import now, parse_date
|
||||||
from calibre.utils.logging import Log
|
from calibre.utils.logging import Log
|
||||||
from calibre.utils.zipfile import ZipFile
|
from calibre.utils.zipfile import ZipFile
|
||||||
|
|
||||||
|
def strftime(fmt='%Y/%m/%d %H:%M:%S', dt=None):
|
||||||
|
|
||||||
|
if not hasattr(dt, 'timetuple'):
|
||||||
|
dt = now()
|
||||||
|
dt = dt.timetuple()
|
||||||
|
try:
|
||||||
|
return _strftime(fmt, dt)
|
||||||
|
except:
|
||||||
|
return _strftime(fmt, now().timetuple())
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class AppleOpenFeedback(OpenFeedback):
|
class AppleOpenFeedback(OpenFeedback):
|
||||||
|
|
||||||
@ -1675,6 +1683,8 @@ class ITUNES(DriverBase):
|
|||||||
def _dump_epub_metadata(self, fpath):
|
def _dump_epub_metadata(self, fpath):
|
||||||
'''
|
'''
|
||||||
'''
|
'''
|
||||||
|
from calibre.ebooks.BeautifulSoup import BeautifulSoup
|
||||||
|
|
||||||
self.log.info(" ITUNES.__get_epub_metadata()")
|
self.log.info(" ITUNES.__get_epub_metadata()")
|
||||||
title = None
|
title = None
|
||||||
author = None
|
author = None
|
||||||
@ -2648,6 +2658,8 @@ class ITUNES(DriverBase):
|
|||||||
def _update_epub_metadata(self, fpath, metadata):
|
def _update_epub_metadata(self, fpath, metadata):
|
||||||
'''
|
'''
|
||||||
'''
|
'''
|
||||||
|
from calibre.ebooks.metadata.epub import set_metadata
|
||||||
|
|
||||||
if DEBUG:
|
if DEBUG:
|
||||||
self.log.info(" ITUNES._update_epub_metadata()")
|
self.log.info(" ITUNES._update_epub_metadata()")
|
||||||
|
|
||||||
|
@ -8,7 +8,7 @@ __docformat__ = 'restructuredtext en'
|
|||||||
Sanda library wrapper
|
Sanda library wrapper
|
||||||
'''
|
'''
|
||||||
|
|
||||||
import ctypes, uuid, hashlib, os, sys
|
import ctypes, hashlib, os, sys
|
||||||
from threading import Event, Lock
|
from threading import Event, Lock
|
||||||
from calibre.constants import iswindows
|
from calibre.constants import iswindows
|
||||||
from calibre import load_library
|
from calibre import load_library
|
||||||
@ -350,6 +350,7 @@ class Bambook:
|
|||||||
return None
|
return None
|
||||||
|
|
||||||
def SendFile(self, fileName, guid = None):
|
def SendFile(self, fileName, guid = None):
|
||||||
|
import uuid
|
||||||
if self.handle:
|
if self.handle:
|
||||||
taskID = job.NewJob()
|
taskID = job.NewJob()
|
||||||
if guid:
|
if guid:
|
||||||
|
@ -9,7 +9,6 @@ Generates and writes an APNX page mapping file.
|
|||||||
'''
|
'''
|
||||||
|
|
||||||
import struct
|
import struct
|
||||||
import uuid
|
|
||||||
|
|
||||||
from calibre.ebooks.mobi.reader import MobiReader
|
from calibre.ebooks.mobi.reader import MobiReader
|
||||||
from calibre.ebooks.pdb.header import PdbHeaderReader
|
from calibre.ebooks.pdb.header import PdbHeaderReader
|
||||||
@ -51,6 +50,7 @@ class APNXBuilder(object):
|
|||||||
apnxf.write(apnx)
|
apnxf.write(apnx)
|
||||||
|
|
||||||
def generate_apnx(self, pages):
|
def generate_apnx(self, pages):
|
||||||
|
import uuid
|
||||||
apnx = ''
|
apnx = ''
|
||||||
|
|
||||||
content_vals = {
|
content_vals = {
|
||||||
|
@ -10,10 +10,8 @@ Device driver for Amazon's Kindle
|
|||||||
|
|
||||||
import datetime, os, re, sys, json, hashlib
|
import datetime, os, re, sys, json, hashlib
|
||||||
|
|
||||||
from calibre.devices.kindle.apnx import APNXBuilder
|
|
||||||
from calibre.devices.kindle.bookmark import Bookmark
|
from calibre.devices.kindle.bookmark import Bookmark
|
||||||
from calibre.devices.usbms.driver import USBMS
|
from calibre.devices.usbms.driver import USBMS
|
||||||
from calibre.ebooks.metadata import MetaInformation
|
|
||||||
from calibre import strftime
|
from calibre import strftime
|
||||||
|
|
||||||
'''
|
'''
|
||||||
@ -152,6 +150,7 @@ class KINDLE(USBMS):
|
|||||||
path_map, book_ext = resolve_bookmark_paths(storage, path_map)
|
path_map, book_ext = resolve_bookmark_paths(storage, path_map)
|
||||||
|
|
||||||
bookmarked_books = {}
|
bookmarked_books = {}
|
||||||
|
|
||||||
for id in path_map:
|
for id in path_map:
|
||||||
bookmark_ext = path_map[id].rpartition('.')[2]
|
bookmark_ext = path_map[id].rpartition('.')[2]
|
||||||
myBookmark = Bookmark(path_map[id], id, book_ext[id], bookmark_ext)
|
myBookmark = Bookmark(path_map[id], id, book_ext[id], bookmark_ext)
|
||||||
@ -236,6 +235,8 @@ class KINDLE(USBMS):
|
|||||||
|
|
||||||
def add_annotation_to_library(self, db, db_id, annotation):
|
def add_annotation_to_library(self, db, db_id, annotation):
|
||||||
from calibre.ebooks.BeautifulSoup import Tag
|
from calibre.ebooks.BeautifulSoup import Tag
|
||||||
|
from calibre.ebooks.metadata import MetaInformation
|
||||||
|
|
||||||
bm = annotation
|
bm = annotation
|
||||||
ignore_tags = set(['Catalog', 'Clippings'])
|
ignore_tags = set(['Catalog', 'Clippings'])
|
||||||
|
|
||||||
@ -363,6 +364,8 @@ class KINDLE2(KINDLE):
|
|||||||
'''
|
'''
|
||||||
Hijacking this function to write the apnx file.
|
Hijacking this function to write the apnx file.
|
||||||
'''
|
'''
|
||||||
|
from calibre.devices.kindle.apnx import APNXBuilder
|
||||||
|
|
||||||
opts = self.settings()
|
opts = self.settings()
|
||||||
if not opts.extra_customization[self.OPT_APNX]:
|
if not opts.extra_customization[self.OPT_APNX]:
|
||||||
return
|
return
|
||||||
|
@ -7,8 +7,6 @@ __docformat__ = 'restructuredtext en'
|
|||||||
|
|
||||||
import os, time
|
import os, time
|
||||||
from base64 import b64decode
|
from base64 import b64decode
|
||||||
from uuid import uuid4
|
|
||||||
from lxml import etree
|
|
||||||
from datetime import date
|
from datetime import date
|
||||||
|
|
||||||
from calibre import prints, guess_type, isbytestring
|
from calibre import prints, guess_type, isbytestring
|
||||||
@ -78,6 +76,7 @@ def strftime(epoch, zone=time.localtime):
|
|||||||
return ' '.join(src)
|
return ' '.join(src)
|
||||||
|
|
||||||
def uuid():
|
def uuid():
|
||||||
|
from uuid import uuid4
|
||||||
return str(uuid4()).replace('-', '', 1).upper()
|
return str(uuid4()).replace('-', '', 1).upper()
|
||||||
|
|
||||||
# }}}
|
# }}}
|
||||||
@ -85,6 +84,8 @@ def uuid():
|
|||||||
class XMLCache(object):
|
class XMLCache(object):
|
||||||
|
|
||||||
def __init__(self, paths, ext_paths, prefixes, use_author_sort):
|
def __init__(self, paths, ext_paths, prefixes, use_author_sort):
|
||||||
|
from lxml import etree
|
||||||
|
|
||||||
if DEBUG:
|
if DEBUG:
|
||||||
debug_print('Building XMLCache...', paths)
|
debug_print('Building XMLCache...', paths)
|
||||||
self.paths = paths
|
self.paths = paths
|
||||||
@ -714,6 +715,8 @@ class XMLCache(object):
|
|||||||
|
|
||||||
|
|
||||||
def write(self):
|
def write(self):
|
||||||
|
from lxml import etree
|
||||||
|
|
||||||
for i, path in self.paths.items():
|
for i, path in self.paths.items():
|
||||||
self.move_playlists_to_bottom()
|
self.move_playlists_to_bottom()
|
||||||
self.cleanup_whitespace(i)
|
self.cleanup_whitespace(i)
|
||||||
|
@ -10,7 +10,7 @@ driver. It is intended to be subclassed with the relevant parts implemented
|
|||||||
for a particular device.
|
for a particular device.
|
||||||
'''
|
'''
|
||||||
|
|
||||||
import os, re, time, json, uuid, functools, shutil
|
import os, re, time, json, functools, shutil
|
||||||
from itertools import cycle
|
from itertools import cycle
|
||||||
|
|
||||||
from calibre.constants import numeric_version
|
from calibre.constants import numeric_version
|
||||||
@ -58,6 +58,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):
|
||||||
|
import uuid
|
||||||
if not isinstance(dinfo, dict):
|
if not isinstance(dinfo, dict):
|
||||||
dinfo = {}
|
dinfo = {}
|
||||||
if dinfo.get('device_store_uuid', None) is None:
|
if dinfo.get('device_store_uuid', None) is None:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user