From 169292ab5114fe3d14f7875aa719eb0e7635df2a Mon Sep 17 00:00:00 2001 From: Michael Becker Date: Mon, 8 Apr 2024 14:51:38 -0400 Subject: [PATCH 1/2] preliminary implementation of get_instance_text and stubs / convenience methods --- python/mocha-shell.py | 6 ++-- python/mocha/oms/Oms.py | 36 +++++++++++++++++++ python/mocha/oms/db/mysql/MySQLDatabaseOms.py | 3 ++ 3 files changed, 42 insertions(+), 3 deletions(-) diff --git a/python/mocha-shell.py b/python/mocha-shell.py index 5e018ae..44e2dc7 100644 --- a/python/mocha-shell.py +++ b/python/mocha-shell.py @@ -51,10 +51,10 @@ class MochaShell (REPLApplication): def print_instance_list(self, instances : list): print("") - print("instance key global identifier ") - print("--------------- --------------------------------------") + print("instance key global identifier comment ") + print("--------------- -------------------------------------- -------------------------") for inst in instances: - print(str(inst.get_instance_key()).ljust(16) + str(inst.get_global_identifier())) + print(str(inst.get_instance_key()).ljust(16) + str(inst.get_global_identifier()) + " " + self.oms.get_instance_text(inst)) print("") def print_instance_list_with_attribute_values(self, instances : list, oms : Oms, refobj : InstanceReference): diff --git a/python/mocha/oms/Oms.py b/python/mocha/oms/Oms.py index 204dab8..239f452 100644 --- a/python/mocha/oms/Oms.py +++ b/python/mocha/oms/Oms.py @@ -103,6 +103,42 @@ class Oms: def get_tenant_by_name(self, tenant_name : str) -> TenantReference: pass + def get_related_instances(self, inst : InstanceReference, rel : InstanceReference) -> list[InstanceReference]: + pass + + def get_related_instance(self, inst : InstanceReference, rel : InstanceReference) -> InstanceReference | None: + rels = self.get_related_instances(inst, rel) + if len(rels) == 0: + return None + + return rels[0] + + def assign_attribute(self, instance : InstanceReference, attribute : InstanceReference, value : str): + pass + + def assign_relationship(self, instance : InstanceReference, relationship : InstanceReference, related_instances : InstanceReference|list): + pass + + def get_instance_text(self, inst : InstanceReference) -> str: + # first see if we have a parent class with `Class.instance labeled by Executable returning Attribute` + pclasz = self.get_parent_class(inst) + if pclasz is not None: + rel = self.get_instance_by_global_identifier(KnownRelationshipGuids.Class__instances_labeled_by__Executable_returning_Attribute) + relinst = self.get_related_instance(pclasz, rel) + if relinst is not None: + text = "EXEC:" + str(relinst.get_instance_key()) # self.execute(relinst) + return text + + + # if all else fails, try getting the `Name` attribute + attr = self.get_instance_by_global_identifier(KnownAttributeGuids.Name) + text = self.get_attribute_value(inst, attr) + + if text is None: + text = "" + + return text + def _create_instance_of(self, class_inst : InstanceReference, global_identifier : Guid = None): pass diff --git a/python/mocha/oms/db/mysql/MySQLDatabaseOms.py b/python/mocha/oms/db/mysql/MySQLDatabaseOms.py index 07112f5..97acae0 100644 --- a/python/mocha/oms/db/mysql/MySQLDatabaseOms.py +++ b/python/mocha/oms/db/mysql/MySQLDatabaseOms.py @@ -118,6 +118,9 @@ class MySQLDatabaseOms(DatabaseOms): return None + def get_related_instances(self, inst : InstanceReference, rel : InstanceReference) -> list[InstanceReference]: + pass + def get_tenant_by_name(self, tenant_name : str) -> TenantReference: mycur = self.db.cursor() From cadbb4839ffa705d48d00b5f6b7b7a1b10bff5f5 Mon Sep 17 00:00:00 2001 From: Michael Becker Date: Mon, 8 Apr 2024 15:28:55 -0400 Subject: [PATCH 2/2] hack to set Name attribute of Class inst --- python/mocha/oms/Oms.py | 1 + 1 file changed, 1 insertion(+) diff --git a/python/mocha/oms/Oms.py b/python/mocha/oms/Oms.py index 239f452..635e269 100644 --- a/python/mocha/oms/Oms.py +++ b/python/mocha/oms/Oms.py @@ -258,6 +258,7 @@ class Oms: ik_MaximumValue = self.create_instance_of(ik_NumericAttribute, KnownAttributeGuids.MaximumValue) self.set_attribute_value(ik_MaximumValue, att_Name, "Maximum Value") + self.set_attribute_value(ik_Class, att_Name, "Class") self.update_class_instances() def update_relationship(self, relationship : InstanceReference, src_class : InstanceReference, type : str, dst_class : InstanceReference, singular: bool, sibling_relationship : InstanceReference):