|
1 | | -from ngcsimlib.utils import make_unique_path, check_attributes, \ |
2 | | - check_serializable, load_from_path, get_compartment_by_name, \ |
3 | | - get_context, add_context, get_current_path, get_current_context, \ |
4 | | - set_new_context, load_module, GuideList, infer_context, Get_Compartment_Batch |
| 1 | +from ngcsimlib.utils import (make_unique_path, check_attributes, \ |
| 2 | + check_serializable, load_from_path, |
| 3 | + get_compartment_by_name, \ |
| 4 | + get_context, add_context, get_current_path, |
| 5 | + get_current_context, \ |
| 6 | + set_new_context, load_module, GuideList, |
| 7 | + infer_context, |
| 8 | + Get_Compartment_Batch, Set_Compartment_Batch) |
5 | 9 | from ngcsimlib.logger import warn, info, critical |
6 | 10 | from ngcsimlib import preload_modules |
7 | 11 | from ngcsimlib.compilers import dynamic_compile, wrap_command |
@@ -74,7 +78,8 @@ def __init__(self, name, should_validate=None): |
74 | 78 | self.path = get_current_path() + "/" + str(name) |
75 | 79 | self._last_context = "" |
76 | 80 |
|
77 | | - self._json_objects = {"ops": [], "components": {}, "commands": {}, "processes" : []} |
| 81 | + self._json_objects = {"ops": [], "components": {}, "commands": {}, |
| 82 | + "processes": []} |
78 | 83 |
|
79 | 84 | if should_validate is None: |
80 | 85 | _base_config = get_config("context") |
@@ -204,8 +209,6 @@ def register_component(self, component, *args, **kwargs): |
204 | 209 | def register_process(self, process): |
205 | 210 | self._json_objects['processes'].append(process) |
206 | 211 |
|
207 | | - |
208 | | - |
209 | 212 | def add_component(self, component): |
210 | 213 | """ |
211 | 214 | Adds a component to the context if it does not exist already in the |
@@ -371,7 +374,6 @@ def load_from_dir(self, directory, custom_folder="/custom"): |
371 | 374 | self.make_commands(directory + "/commands.json") |
372 | 375 | self.make_process(directory + "/processes.json") |
373 | 376 |
|
374 | | - |
375 | 377 | def make_components(self, path_to_components_file, custom_file_dir=None): |
376 | 378 | """ |
377 | 379 | Loads a collection of components from a json file. Follow |
@@ -649,9 +651,16 @@ def view_guide(self, guide, skip=None): |
649 | 651 | guides += klass.guides.__dict__[guide.value] |
650 | 652 | return guides |
651 | 653 |
|
652 | | - def get_current_state(self): |
| 654 | + def _get_state_keys(self): |
653 | 655 | all_keys = [] |
654 | 656 | for comp_name in self.components.keys(): |
655 | 657 | all_keys.extend([key for key in Get_Compartment_Batch().keys() |
656 | 658 | if self.path + "/" + comp_name in key]) |
657 | | - return Get_Compartment_Batch(all_keys) |
| 659 | + return all_keys |
| 660 | + |
| 661 | + def get_current_state(self): |
| 662 | + return Get_Compartment_Batch(self._get_state_keys()) |
| 663 | + |
| 664 | + def update_current_state(self, state): |
| 665 | + Set_Compartment_Batch({key: value for key, value in state.items() if key in self._get_state_keys()}) |
| 666 | + |
0 commit comments