Load modules from .zip file.
This commit is contained in:
parent
cfeba7a49f
commit
fcbace28b4
1 changed files with 19 additions and 2 deletions
|
@ -4,17 +4,34 @@
|
||||||
Functions to load plugin modules.
|
Functions to load plugin modules.
|
||||||
"""
|
"""
|
||||||
import os
|
import os
|
||||||
|
import sys
|
||||||
|
import zipfile
|
||||||
import importlib
|
import importlib
|
||||||
|
|
||||||
|
|
||||||
|
def is_frozen ():
|
||||||
|
"""Return True if running inside a py2exe-generated executable."""
|
||||||
|
return hasattr(sys, "frozen")
|
||||||
|
|
||||||
|
|
||||||
def get_modules(folder='plugins'):
|
def get_modules(folder='plugins'):
|
||||||
"""Find all valid modules in the plugins subdirectory. A valid module
|
"""Find all valid modules in the plugins subdirectory. A valid module
|
||||||
must have a .py extension, and is importable.
|
must have a .py extension, and is importable.
|
||||||
@return: all loaded valid modules
|
@return: all loaded valid modules
|
||||||
@rtype: iterator of module
|
@rtype: iterator of module
|
||||||
"""
|
"""
|
||||||
|
if is_frozen():
|
||||||
|
# find modules in library.zip filename
|
||||||
|
zipname = os.path.dirname(os.path.dirname(__file__))
|
||||||
|
with zipfile.ZipFile(zipname, 'r') as f:
|
||||||
|
modnames = [os.path.splitext(n[17:])[0]
|
||||||
|
for n in f.namelist()
|
||||||
|
if n.startswith("dosagelib/%s" % folder)
|
||||||
|
and "__init__" not in n]
|
||||||
|
else:
|
||||||
dirname = os.path.join(os.path.dirname(__file__), folder)
|
dirname = os.path.join(os.path.dirname(__file__), folder)
|
||||||
for modname in get_importable_modules(dirname):
|
modnames = get_importable_modules(dirname)
|
||||||
|
for modname in modnames:
|
||||||
try:
|
try:
|
||||||
name ="..%s.%s" % (folder, modname)
|
name ="..%s.%s" % (folder, modname)
|
||||||
yield importlib.import_module(name, __name__)
|
yield importlib.import_module(name, __name__)
|
||||||
|
|
Loading…
Reference in a new issue