DUNE-DAQ
DUNE Trigger and Data Acquisition software
Loading...
Searching...
No Matches
cider.widgets.configuration_controller.ConfigurationController Class Reference
Inheritance diagram for cider.widgets.configuration_controller.ConfigurationController:
[legend]
Collaboration diagram for cider.widgets.configuration_controller.ConfigurationController:
[legend]

Classes

class  Changed
 

Public Member Functions

 on_mount (self)
 
 select_new_dal_from_id (self, str new_id, str new_class)
 
 current_dal (self)
 
 current_dal (self, new_dal)
 
 update_configuration (self, attr_name, update_value)
 
 new_handler_from_str (self, str file_name)
 
StructuredConfiguration|None handler (self)
 
 handler (self, StructuredConfiguration new_handler)
 
 configuration (self)
 
str generate_rich_string (cls, dal_obj, bool obj_disabled=False)
 
 get_interface (self)
 
None add_interface (self, str interface_label)
 
None commit_configuration (self, str message)
 
None rename_dal (self, str new_name)
 
 add_new_conf_obj (self, str class_id, str uid)
 
 destroy_conf_obj (self, str class_id, str uid)
 
 destroy_current_object (self)
 
bool can_be_disabled (self)
 
None toggle_disable_conf_obj (self, selection_menu)
 
list get_all_sessions (self)
 
list is_selected_object_enabled (self)
 
 modify_current_dal_relationship (self, str relationship_name, updated_value, bool append=False)
 
 remove_current_dal_relationship (self, relationship_name)
 
 pop_dal_relationship (self, relationship_name, dal_to_remove)
 
 get_dals_of_class (self, str dal_class)
 
 get_list_of_classes (self)
 
 get_relations_to_current_dal (self)
 
 get_relation_category_in_current_dal (self, str relation_name)
 

Public Attributes

 current_dal
 

Static Public Attributes

list BINDINGS = [("ctrl+s", "save_configuration", "Save Configuration")]
 

Protected Attributes

 _logger = self.app.query_one("RichLogWError")
 

Static Protected Attributes

StructuredConfiguration _handler = None
 
dict _selection_interfaces = {}
 
StructuredConfiguration|None _current_selected_object = None
 

Private Member Functions

 __no_handler_check (self)
 

Detailed Description

Controller widget for the full configuration. In principal this is 
where all communication with the configuration is actually done!

Definition at line 13 of file configuration_controller.py.

Member Function Documentation

◆ __no_handler_check()

cider.widgets.configuration_controller.ConfigurationController.__no_handler_check ( self)
private
Raise error if no handler is setup

Definition at line 226 of file configuration_controller.py.

226 def __no_handler_check(self):
227 """Raise error if no handler is setup"""
228 if self._handler is None:
229 self._logger.write_error("Handler not initialised, this could be")
230

◆ add_interface()

None cider.widgets.configuration_controller.ConfigurationController.add_interface ( self,
str interface_label )

Definition at line 132 of file configuration_controller.py.

132 def add_interface(self, interface_label: str)->None:
133 self.__no_handler_check()
134 self._selection_interfaces[interface_label]= \
135 SelectionInterfaceFactory.get_interface(interface_label, self._handler)
136

◆ add_new_conf_obj()

cider.widgets.configuration_controller.ConfigurationController.add_new_conf_obj ( self,
str class_id,
str uid )
Add new object to configuration

Definition at line 150 of file configuration_controller.py.

150 def add_new_conf_obj(self, class_id: str, uid: str):
151 """Add new object to configuration
152 """
153 self._handler.configuration_handler.add_new_conf_obj(class_id, uid)
154 self._logger.write(f"[green]Added new configuration object[/green] [red]{class_id}[/red]@[yellow]{uid}[/yellow]")
155

◆ can_be_disabled()

bool cider.widgets.configuration_controller.ConfigurationController.can_be_disabled ( self)
Check if current object is capable of being disabled

Returns:
    bool -- True if object can be disabled

Definition at line 167 of file configuration_controller.py.

167 def can_be_disabled(self)->bool:
168 """Check if current object is capable of being disabled
169
170 Returns:
171 bool -- True if object can be disabled
172 """
173 if self._current_selected_object is None:
174 self._logger.write_error("No object selected")
175 return False
176
177 if self._current_selected_object not in self._handler.configuration_handler.get_all_conf_classes()['Component']:
178 self._logger.write_error(f"Cannot disable {self.generate_rich_string(self._current_selected_object)} must inherit from [red]Component[/red]!")
179 return False
180
181 return True
182
183

◆ commit_configuration()

None cider.widgets.configuration_controller.ConfigurationController.commit_configuration ( self,
str message )
Save configuration with a message to database

Definition at line 138 of file configuration_controller.py.

138 def commit_configuration(self, message: str)->None:
139 """Save configuration with a message to database
140 """
141 self._handler.configuration_handler.commit(message)
142 self._logger.write(f"[green]Saved configuration with message:[/green] [red]{message}[/red]")
143

◆ configuration()

cider.widgets.configuration_controller.ConfigurationController.configuration ( self)
Return current configuration

Returns:
    Access the raw configuration

Definition at line 104 of file configuration_controller.py.

104 def configuration(self):
105 """Return current configuration
106
107 Returns:
108 Access the raw configuration
109 """
110 self.__no_handler_check()
111
112 return self._handler.configuration_handler.configuration
113

◆ current_dal() [1/2]

cider.widgets.configuration_controller.ConfigurationController.current_dal ( self)
Get current selected dal

Definition at line 38 of file configuration_controller.py.

38 def current_dal(self):
39 """Get current selected dal
40 """
41 return self._current_selected_object
42

◆ current_dal() [2/2]

cider.widgets.configuration_controller.ConfigurationController.current_dal ( self,
new_dal )
Set the current dal via a pre-existing dal

Arguments:
    new_dal -- New dal object

Definition at line 44 of file configuration_controller.py.

44 def current_dal(self, new_dal):
45 """Set the current dal via a pre-existing dal
46
47 Arguments:
48 new_dal -- New dal object
49 """
50 if new_dal!=self._current_selected_object:
51 self._current_selected_object=new_dal
52 self.post_message(self.Changed(self._current_selected_object))
53

◆ destroy_conf_obj()

cider.widgets.configuration_controller.ConfigurationController.destroy_conf_obj ( self,
str class_id,
str uid )
Destroy object in configuration

Definition at line 156 of file configuration_controller.py.

156 def destroy_conf_obj(self, class_id: str, uid: str):
157 """Destroy object in configuration
158 """
159 self._handler.configuration_handler.destroy_conf_obj(class_id, uid)
160 self._logger.write(f"[green]Destroyed configuration object[/green] [red]{class_id}[/red]@[yellow]{uid}[/yellow]")
161

◆ destroy_current_object()

cider.widgets.configuration_controller.ConfigurationController.destroy_current_object ( self)

Definition at line 162 of file configuration_controller.py.

162 def destroy_current_object(self):
163 if self.current_dal is not None:
164 self.destroy_conf_obj(self.current_dal.className(), getattr(self.current_dal, 'id'))
165 # self.current_dal = None
166

◆ generate_rich_string()

str cider.widgets.configuration_controller.ConfigurationController.generate_rich_string ( cls,
dal_obj,
bool obj_disabled = False )
Generate a rich string for a DAL object, shouldn't live here but :shrug:

Definition at line 115 of file configuration_controller.py.

115 def generate_rich_string(cls, dal_obj, obj_disabled: bool=False)->str:
116 """Generate a rich string for a DAL object, shouldn't live here but :shrug:"""
117 if obj_disabled:
118 return f"[grey]{getattr(dal_obj, 'id')}[/grey]@[grey]{dal_obj.className()}[/grey] [bold red]DISABLED[/bold red]"
119 else:
120 return f"[yellow]{getattr(dal_obj, 'id')}[/yellow]@[green]{dal_obj.className()}[/green]"
121
122

◆ get_all_sessions()

list cider.widgets.configuration_controller.ConfigurationController.get_all_sessions ( self)

Definition at line 217 of file configuration_controller.py.

217 def get_all_sessions(self)->list:
218 return [top_object for top_object in self._handler.relational_graph.top_level_nodes\
219 if top_object.className() == "Session"]
220

◆ get_dals_of_class()

cider.widgets.configuration_controller.ConfigurationController.get_dals_of_class ( self,
str dal_class )

Definition at line 276 of file configuration_controller.py.

276 def get_dals_of_class(self, dal_class: str):
277 return self._handler.configuration_handler.get_conf_objects_class(dal_class)
278

◆ get_interface()

cider.widgets.configuration_controller.ConfigurationController.get_interface ( self)
get all interface objects. The interface defines an "ordering" for objects
in the configuration

Returns:
    dict{interfaces}

Definition at line 123 of file configuration_controller.py.

123 def get_interface(self):
124 """get all interface objects. The interface defines an "ordering" for objects
125 in the configuration
126
127 Returns:
128 dict{interfaces}
129 """
130 return self._selection_interfaces
131

◆ get_list_of_classes()

cider.widgets.configuration_controller.ConfigurationController.get_list_of_classes ( self)

Definition at line 279 of file configuration_controller.py.

279 def get_list_of_classes(self):
280 return list(self._handler.configuration_handler.get_all_conf_classes().keys())
281

◆ get_relation_category_in_current_dal()

cider.widgets.configuration_controller.ConfigurationController.get_relation_category_in_current_dal ( self,
str relation_name )

Definition at line 286 of file configuration_controller.py.

286 def get_relation_category_in_current_dal(self, relation_name: str):
287 relations = self.get_relations_to_current_dal()
288
289 # Find the correct category
290 for rel in relations:
291 if list(rel.keys())[0] != relation_name:
292 continue
293
294 # Found correct_relation
295 return rel
296
297 raise RuntimeError(f"Error cannot find relation: {relation_name} in {self.generate_rich_string(self._current_selected_object)}

◆ get_relations_to_current_dal()

cider.widgets.configuration_controller.ConfigurationController.get_relations_to_current_dal ( self)

Definition at line 282 of file configuration_controller.py.

282 def get_relations_to_current_dal(self):
283 return self._handler.configuration_handler.get_relationships_for_conf_object(self.current_dal)
284

◆ handler() [1/2]

StructuredConfiguration | None cider.widgets.configuration_controller.ConfigurationController.handler ( self)
Return the configuration handler

Returns:
    ConfigurationHandler instance

Definition at line 86 of file configuration_controller.py.

86 def handler(self)->StructuredConfiguration | None:
87 """Return the configuration handler
88
89 Returns:
90 ConfigurationHandler instance
91 """
92 return self._handler
93

◆ handler() [2/2]

cider.widgets.configuration_controller.ConfigurationController.handler ( self,
StructuredConfiguration new_handler )
Set new handelr

Arguments:
    new_handler -- New handler object

Definition at line 95 of file configuration_controller.py.

95 def handler(self, new_handler: StructuredConfiguration):
96 """Set new handelr
97
98 Arguments:
99 new_handler -- New handler object
100 """
101 self._handler = new_handler
102

◆ is_selected_object_enabled()

list cider.widgets.configuration_controller.ConfigurationController.is_selected_object_enabled ( self)
Check if object is disabled in any session

Definition at line 221 of file configuration_controller.py.

221 def is_selected_object_enabled(self)->list:
222 """Check if object is disabled in any session
223 """
224 return [self._current_selected_object not in session.disabled for session in self.get_all_sessions()]
225

◆ modify_current_dal_relationship()

cider.widgets.configuration_controller.ConfigurationController.modify_current_dal_relationship ( self,
str relationship_name,
updated_value,
bool append = False )

Definition at line 237 of file configuration_controller.py.

237 def modify_current_dal_relationship(self, relationship_name: str, updated_value, append: bool=False):
238 # Wrapper method for changing value of relationship to anythings
239 self.__no_handler_check()
240 self.handler.configuration_handler.modify_relationship(self._current_selected_object.className(),
241 getattr(self._current_selected_object, 'id'),
242 relationship_name, updated_value, append)
243

◆ new_handler_from_str()

cider.widgets.configuration_controller.ConfigurationController.new_handler_from_str ( self,
str file_name )
Set new handler object by file name

Arguments:
    file_name -- New database to load

Definition at line 73 of file configuration_controller.py.

73 def new_handler_from_str(self, file_name: str):
74 """Set new handler object by file name
75
76 Arguments:
77 file_name -- New database to load
78 """
79 try:
80 self._handler = StructuredConfiguration(file_name)
81 except Exception as e:
82 raise e
83
84

◆ on_mount()

cider.widgets.configuration_controller.ConfigurationController.on_mount ( self)

Definition at line 23 of file configuration_controller.py.

23 def on_mount(self):
24 self._logger = self.app.query_one("RichLogWError")
25

◆ pop_dal_relationship()

cider.widgets.configuration_controller.ConfigurationController.pop_dal_relationship ( self,
relationship_name,
dal_to_remove )

Definition at line 252 of file configuration_controller.py.

252 def pop_dal_relationship(self, relationship_name, dal_to_remove):
253 # Wrapper method for removing dal from multi-value relationship
254 self.__no_handler_check()
255
256 if dal_to_remove is None:
257 raise Exception("Relationship is already emptied")
258
259 relationship_dict = self.get_relation_category_in_current_dal(relationship_name)
260
261 relationships = relationship_dict[relationship_name]
262
263 if not relationship_dict['rel_info']['multivalue']:
264 self.remove_current_dal_relationship(relationship_name)
265 return
266
267 # Grab index of dal to be removed
268 try:
269 dal_idx = relationships.index(dal_to_remove)
270 relationships.pop(dal_idx)
271 setattr(self._current_selected_object, relationship_name, relationships)
272 except Exception as e:
273 self._logger.write_error(e)
274

◆ remove_current_dal_relationship()

cider.widgets.configuration_controller.ConfigurationController.remove_current_dal_relationship ( self,
relationship_name )

Definition at line 244 of file configuration_controller.py.

244 def remove_current_dal_relationship(self, relationship_name):
245 # Wrapper method for setting relationship value to None
246 self.__no_handler_check()
247 self.handler.configuration_handler.modify_relationship(self._current_selected_object.className(),
248 getattr(self._current_selected_object, 'id'),
249 relationship_name,
250 None)
251

◆ rename_dal()

None cider.widgets.configuration_controller.ConfigurationController.rename_dal ( self,
str new_name )
Rename the currently selected object [NOT TESTED]

Definition at line 144 of file configuration_controller.py.

144 def rename_dal(self, new_name: str)->None:
145 """Rename the currently selected object [NOT TESTED]
146 """
147 self._current_selected_object.rename(new_name)
148 self._handler.configuration_handler.configuration.update_dal(self._current_selected_object)
149

◆ select_new_dal_from_id()

cider.widgets.configuration_controller.ConfigurationController.select_new_dal_from_id ( self,
str new_id,
str new_class )
Swap currently selected DAL object via its unique ID and class

Arguments:
    new_id -- UID of new DAL
    new_class -- Class of DAL

Definition at line 27 of file configuration_controller.py.

27 def select_new_dal_from_id(self, new_id: str, new_class: str):
28 """Swap currently selected DAL object via its unique ID and class
29
30 Arguments:
31 new_id -- UID of new DAL
32 new_class -- Class of DAL
33 """
34 if self.handler is not None:
35 self._current_selected_object = self.handler.configuration_handler.get_obj(new_id, new_class)
36

◆ toggle_disable_conf_obj()

None cider.widgets.configuration_controller.ConfigurationController.toggle_disable_conf_obj ( self,
selection_menu )
Disable current object in configuration

Definition at line 184 of file configuration_controller.py.

184 def toggle_disable_conf_obj(self, selection_menu)->None:
185 """Disable current object in configuration
186 """
187
188 self._logger.write("\n[red]=============================")
189 # DAL as configuration object
190 # Loop over all sessions [note currently this is badly implemented]
191 for session, toggle_enable in selection_menu:
192 session_disabled_elements = session.disabled
193
194
195 # Make sure if nothing's happening we don't do anything
196 if self._current_selected_object not in session_disabled_elements and toggle_enable:
197 return
198
199 elif self._current_selected_object in session_disabled_elements and not toggle_enable:
200 return
201
202 if toggle_enable:
203 self._logger.write(f"Enabling {self.generate_rich_string(self._current_selected_object)} in {self.generate_rich_string(session)}")
204 if self._current_selected_object in session_disabled_elements:
205 session_disabled_elements.remove(self._current_selected_object)
206 else:
207 self._logger.write(f"Disabling {self.generate_rich_string(self._current_selected_object)} in {self.generate_rich_string(session)}")
208
209 if self._current_selected_object not in session_disabled_elements:
210 session_disabled_elements.append(self._current_selected_object)
211
212 session.disabled = session_disabled_elements
213 self._handler.configuration_handler.configuration.update_dal(session)
214 self._logger.write("[red]=============================\n")
215
216

◆ update_configuration()

cider.widgets.configuration_controller.ConfigurationController.update_configuration ( self,
attr_name,
update_value )
Update an attribute of the currently loaded dal object.
NOTE This does not update the database file itself

Arguments:
    attr_name -- Attribute to update
    update_value -- New value for attribute

Definition at line 54 of file configuration_controller.py.

54 def update_configuration(self, attr_name, update_value):
55 """Update an attribute of the currently loaded dal object.
56 NOTE This does not update the database file itself
57
58 Arguments:
59 attr_name -- Attribute to update
60 update_value -- New value for attribute
61 """
62 if self.handler is None:
63 self._logger.write_error("No handler has been setup")
64
65
66 try:
67 setattr(self._current_selected_object, attr_name, update_value)
68 self._handler.configuration_handler.configuration.update_dal(self._current_selected_object)
69 except Exception as e:
70 self._logger.write_error(e)
71 self._logger.write_error(f"\nCould not update [yellow]{attr_name}[/yellow] to [yellow]{update_value}[/yellow] for {self.generate_rich_string(self._current_selected_object)}")
72

Member Data Documentation

◆ _current_selected_object

cider.widgets.configuration_controller.ConfigurationController._current_selected_object = None
staticprotected

Definition at line 21 of file configuration_controller.py.

◆ _handler

StructuredConfiguration cider.widgets.configuration_controller.ConfigurationController._handler = None
staticprotected

Definition at line 19 of file configuration_controller.py.

◆ _logger

cider.widgets.configuration_controller.ConfigurationController._logger = self.app.query_one("RichLogWError")
protected

Definition at line 24 of file configuration_controller.py.

◆ _selection_interfaces

dict cider.widgets.configuration_controller.ConfigurationController._selection_interfaces = {}
staticprotected

Definition at line 20 of file configuration_controller.py.

◆ BINDINGS

list cider.widgets.configuration_controller.ConfigurationController.BINDINGS = [("ctrl+s", "save_configuration", "Save Configuration")]
static

Definition at line 17 of file configuration_controller.py.

◆ current_dal

cider.widgets.configuration_controller.ConfigurationController.current_dal

Definition at line 164 of file configuration_controller.py.


The documentation for this class was generated from the following file: