Esempio n. 1
0
def generate(
    filename: PathLike,
    outfile: PathLike,
    overridesfile: Optional[PathLike] = None,
) -> None:
    """Generates the Python data model.

    Opens the Gaphor model, generates the list of classes using the element
    factory, and then creates a new Python data model using a relationship
    search tree.

    """
    element_factory = ElementFactory()
    modeling_language = UMLModelingLanguage()
    with open(filename):
        storage.load(
            filename,
            element_factory,
            modeling_language,
        )
    with open(outfile, "w") as f:
        f.write(header)
        classes: List = element_factory.lselect(
            lambda e: e.isKindOf(UML.Class))
        classes, enumerations = find_enumerations(classes)

        classes = sorted((cls for cls in classes if cls.name[0] != "~"),
                         key=lambda c: c.name)

        trees = create_class_trees(classes)
        create_referenced(classes)

        uml_classes = filter_uml_classes(classes, modeling_language)
        for cls in uml_classes:
            f.write(f"from gaphor.UML import {cls.name}\n")

        cls_written: Set[Element] = set(uml_classes)
        for cls in trees.keys():
            cls.attribute.sort(
                key=lambda a: a.name or "")  # type: ignore[attr-defined]
            write_class_def(cls, trees, f, cls_written)

        f.write("\n\n")

        for cls in trees.keys():
            write_properties(cls, f, enumerations)

    element_factory.shutdown()
Esempio n. 2
0
def element_factory(event_manager):
    element_factory = ElementFactory(
        event_manager, ElementDispatcher(event_manager, UMLModelingLanguage()))
    yield element_factory
    element_factory.shutdown()