mirror of
https://github.com/volatilityfoundation/volatility3.git
synced 2026-09-28 20:44:52 +02:00
Refactor the way that plugins are imported for use on other modules (such as the upcoming automagic).
This commit is contained in:
@@ -1,34 +0,0 @@
|
||||
# TODO: Code to import all the py/pyc files available (but not both).
|
||||
# TODO: Code to return a none-instantiated list of plugin classes.
|
||||
|
||||
import logging
|
||||
import os
|
||||
import sys
|
||||
|
||||
import volatility.plugins as plugins
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
def import_plugins():
|
||||
"""Imports all plugins present under plugins path"""
|
||||
if not isinstance(plugins.__path__, list):
|
||||
raise TypeError("Plugins.__path__ must be a list of paths")
|
||||
for path in plugins.__path__:
|
||||
for root, _, files in os.walk(path, followlinks = True):
|
||||
# TODO: Figure out how to import pycache files
|
||||
if root.endswith("__pycache__"):
|
||||
continue
|
||||
for f in files:
|
||||
if (f.endswith(".py") or f.endswith(".pyc") or f.endswith(".pyo")) and not f.startswith("__"):
|
||||
path = os.path.join(root[len(path) + len(os.path.sep):], f[:f.rfind(".")])
|
||||
module = path.replace(os.path.sep, ".")
|
||||
if module not in sys.modules:
|
||||
try:
|
||||
logging.debug("Importing volatility.plugins." + str(module))
|
||||
__import__("volatility.plugins." + str(module))
|
||||
except ImportError:
|
||||
logger.warning("Failed to import module " + str(module) + " based on file " + path)
|
||||
raise
|
||||
else:
|
||||
logger.info("Skipping existing module " + str(module))
|
||||
|
||||
Reference in New Issue
Block a user