forked from ZclassicCommunity/electrum-zclassic
-
Notifications
You must be signed in to change notification settings - Fork 1
/
pyi_runtimehook.py
88 lines (71 loc) · 2.44 KB
/
pyi_runtimehook.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
# -*- coding: utf-8 -*-
"""PyInstaller runtime hook"""
import imp
import sys
import pkgutil
_old_find_module = imp.find_module
def _new_find_module(name, *args, **kwargs):
if name in ['lib', 'gui', 'plugins']:
return (None, name, ('', '', 5))
else:
return _old_find_module(name, *args, **kwargs)
imp.find_module = _new_find_module
_old_load_module = imp.load_module
def _new_load_module(name, file, pathname, description):
if pathname in ['lib', 'gui', 'plugins']:
return __import__(name)
else:
return _old_load_module(name, file, pathname, description)
imp.load_module = _new_load_module
PLUGINS_PREFIX = 'electrum_bitcoinprivate_plugins'
KEYSTORE_PLUGINS = [
'hw_wallet',
'digitalbitbox',
'keepkey',
'ledger',
'trezor',
]
OTHER_PLUGINS= [
'audio_modem',
'cosigner_pool',
'email_requests',
'labels',
'virtualkeyboard',
]
OTHER_PLUGINS = list(map(lambda p: '%s.%s' % (PLUGINS_PREFIX, p), OTHER_PLUGINS))
PLUGINS = KEYSTORE_PLUGINS + OTHER_PLUGINS
class PluginsImporter(object):
def find_module(self, name):
return self
def load_module(self, name):
if name in KEYSTORE_PLUGINS:
return getattr(__import__('%s.%s' % (PLUGINS_PREFIX, name)), name)
elif name in OTHER_PLUGINS:
return getattr(__import__(name), name.split('.')[-1])
elif name.endswith('.qt'):
split = name.split('.')
if split[0] != split[1]:
plugin_module = getattr(__import__(name), split[-2])
return getattr(plugin_module, 'qt')
else:
path = '.'.join(split[1:])
plugin_module = getattr(__import__(path), split[-2])
return getattr(plugin_module, 'qt')
else:
raise Exception('Can not import %s' % name)
_old_find_loader = pkgutil.find_loader
def _new_find_loader(fullname):
if fullname.startswith('%s.' % PLUGINS_PREFIX):
return PluginsImporter()
else:
return _old_find_loader(fullname)
pkgutil.find_loader = _new_find_loader
_old_iter_modules = pkgutil.iter_modules
def _new_iter_modules(path=None, prefix=''):
if path and len(path) == 1 and path[0].endswith(PLUGINS_PREFIX):
for p in PLUGINS:
yield PluginsImporter(), p, True
else:
for loader, name, ispkg in _old_iter_modules(path, prefix):
yield loader, name, ispkg
pkgutil.iter_modules = _new_iter_modules