add Python code generation support

This commit is contained in:
Michael Becker 2024-08-24 15:50:11 -04:00
parent aaef3a529d
commit d6eb3868ec

View File

@ -466,8 +466,12 @@ class MochaLibraryManager:
# assign relationship `Class.has Instance` # assign relationship `Class.has Instance`
self.assign_relationship(classGid, Guid.parse('7EB41D3C2AE9488483A4E59441BCAEFB'), instGid) self.assign_relationship(classGid, Guid.parse('7EB41D3C2AE9488483A4E59441BCAEFB'), instGid)
def save_entities_to_file(self, filename : str): def save_entities_to_file(self, filename : str, libraryFileName : str = ""):
f = open(filename, "w") f = open(filename, "w")
if filename.endswith(".cs"):
print("// Mocha entity definitions" + (" for " + libraryFileName if libraryFileName != "" else ""), file=f)
print("// Generated by yaml2mcl version 1.0", file=f)
print("", file=f)
print("public static class KnownInstances", file=f) print("public static class KnownInstances", file=f)
print("{", file=f) print("{", file=f)
for name in self.entityReferences: for name in self.entityReferences:
@ -479,4 +483,19 @@ class MochaLibraryManager:
print("\tpublic static readonly Guid " + shortname + " = new Guid(\"" + self.entityReferences[name] + "\");", file=f) print("\tpublic static readonly Guid " + shortname + " = new Guid(\"" + self.entityReferences[name] + "\");", file=f)
print("}", file=f) print("}", file=f)
elif filename.endswith(".py"):
print("# Mocha entity definitions" + (" for " + libraryFileName if libraryFileName != "" else ""), file=f)
print("# Generated by yaml2mcl version 1.0", file=f)
print("", file=f)
print("class KnownInstances:", file=f)
print("", file=f)
for name in self.entityReferences:
if name.startswith("IDC_") or name.startswith("IDA_") or name.startswith("IDI_"):
shortname = name
if name.startswith("ID") and "_" in name:
shortname = name[name.index("ID") + 2:]
print("\t" + shortname + " = Guid.parse(\"" + self.entityReferences[name] + "\")", file=f)
f.close() f.close()