Raiff1982 commited on
Commit
8b454da
Β·
verified Β·
1 Parent(s): c3da1bd

Update modules/secure_memory_loader.py

Browse files
Files changed (1) hide show
  1. modules/secure_memory_loader.py +25 -8
modules/secure_memory_loader.py CHANGED
@@ -1,16 +1,33 @@
1
  import importlib.util
2
  from pathlib import Path
 
3
 
4
- def load_secure_memory_module(temp_path = "./modules/secure_memory.py"):
 
 
 
5
  """
6
- Dynamically loads secure_memory.py from a temporary path.
7
- Returns the module object.
8
  """
 
9
  secure_memory = Path(temp_path)
10
  if not secure_memory.exists():
11
- raise FileNotFoundError(f"{temp_path} not found.")
 
 
 
 
 
 
 
 
 
 
12
 
13
- spec = importlib.util.spec_from_file_location("secure_memory", temp_path)
14
- module = importlib.util.module_from_spec(spec)
15
- spec.loader.exec_module(module)
16
- return module
 
 
 
1
  import importlib.util
2
  from pathlib import Path
3
+ import logging
4
 
5
+ # Configure logging for better debugging
6
+ logging.basicConfig(level=logging.INFO, format="%(asctime)s - %(levelname)s - %(message)s")
7
+
8
+ def load_secure_memory_module(temp_path="./modules/secure_memory.py"):
9
  """
10
+ Dynamically loads secure_memory.py from a specified path.
11
+ Returns the module object if successful.
12
  """
13
+ # Validate the file path
14
  secure_memory = Path(temp_path)
15
  if not secure_memory.exists():
16
+ logging.error(f"File not found at specified path: {temp_path}")
17
+ raise FileNotFoundError(f"File not found: {temp_path}")
18
+
19
+ # Log the loading process
20
+ logging.info(f"Loading secure_memory module from: {temp_path}")
21
+
22
+ try:
23
+ # Create a module specification and load it dynamically
24
+ spec = importlib.util.spec_from_file_location("secure_memory", temp_path)
25
+ module = importlib.util.module_from_spec(spec)
26
+ spec.loader.exec_module(module)
27
 
28
+ # Log success and return the module
29
+ logging.info("secure_memory module successfully loaded.")
30
+ return module
31
+ except Exception as e:
32
+ logging.error(f"Failed to load secure_memory module: {e}")
33
+ raise RuntimeError(f"Error while loading secure_memory module: {e}")