diff --git a/src/caosdb/apiutils.py b/src/caosdb/apiutils.py index f49b13e717f3464cae5cf0d14284c6e6a750f393..391edfed8231a09bd2014ac321e830bc1477919b 100644 --- a/src/caosdb/apiutils.py +++ b/src/caosdb/apiutils.py @@ -484,18 +484,18 @@ def getCommitIn(folder): COMPARED = ["name", "role", "datatype", "description", "importance"] -def compare_entities(r1, r2): +def compare_entities(old_entity, new_entity): description = "" - # if r1 is r2: + # if old_entity is new_entity: # return description for attr in COMPARED: try: - r1.__getattribute__(attr) + old_entity.__getattribute__(attr) r1_attr_exists = True except BaseException: r1_attr_exists = False try: - r2.__getattribute__(attr) + new_entity.__getattribute__(attr) r2_attr_exists = True except BaseException: r2_attr_exists = False @@ -504,22 +504,22 @@ def compare_entities(r1, r2): continue if not r1_attr_exists and not r2_attr_exists: continue - if r1.__getattribute__(attr) != r2.__getattribute__(attr): + if old_entity.__getattribute__(attr) != new_entity.__getattribute__(attr): description += attr + " differs:\n" - description += str(r1.__getattribute__(attr)) + "\n" - description += str(r2.__getattribute__(attr)) + "\n" + description += str(old_entity.__getattribute__(attr)) + "\n" + description += str(new_entity.__getattribute__(attr)) + "\n" # properties - if (len(r1.properties) > 0) ^ (len(r2.properties) > 0): + if (len(old_entity.properties) > 0) ^ (len(new_entity.properties) > 0): description += "only one has properties\n" else: - for prop in r1.properties: - matching = [p for p in r2.properties if p.name == prop.name] + for prop in old_entity.properties: + matching = [p for p in new_entity.properties if p.name == prop.name] if len(matching) == 0: - description += "r2 is missing the property '" + prop.name + "'\n" + description += "new_entity is missing the property '" + prop.name + "'\n" elif len(matching) == 1: - if (r1.get_importance(prop.name) != - r2.get_importance(prop.name)): + if (old_entity.get_importance(prop.name) != + new_entity.get_importance(prop.name)): description += "importance of '" + prop.name + "' differs\n" if ((prop.datatype is not None and matching[0].datatype is not None) and @@ -527,28 +527,28 @@ def compare_entities(r1, r2): description += "datatype of '" + prop.name + "' differs\n" else: raise NotImplementedError() - for prop in r2.properties: - if len([0 for p in r1.properties if p.name == prop.name]) == 0: - description += "r1 is missing the property '" + prop.name + "'\n" + for prop in new_entity.properties: + if len([0 for p in old_entity.properties if p.name == prop.name]) == 0: + description += "old_entity is missing the property '" + prop.name + "'\n" # parents - if ((len(r1.parents) > 0) ^ (len(r2.parents) > 0)): + if ((len(old_entity.parents) > 0) ^ (len(new_entity.parents) > 0)): description += "only one has parents\n" else: - for par in r1.parents: - matching = [p for p in r2.parents if p.name == par.name] + for par in old_entity.parents: + matching = [p for p in new_entity.parents if p.name == par.name] if len(matching) == 0: - description += "r2 is missing the parent '" + par.name + "'\n" + description += "new_entity is missing the parent '" + par.name + "'\n" elif len(matching) == 1: description += compare_entities(par, matching[0]) else: raise NotImplementedError() - for par in r2.parents: - if len([0 for p in r1.parents if p.name == par.name]) == 0: - description += "r1 is missing the parent '" + par.name + "'\n" + for par in new_entity.parents: + if len([0 for p in old_entity.parents if p.name == par.name]) == 0: + description += "old_entity is missing the parent '" + par.name + "'\n" if description != "": description = """####################### {} -#######################\n""".format(r1.name) + description +#######################\n""".format(old_entity.name) + description return description