diff --git a/esds/helpers/platform.py b/esds/helpers/platform.py index 341baed..a811398 100644 --- a/esds/helpers/platform.py +++ b/esds/helpers/platform.py @@ -1,5 +1,5 @@ -import yaml, os +import yaml, os, importlib import numpy as np class UnitsParser: @@ -195,3 +195,12 @@ class YAMLPlatformFile: if type(general["interferences"]) != bool: self.parsing_error("interferences should be on or off") self.default["interferences"]=general["interferences"] + + def run(self): + callback=None + ##### First load callback from file if any + if self.default["breakpoints_file"] != None: + module, ext=os.path.splitext(self.default["breakpoints_file"]) + imported=importlib.import_module(module) + callback=getattr(imported, self.default["breakpoints_callback"]) + pass diff --git a/example/platform.yaml b/example/platform.yaml index 45c6685..1f9eae5 100644 --- a/example/platform.yaml +++ b/example/platform.yaml @@ -7,7 +7,7 @@ general: breakpoints_every: 0 # Define the callback to call when the simulator reach a breakpoint breakpoints_callback: - file: "platform_test.py" + file: "platform_callback.py" callback: "callback" # Turn on/off the debugging of esds debug: off diff --git a/example/platform_callback.py b/example/platform_callback.py new file mode 100644 index 0000000..b8a87d0 --- /dev/null +++ b/example/platform_callback.py @@ -0,0 +1,6 @@ + + + + +def callback(simulator): + print("Called :)") \ No newline at end of file diff --git a/example/platform_test.py b/example/platform_test.py index ccc9a98..2573b32 100755 --- a/example/platform_test.py +++ b/example/platform_test.py @@ -4,4 +4,5 @@ from esds.helpers.platform import YAMLPlatformFile -simulator=YAMLPlatformFile("platform.yaml") \ No newline at end of file +s=YAMLPlatformFile("platform.yaml") +s.run() \ No newline at end of file