mirror of
				https://github.com/kovidgoyal/calibre.git
				synced 2025-11-04 03:27:00 -05: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:
 | 
			
		||||
    from calibre_extensions import winutil
 | 
			
		||||
    try:
 | 
			
		||||
        config_dir = winutil.special_folder_path(plugins['winutil'][0].CSIDL_APPDATA)
 | 
			
		||||
        config_dir = winutil.special_folder_path(winutil.CSIDL_APPDATA)
 | 
			
		||||
    except ValueError:
 | 
			
		||||
        config_dir = None
 | 
			
		||||
    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
 | 
			
		||||
    from contextlib import suppress
 | 
			
		||||
    from calibre.constants import (__appname__, get_version, isportable, ismacos,
 | 
			
		||||
                                   isfrozen, is64bit, plugins)
 | 
			
		||||
                                   isfrozen, is64bit)
 | 
			
		||||
    from calibre.utils.localization import set_translators
 | 
			
		||||
    out(__appname__, get_version(), 'Portable' if isportable else '',
 | 
			
		||||
        'embedded-python:', isfrozen, 'is64bit:', is64bit)
 | 
			
		||||
    out(platform.platform(), platform.system(), platform.architecture())
 | 
			
		||||
    if iswindows and not is64bit:
 | 
			
		||||
        from calibre_extensions.winutil import is_wow64_process
 | 
			
		||||
        with suppress(Exception):
 | 
			
		||||
            if plugins['winutil'][0].is_wow64_process():
 | 
			
		||||
            if is_wow64_process():
 | 
			
		||||
                out('32bit process running on 64bit windows')
 | 
			
		||||
    out(platform.system_alias(platform.system(), platform.release(),
 | 
			
		||||
            platform.version()))
 | 
			
		||||
 | 
			
		||||
@ -305,13 +305,6 @@ class Bookmark():  # {{{
 | 
			
		||||
                    self.book_length = mu.book_length
 | 
			
		||||
            except:
 | 
			
		||||
                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:
 | 
			
		||||
            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.
 | 
			
		||||
        try:
 | 
			
		||||
            if DEBUG:
 | 
			
		||||
                from calibre.constants import plugins
 | 
			
		||||
                usbobserver, usbobserver_err = plugins['usbobserver']
 | 
			
		||||
                mount_map = usbobserver.get_mounted_filesystems()
 | 
			
		||||
                from calibre_extensions.usbobserver import get_mounted_filesystems
 | 
			
		||||
                mount_map = get_mounted_filesystems()
 | 
			
		||||
                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._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 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.devices.errors import OpenFailed, DeviceError, BlacklistedDevice
 | 
			
		||||
from calibre.devices.mtp.base import MTPDeviceBase, debug
 | 
			
		||||
@ -63,7 +63,12 @@ class MTP_DEVICE(MTPDeviceBase):
 | 
			
		||||
            self.wpd = None
 | 
			
		||||
            self.wpd_error = _('MTP devices are not supported on Windows XP')
 | 
			
		||||
        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:
 | 
			
		||||
            try:
 | 
			
		||||
                self.wpd.init(__appname__, *(numeric_version[:3]))
 | 
			
		||||
 | 
			
		||||
@ -6,7 +6,7 @@ __license__   = 'GPL v3'
 | 
			
		||||
__copyright__ = '2012, Kovid Goyal <kovid at kovidgoyal.net>'
 | 
			
		||||
__docformat__ = 'restructuredtext en'
 | 
			
		||||
 | 
			
		||||
import subprocess, sys, os, pprint, signal, time, glob, io
 | 
			
		||||
import subprocess, os, pprint, signal, time, glob, io
 | 
			
		||||
pprint, io
 | 
			
		||||
from polyglot.builtins import environ_item
 | 
			
		||||
 | 
			
		||||
@ -48,14 +48,6 @@ def main():
 | 
			
		||||
        subprocess.call(['calibre-debug', '-e', fp], env=env)
 | 
			
		||||
        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
 | 
			
		||||
    # run()
 | 
			
		||||
    # return
 | 
			
		||||
 | 
			
		||||
@ -11,7 +11,7 @@ from collections import namedtuple
 | 
			
		||||
from threading import Lock
 | 
			
		||||
 | 
			
		||||
from calibre import prints, as_unicode
 | 
			
		||||
from calibre.constants import (iswindows, ismacos, plugins, islinux, isfreebsd,
 | 
			
		||||
from calibre.constants import (iswindows, ismacos, islinux, isfreebsd,
 | 
			
		||||
        isnetbsd)
 | 
			
		||||
from polyglot.builtins import range
 | 
			
		||||
 | 
			
		||||
@ -60,11 +60,8 @@ class LibUSBScanner(object):
 | 
			
		||||
 | 
			
		||||
    def __call__(self):
 | 
			
		||||
        if not hasattr(self, 'libusb'):
 | 
			
		||||
            self.libusb, self.libusb_err = plugins['libusb']
 | 
			
		||||
            if self.libusb is None:
 | 
			
		||||
                raise ValueError(
 | 
			
		||||
                    'DeviceScanner needs libusb to work. Error: %s'%
 | 
			
		||||
                    self.libusb_err)
 | 
			
		||||
            from calibre_extensions import libusb
 | 
			
		||||
            self.libusb = libusb
 | 
			
		||||
 | 
			
		||||
        ans = set()
 | 
			
		||||
        seen = set()
 | 
			
		||||
@ -172,16 +169,6 @@ if islinux:
 | 
			
		||||
    linux_scanner = LinuxScanner()
 | 
			
		||||
 | 
			
		||||
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:
 | 
			
		||||
    freebsd_scanner = libusb_scanner
 | 
			
		||||
 | 
			
		||||
@ -21,12 +21,11 @@ from calibre.constants import DEBUG
 | 
			
		||||
from calibre.devices.interface import DevicePlugin
 | 
			
		||||
from calibre.devices.errors import DeviceError
 | 
			
		||||
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 polyglot.builtins import iteritems, string_or_bytes, map
 | 
			
		||||
 | 
			
		||||
if ismacos:
 | 
			
		||||
    usbobserver, usbobserver_err = plugins['usbobserver']
 | 
			
		||||
    osx_sanitize_name_pat = re.compile(r'[.-]')
 | 
			
		||||
 | 
			
		||||
if iswindows:
 | 
			
		||||
@ -314,9 +313,8 @@ class Device(DeviceConfig, DevicePlugin):
 | 
			
		||||
 | 
			
		||||
    @classmethod
 | 
			
		||||
    def osx_get_usb_drives(cls):
 | 
			
		||||
        if usbobserver_err:
 | 
			
		||||
            raise RuntimeError('Failed to load usbobserver: '+usbobserver_err)
 | 
			
		||||
        return usbobserver.get_usb_drives()
 | 
			
		||||
        from calibre_extensions.usbobserver import get_usb_drives
 | 
			
		||||
        return get_usb_drives()
 | 
			
		||||
 | 
			
		||||
    def _osx_bsd_names(self):
 | 
			
		||||
        drives = self.osx_get_usb_drives()
 | 
			
		||||
@ -390,9 +388,10 @@ class Device(DeviceConfig, DevicePlugin):
 | 
			
		||||
        return drives
 | 
			
		||||
 | 
			
		||||
    def open_osx(self):
 | 
			
		||||
        from calibre_extensions.usbobserver import get_mounted_filesystems
 | 
			
		||||
        bsd_drives = self.osx_bsd_names()
 | 
			
		||||
        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)}
 | 
			
		||||
        if DEBUG:
 | 
			
		||||
            print()
 | 
			
		||||
 | 
			
		||||
@ -25,8 +25,8 @@ def do_detach(fork=True, setsid=True, redirect=True):
 | 
			
		||||
    if setsid:
 | 
			
		||||
        os.setsid()
 | 
			
		||||
    if redirect:
 | 
			
		||||
        from calibre.constants import plugins
 | 
			
		||||
        plugins['speedup'][0].detach(os.devnull)
 | 
			
		||||
        from calibre_extensions.speedup import detach
 | 
			
		||||
        detach(os.devnull)
 | 
			
		||||
    is_detached = True
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -29,7 +29,7 @@ def available_translations():
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
def get_system_locale():
 | 
			
		||||
    from calibre.constants import iswindows, ismacos, plugins
 | 
			
		||||
    from calibre.constants import iswindows, ismacos
 | 
			
		||||
    lang = None
 | 
			
		||||
    if iswindows:
 | 
			
		||||
        try:
 | 
			
		||||
@ -41,9 +41,10 @@ def get_system_locale():
 | 
			
		||||
        except:
 | 
			
		||||
            pass  # Windows XP does not have the GetUserDefaultLocaleName fn
 | 
			
		||||
    elif ismacos:
 | 
			
		||||
        from calibre_extensions.usbobserver import user_locale
 | 
			
		||||
        try:
 | 
			
		||||
            lang = plugins['usbobserver'][0].user_locale() or None
 | 
			
		||||
        except:
 | 
			
		||||
            lang = user_locale() or None
 | 
			
		||||
        except Exception:
 | 
			
		||||
            # Fallback to environment vars if something bad happened
 | 
			
		||||
            import traceback
 | 
			
		||||
            traceback.print_exc()
 | 
			
		||||
 | 
			
		||||
@ -14,7 +14,7 @@ from collections import OrderedDict
 | 
			
		||||
from itertools import islice
 | 
			
		||||
 | 
			
		||||
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 polyglot.builtins import iteritems, itervalues, map, unicode_type, range, zip, raw_input, filter, getcwd
 | 
			
		||||
from polyglot.queue import Queue
 | 
			
		||||
@ -255,12 +255,8 @@ class CScorer(object):
 | 
			
		||||
        level2=DEFAULT_LEVEL2,
 | 
			
		||||
        level3=DEFAULT_LEVEL3
 | 
			
		||||
    ):
 | 
			
		||||
        speedup, err = plugins['matcher']
 | 
			
		||||
        if speedup is None:
 | 
			
		||||
            raise PluginFailed(
 | 
			
		||||
                'Failed to load the matcher plugin with error: %s' % err
 | 
			
		||||
            )
 | 
			
		||||
        self.m = speedup.Matcher(
 | 
			
		||||
        from calibre_extensions.matcher import Matcher
 | 
			
		||||
        self.m = Matcher(
 | 
			
		||||
            items,
 | 
			
		||||
            primary_collator().capsule,
 | 
			
		||||
            unicode_type(level1), unicode_type(level2), unicode_type(level3)
 | 
			
		||||
 | 
			
		||||
@ -5,13 +5,13 @@
 | 
			
		||||
 | 
			
		||||
from collections import defaultdict
 | 
			
		||||
 | 
			
		||||
from calibre.constants import plugins
 | 
			
		||||
from calibre.utils.icu import ord_string
 | 
			
		||||
from polyglot.builtins import iteritems
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
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():
 | 
			
		||||
@ -35,7 +35,8 @@ def points_for_word(w):
 | 
			
		||||
    w = w.lower()
 | 
			
		||||
    ans = points_for_word.cache.get(w)
 | 
			
		||||
    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
 | 
			
		||||
    return ans
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -10,7 +10,7 @@ from threading import Thread
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
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.lock import singleinstance
 | 
			
		||||
from polyglot.builtins import iteritems, itervalues
 | 
			
		||||
@ -131,7 +131,6 @@ def register():
 | 
			
		||||
        with Key(r'Software\RegisteredApplications') as key:
 | 
			
		||||
            key.set(data['name'], capabilities_path)
 | 
			
		||||
 | 
			
		||||
    winutil = plugins['winutil'][0]
 | 
			
		||||
    winutil.notify_associations_changed()
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -228,12 +227,12 @@ def split_commandline(commandline):
 | 
			
		||||
    # CommandLineToArgvW returns path to executable if called with empty string.
 | 
			
		||||
    if not commandline.strip():
 | 
			
		||||
        return []
 | 
			
		||||
    return list(plugins['winutil'][0].parse_cmdline(commandline))
 | 
			
		||||
    return list(winutil.parse_cmdline(commandline))
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
def friendly_app_name(prog_id=None, exe=None):
 | 
			
		||||
    try:
 | 
			
		||||
        return plugins['winutil'][0].friendly_name(prog_id, exe)
 | 
			
		||||
        return winutil.friendly_name(prog_id, exe)
 | 
			
		||||
    except Exception:
 | 
			
		||||
        traceback.print_exc()
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user