File size: 1,281 Bytes
e13f1f7
fce27c6
8b454da
e13f1f7
8b454da
 
 
 
fce27c6
8b454da
 
fce27c6
8b454da
fce27c6
 
8b454da
 
 
 
 
 
 
 
 
 
 
e13f1f7
8b454da
 
 
 
 
 
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
import importlib.util
from pathlib import Path
import logging

# Configure logging for better debugging
logging.basicConfig(level=logging.INFO, format="%(asctime)s - %(levelname)s - %(message)s")

def load_secure_memory_module(temp_path="./modules/secure_memory.py"):
    """
    Dynamically loads secure_memory.py from a specified path.
    Returns the module object if successful.
    """
    # Validate the file path
    secure_memory = Path(temp_path)
    if not secure_memory.exists():
        logging.error(f"File not found at specified path: {temp_path}")
        raise FileNotFoundError(f"File not found: {temp_path}")

    # Log the loading process
    logging.info(f"Loading secure_memory module from: {temp_path}")

    try:
        # Create a module specification and load it dynamically
        spec = importlib.util.spec_from_file_location("secure_memory", temp_path)
        module = importlib.util.module_from_spec(spec)
        spec.loader.exec_module(module)

        # Log success and return the module
        logging.info("secure_memory module successfully loaded.")
        return module
    except Exception as e:
        logging.error(f"Failed to load secure_memory module: {e}")
        raise RuntimeError(f"Error while loading secure_memory module: {e}")