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()