#Load mods
#Imported in C++ as file_load_py_main
#Automatically copied into modules/BLPython/bootstrap.py if file does not already exist
#This file can be edited without being overwritten. It can be deleted if it needs to be restored.

#todo: catch module exceptions (will quit program if a module has an exception

import BLpython
import sys
from pathlib import Path
import zipimport

try:
	path = Path("modules/BLpython/")

	for zip_plugin in path.glob("*.zip"):
		try:
			zip_plugin_str = str(zip_plugin)
			BLpython.BlPrint('      [ Importing \'main\' from: '+ zip_plugin_str +' ]')
			importer = zipimport.zipimporter(zip_plugin)

			basename = zip_plugin.stem #a/b/c/d.zip -> d

			#load_module is deprecated but no alternative code worked

			plugin_module = importer.load_module(basename)

			#importer.exec_module(plugin_module)

			#BLpython.BlPrint(str(mod.__name__))
			#BLpython.BlPrint(str(mod.__file__))
			#BLpython.BlPrint(str(mod.__loader__))
		except:
			type, value, traceback = sys.exc_info()
			BLpython.BlPrint('            Module import exception: '+ str(value))
except:
	type, value, traceback = sys.exc_info()
	BLpython.BlPrint('Exception: '+ str(value))


