mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-07 10:14:46 -04:00
Remove all remaining uses of plugins dict
This commit is contained in:
parent
e90770509f
commit
94d5775047
@ -334,7 +334,7 @@ if cconfd is not None:
|
|||||||
elif iswindows:
|
elif iswindows:
|
||||||
from calibre_extensions import winutil
|
from calibre_extensions import winutil
|
||||||
try:
|
try:
|
||||||
config_dir = winutil.special_folder_path(plugins['winutil'][0].CSIDL_APPDATA)
|
config_dir = winutil.special_folder_path(winutil.CSIDL_APPDATA)
|
||||||
except ValueError:
|
except ValueError:
|
||||||
config_dir = None
|
config_dir = None
|
||||||
if not config_dir or not os.access(config_dir, os.W_OK|os.X_OK):
|
if not config_dir or not os.access(config_dir, os.W_OK|os.X_OK):
|
||||||
|
@ -182,14 +182,15 @@ def print_basic_debug_info(out=None):
|
|||||||
import platform
|
import platform
|
||||||
from contextlib import suppress
|
from contextlib import suppress
|
||||||
from calibre.constants import (__appname__, get_version, isportable, ismacos,
|
from calibre.constants import (__appname__, get_version, isportable, ismacos,
|
||||||
isfrozen, is64bit, plugins)
|
isfrozen, is64bit)
|
||||||
from calibre.utils.localization import set_translators
|
from calibre.utils.localization import set_translators
|
||||||
out(__appname__, get_version(), 'Portable' if isportable else '',
|
out(__appname__, get_version(), 'Portable' if isportable else '',
|
||||||
'embedded-python:', isfrozen, 'is64bit:', is64bit)
|
'embedded-python:', isfrozen, 'is64bit:', is64bit)
|
||||||
out(platform.platform(), platform.system(), platform.architecture())
|
out(platform.platform(), platform.system(), platform.architecture())
|
||||||
if iswindows and not is64bit:
|
if iswindows and not is64bit:
|
||||||
|
from calibre_extensions.winutil import is_wow64_process
|
||||||
with suppress(Exception):
|
with suppress(Exception):
|
||||||
if plugins['winutil'][0].is_wow64_process():
|
if is_wow64_process():
|
||||||
out('32bit process running on 64bit windows')
|
out('32bit process running on 64bit windows')
|
||||||
out(platform.system_alias(platform.system(), platform.release(),
|
out(platform.system_alias(platform.system(), platform.release(),
|
||||||
platform.version()))
|
platform.version()))
|
||||||
|
@ -305,13 +305,6 @@ class Bookmark(): # {{{
|
|||||||
self.book_length = mu.book_length
|
self.book_length = mu.book_length
|
||||||
except:
|
except:
|
||||||
pass
|
pass
|
||||||
elif self.bookmark_extension == 'pdr':
|
|
||||||
from calibre.constants import plugins
|
|
||||||
try:
|
|
||||||
self.book_length = plugins['pdfreflow'][0].get_numpages(open(book_fs).read())
|
|
||||||
except :
|
|
||||||
pass
|
|
||||||
|
|
||||||
else:
|
else:
|
||||||
print("unsupported bookmark_extension: %s" % self.bookmark_extension)
|
print("unsupported bookmark_extension: %s" % self.bookmark_extension)
|
||||||
|
|
||||||
|
@ -1524,9 +1524,8 @@ class KOBOTOUCH(KOBO):
|
|||||||
# Wrap some debugging output in a try/except so that it is unlikely to break things completely.
|
# Wrap some debugging output in a try/except so that it is unlikely to break things completely.
|
||||||
try:
|
try:
|
||||||
if DEBUG:
|
if DEBUG:
|
||||||
from calibre.constants import plugins
|
from calibre_extensions.usbobserver import get_mounted_filesystems
|
||||||
usbobserver, usbobserver_err = plugins['usbobserver']
|
mount_map = get_mounted_filesystems()
|
||||||
mount_map = usbobserver.get_mounted_filesystems()
|
|
||||||
debug_print('KoboTouch::open_osx - mount_map=', mount_map)
|
debug_print('KoboTouch::open_osx - mount_map=', mount_map)
|
||||||
debug_print('KoboTouch::open_osx - self._main_prefix=', self._main_prefix)
|
debug_print('KoboTouch::open_osx - self._main_prefix=', self._main_prefix)
|
||||||
debug_print('KoboTouch::open_osx - self._card_a_prefix=', self._card_a_prefix)
|
debug_print('KoboTouch::open_osx - self._card_a_prefix=', self._card_a_prefix)
|
||||||
|
@ -12,7 +12,7 @@ from polyglot.builtins import iteritems, itervalues, unicode_type, zip
|
|||||||
from itertools import chain
|
from itertools import chain
|
||||||
|
|
||||||
from calibre import as_unicode, prints, force_unicode
|
from calibre import as_unicode, prints, force_unicode
|
||||||
from calibre.constants import plugins, __appname__, numeric_version, isxp
|
from calibre.constants import __appname__, numeric_version, isxp
|
||||||
from calibre.ptempfile import SpooledTemporaryFile
|
from calibre.ptempfile import SpooledTemporaryFile
|
||||||
from calibre.devices.errors import OpenFailed, DeviceError, BlacklistedDevice
|
from calibre.devices.errors import OpenFailed, DeviceError, BlacklistedDevice
|
||||||
from calibre.devices.mtp.base import MTPDeviceBase, debug
|
from calibre.devices.mtp.base import MTPDeviceBase, debug
|
||||||
@ -63,7 +63,12 @@ class MTP_DEVICE(MTPDeviceBase):
|
|||||||
self.wpd = None
|
self.wpd = None
|
||||||
self.wpd_error = _('MTP devices are not supported on Windows XP')
|
self.wpd_error = _('MTP devices are not supported on Windows XP')
|
||||||
else:
|
else:
|
||||||
self.wpd, self.wpd_error = plugins['wpd']
|
try:
|
||||||
|
from calibre_extensions import wpd
|
||||||
|
self.wpd = wpd
|
||||||
|
except Exception as err:
|
||||||
|
self.wpd = None
|
||||||
|
self.wpd_error = as_unicode(err)
|
||||||
if self.wpd is not None:
|
if self.wpd is not None:
|
||||||
try:
|
try:
|
||||||
self.wpd.init(__appname__, *(numeric_version[:3]))
|
self.wpd.init(__appname__, *(numeric_version[:3]))
|
||||||
|
@ -6,7 +6,7 @@ __license__ = 'GPL v3'
|
|||||||
__copyright__ = '2012, Kovid Goyal <kovid at kovidgoyal.net>'
|
__copyright__ = '2012, Kovid Goyal <kovid at kovidgoyal.net>'
|
||||||
__docformat__ = 'restructuredtext en'
|
__docformat__ = 'restructuredtext en'
|
||||||
|
|
||||||
import subprocess, sys, os, pprint, signal, time, glob, io
|
import subprocess, os, pprint, signal, time, glob, io
|
||||||
pprint, io
|
pprint, io
|
||||||
from polyglot.builtins import environ_item
|
from polyglot.builtins import environ_item
|
||||||
|
|
||||||
@ -48,14 +48,6 @@ def main():
|
|||||||
subprocess.call(['calibre-debug', '-e', fp], env=env)
|
subprocess.call(['calibre-debug', '-e', fp], env=env)
|
||||||
return
|
return
|
||||||
|
|
||||||
sys.path.insert(0, os.path.dirname(fp))
|
|
||||||
if 'wpd' in sys.modules:
|
|
||||||
del sys.modules['wpd']
|
|
||||||
import wpd
|
|
||||||
from calibre.constants import plugins
|
|
||||||
plugins._plugins['wpd'] = (wpd, '')
|
|
||||||
sys.path.pop(0)
|
|
||||||
|
|
||||||
# from calibre.devices.mtp.test import run
|
# from calibre.devices.mtp.test import run
|
||||||
# run()
|
# run()
|
||||||
# return
|
# return
|
||||||
|
@ -11,7 +11,7 @@ from collections import namedtuple
|
|||||||
from threading import Lock
|
from threading import Lock
|
||||||
|
|
||||||
from calibre import prints, as_unicode
|
from calibre import prints, as_unicode
|
||||||
from calibre.constants import (iswindows, ismacos, plugins, islinux, isfreebsd,
|
from calibre.constants import (iswindows, ismacos, islinux, isfreebsd,
|
||||||
isnetbsd)
|
isnetbsd)
|
||||||
from polyglot.builtins import range
|
from polyglot.builtins import range
|
||||||
|
|
||||||
@ -60,11 +60,8 @@ class LibUSBScanner(object):
|
|||||||
|
|
||||||
def __call__(self):
|
def __call__(self):
|
||||||
if not hasattr(self, 'libusb'):
|
if not hasattr(self, 'libusb'):
|
||||||
self.libusb, self.libusb_err = plugins['libusb']
|
from calibre_extensions import libusb
|
||||||
if self.libusb is None:
|
self.libusb = libusb
|
||||||
raise ValueError(
|
|
||||||
'DeviceScanner needs libusb to work. Error: %s'%
|
|
||||||
self.libusb_err)
|
|
||||||
|
|
||||||
ans = set()
|
ans = set()
|
||||||
seen = set()
|
seen = set()
|
||||||
@ -172,16 +169,6 @@ if islinux:
|
|||||||
linux_scanner = LinuxScanner()
|
linux_scanner = LinuxScanner()
|
||||||
|
|
||||||
libusb_scanner = LibUSBScanner()
|
libusb_scanner = LibUSBScanner()
|
||||||
if False and ismacos:
|
|
||||||
# Apparently libusb causes mem leaks on some Macs and hangs on others and
|
|
||||||
# works on a few. OS X users will just have to live without MTP support.
|
|
||||||
# See https://bugs.launchpad.net/calibre/+bug/1044706
|
|
||||||
# See https://bugs.launchpad.net/calibre/+bug/1044758
|
|
||||||
# osx_scanner = libusb_scanner
|
|
||||||
usbobserver, usbobserver_err = plugins['usbobserver']
|
|
||||||
if usbobserver is None:
|
|
||||||
raise RuntimeError('Failed to load usbobserver: %s'%usbobserver_err)
|
|
||||||
osx_scanner = usbobserver.get_usb_devices
|
|
||||||
|
|
||||||
if isfreebsd:
|
if isfreebsd:
|
||||||
freebsd_scanner = libusb_scanner
|
freebsd_scanner = libusb_scanner
|
||||||
|
@ -21,12 +21,11 @@ from calibre.constants import DEBUG
|
|||||||
from calibre.devices.interface import DevicePlugin
|
from calibre.devices.interface import DevicePlugin
|
||||||
from calibre.devices.errors import DeviceError
|
from calibre.devices.errors import DeviceError
|
||||||
from calibre.devices.usbms.deviceconfig import DeviceConfig
|
from calibre.devices.usbms.deviceconfig import DeviceConfig
|
||||||
from calibre.constants import iswindows, islinux, ismacos, isfreebsd, plugins
|
from calibre.constants import iswindows, islinux, ismacos, isfreebsd
|
||||||
from calibre.utils.filenames import ascii_filename as sanitize
|
from calibre.utils.filenames import ascii_filename as sanitize
|
||||||
from polyglot.builtins import iteritems, string_or_bytes, map
|
from polyglot.builtins import iteritems, string_or_bytes, map
|
||||||
|
|
||||||
if ismacos:
|
if ismacos:
|
||||||
usbobserver, usbobserver_err = plugins['usbobserver']
|
|
||||||
osx_sanitize_name_pat = re.compile(r'[.-]')
|
osx_sanitize_name_pat = re.compile(r'[.-]')
|
||||||
|
|
||||||
if iswindows:
|
if iswindows:
|
||||||
@ -314,9 +313,8 @@ class Device(DeviceConfig, DevicePlugin):
|
|||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def osx_get_usb_drives(cls):
|
def osx_get_usb_drives(cls):
|
||||||
if usbobserver_err:
|
from calibre_extensions.usbobserver import get_usb_drives
|
||||||
raise RuntimeError('Failed to load usbobserver: '+usbobserver_err)
|
return get_usb_drives()
|
||||||
return usbobserver.get_usb_drives()
|
|
||||||
|
|
||||||
def _osx_bsd_names(self):
|
def _osx_bsd_names(self):
|
||||||
drives = self.osx_get_usb_drives()
|
drives = self.osx_get_usb_drives()
|
||||||
@ -390,9 +388,10 @@ class Device(DeviceConfig, DevicePlugin):
|
|||||||
return drives
|
return drives
|
||||||
|
|
||||||
def open_osx(self):
|
def open_osx(self):
|
||||||
|
from calibre_extensions.usbobserver import get_mounted_filesystems
|
||||||
bsd_drives = self.osx_bsd_names()
|
bsd_drives = self.osx_bsd_names()
|
||||||
drives = self.osx_sort_names(bsd_drives.copy())
|
drives = self.osx_sort_names(bsd_drives.copy())
|
||||||
mount_map = usbobserver.get_mounted_filesystems()
|
mount_map = get_mounted_filesystems()
|
||||||
drives = {k: mount_map.get(v) for k, v in iteritems(drives)}
|
drives = {k: mount_map.get(v) for k, v in iteritems(drives)}
|
||||||
if DEBUG:
|
if DEBUG:
|
||||||
print()
|
print()
|
||||||
|
@ -25,8 +25,8 @@ def do_detach(fork=True, setsid=True, redirect=True):
|
|||||||
if setsid:
|
if setsid:
|
||||||
os.setsid()
|
os.setsid()
|
||||||
if redirect:
|
if redirect:
|
||||||
from calibre.constants import plugins
|
from calibre_extensions.speedup import detach
|
||||||
plugins['speedup'][0].detach(os.devnull)
|
detach(os.devnull)
|
||||||
is_detached = True
|
is_detached = True
|
||||||
|
|
||||||
|
|
||||||
|
@ -29,7 +29,7 @@ def available_translations():
|
|||||||
|
|
||||||
|
|
||||||
def get_system_locale():
|
def get_system_locale():
|
||||||
from calibre.constants import iswindows, ismacos, plugins
|
from calibre.constants import iswindows, ismacos
|
||||||
lang = None
|
lang = None
|
||||||
if iswindows:
|
if iswindows:
|
||||||
try:
|
try:
|
||||||
@ -41,9 +41,10 @@ def get_system_locale():
|
|||||||
except:
|
except:
|
||||||
pass # Windows XP does not have the GetUserDefaultLocaleName fn
|
pass # Windows XP does not have the GetUserDefaultLocaleName fn
|
||||||
elif ismacos:
|
elif ismacos:
|
||||||
|
from calibre_extensions.usbobserver import user_locale
|
||||||
try:
|
try:
|
||||||
lang = plugins['usbobserver'][0].user_locale() or None
|
lang = user_locale() or None
|
||||||
except:
|
except Exception:
|
||||||
# Fallback to environment vars if something bad happened
|
# Fallback to environment vars if something bad happened
|
||||||
import traceback
|
import traceback
|
||||||
traceback.print_exc()
|
traceback.print_exc()
|
||||||
|
@ -14,7 +14,7 @@ from collections import OrderedDict
|
|||||||
from itertools import islice
|
from itertools import islice
|
||||||
|
|
||||||
from calibre import detect_ncpus as cpu_count, as_unicode
|
from calibre import detect_ncpus as cpu_count, as_unicode
|
||||||
from calibre.constants import plugins, filesystem_encoding
|
from calibre.constants import filesystem_encoding
|
||||||
from calibre.utils.icu import primary_sort_key, primary_find, primary_collator
|
from calibre.utils.icu import primary_sort_key, primary_find, primary_collator
|
||||||
from polyglot.builtins import iteritems, itervalues, map, unicode_type, range, zip, raw_input, filter, getcwd
|
from polyglot.builtins import iteritems, itervalues, map, unicode_type, range, zip, raw_input, filter, getcwd
|
||||||
from polyglot.queue import Queue
|
from polyglot.queue import Queue
|
||||||
@ -255,12 +255,8 @@ class CScorer(object):
|
|||||||
level2=DEFAULT_LEVEL2,
|
level2=DEFAULT_LEVEL2,
|
||||||
level3=DEFAULT_LEVEL3
|
level3=DEFAULT_LEVEL3
|
||||||
):
|
):
|
||||||
speedup, err = plugins['matcher']
|
from calibre_extensions.matcher import Matcher
|
||||||
if speedup is None:
|
self.m = Matcher(
|
||||||
raise PluginFailed(
|
|
||||||
'Failed to load the matcher plugin with error: %s' % err
|
|
||||||
)
|
|
||||||
self.m = speedup.Matcher(
|
|
||||||
items,
|
items,
|
||||||
primary_collator().capsule,
|
primary_collator().capsule,
|
||||||
unicode_type(level1), unicode_type(level2), unicode_type(level3)
|
unicode_type(level1), unicode_type(level2), unicode_type(level3)
|
||||||
|
@ -5,13 +5,13 @@
|
|||||||
|
|
||||||
from collections import defaultdict
|
from collections import defaultdict
|
||||||
|
|
||||||
from calibre.constants import plugins
|
|
||||||
from calibre.utils.icu import ord_string
|
from calibre.utils.icu import ord_string
|
||||||
from polyglot.builtins import iteritems
|
from polyglot.builtins import iteritems
|
||||||
|
|
||||||
|
|
||||||
def character_name_from_code(code):
|
def character_name_from_code(code):
|
||||||
return plugins['unicode_names'][0].name_for_codepoint(code) or 'U+{:X}'.format(code)
|
from calibre_extensions.unicode_names import name_for_codepoint
|
||||||
|
return name_for_codepoint(code) or 'U+{:X}'.format(code)
|
||||||
|
|
||||||
|
|
||||||
def html_entities():
|
def html_entities():
|
||||||
@ -35,7 +35,8 @@ def points_for_word(w):
|
|||||||
w = w.lower()
|
w = w.lower()
|
||||||
ans = points_for_word.cache.get(w)
|
ans = points_for_word.cache.get(w)
|
||||||
if ans is None:
|
if ans is None:
|
||||||
ans = plugins['unicode_names'][0].codepoints_for_word(w) | html_entities().get(w, set())
|
from calibre_extensions.unicode_names import codepoints_for_word
|
||||||
|
ans = codepoints_for_word(w) | html_entities().get(w, set())
|
||||||
points_for_word.cache[w] = ans
|
points_for_word.cache[w] = ans
|
||||||
return ans
|
return ans
|
||||||
|
|
||||||
|
@ -10,7 +10,7 @@ from threading import Thread
|
|||||||
|
|
||||||
|
|
||||||
from calibre import guess_type, prints
|
from calibre import guess_type, prints
|
||||||
from calibre.constants import is64bit, isportable, isfrozen, __version__, DEBUG, plugins
|
from calibre.constants import is64bit, isportable, isfrozen, __version__, DEBUG
|
||||||
from calibre.utils.winreg.lib import Key, HKEY_CURRENT_USER, HKEY_LOCAL_MACHINE
|
from calibre.utils.winreg.lib import Key, HKEY_CURRENT_USER, HKEY_LOCAL_MACHINE
|
||||||
from calibre.utils.lock import singleinstance
|
from calibre.utils.lock import singleinstance
|
||||||
from polyglot.builtins import iteritems, itervalues
|
from polyglot.builtins import iteritems, itervalues
|
||||||
@ -131,7 +131,6 @@ def register():
|
|||||||
with Key(r'Software\RegisteredApplications') as key:
|
with Key(r'Software\RegisteredApplications') as key:
|
||||||
key.set(data['name'], capabilities_path)
|
key.set(data['name'], capabilities_path)
|
||||||
|
|
||||||
winutil = plugins['winutil'][0]
|
|
||||||
winutil.notify_associations_changed()
|
winutil.notify_associations_changed()
|
||||||
|
|
||||||
|
|
||||||
@ -228,12 +227,12 @@ def split_commandline(commandline):
|
|||||||
# CommandLineToArgvW returns path to executable if called with empty string.
|
# CommandLineToArgvW returns path to executable if called with empty string.
|
||||||
if not commandline.strip():
|
if not commandline.strip():
|
||||||
return []
|
return []
|
||||||
return list(plugins['winutil'][0].parse_cmdline(commandline))
|
return list(winutil.parse_cmdline(commandline))
|
||||||
|
|
||||||
|
|
||||||
def friendly_app_name(prog_id=None, exe=None):
|
def friendly_app_name(prog_id=None, exe=None):
|
||||||
try:
|
try:
|
||||||
return plugins['winutil'][0].friendly_name(prog_id, exe)
|
return winutil.friendly_name(prog_id, exe)
|
||||||
except Exception:
|
except Exception:
|
||||||
traceback.print_exc()
|
traceback.print_exc()
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user