capella2polarion.elements package

Objects for synchronization of capella objects to polarion workitems.

Submodules

capella2polarion.elements.capella_object_renderer module

Provides Capella object specific rendering functionalities.

class capella2polarion.elements.capella_object_renderer.CapellaObjectRenderer(model: MelodyModel, generate_figure_captions: bool, generate_attachments: bool, capella_polarion_mapping: PolarionDataRepository)

Bases: JinjaRendererMixin

A class for work item generating plugins and generators.

draw_diagram_svg(diagram: AbstractDiagram, file_name: str, title: str, max_width: int, cls: str, render_params: dict[str, Any] | None = None, caption: str | None = None) tuple[str, CapellaDiagramAttachment | None]

Return the provided diagram as attachment and HTML.

static get_requirement_types_text(obj: ModelElement | DRepresentationDescriptor, errors: set[str]) dict[str, HtmlContent]

Get the requirement texts and return them.

render_jinja_template(template_folder: str | Path, template_path: str | Path, capella_element: ModelElement | DRepresentationDescriptor, errors: set[str], work_item: CapellaWorkItem | None = None, render_params: dict[str, Any] | None = None) tuple[list[str], Markup, list[Capella2PolarionAttachment]]

Render jinja template for model element and return polarion text.

replace_markup(match: Match, referenced_uuids: list[str], errors: set[str], default_group: int = 1) str

Replace UUID references in a match with a work item link.

If the UUID doesn’t correspond to an existing work item the original text is returned.

sanitize_linked_text(obj: ModelElement | DRepresentationDescriptor, errors: set[str]) tuple[list[str], Markup, list[Capella2PolarionAttachment]]

Get the linked text and return it sanitized.

sanitize_text(obj: ModelElement | DRepresentationDescriptor, text: Markup | str, errors: set[str]) tuple[list[str], Markup, list[Capella2PolarionAttachment]]

Convert Capella texts to Polarion HTML with links and images.

setup_env(env: Environment) None

Add the link rendering filter.

capella2polarion.elements.converter_config module

Module providing capella2polarion config class.

class capella2polarion.elements.converter_config.CapellaTypeConfig(p_type: str | None = None, converters: dict[str, dict[str, ~typing.Any]] | None = None, links: list[~capella2polarion.elements.converter_config.LinkConfig] = <factory>, is_actor: bool | None = None, nature: str | None = None)

Bases: object

A single Capella Type configuration.

converters: dict[str, dict[str, Any]] | None = None
is_actor: bool | None = None
nature: str | None = None
p_type: str | None = None
class capella2polarion.elements.converter_config.ConverterConfig

Bases: object

The overall Config for capella2polarion.

add_layer(layer: str) None

Add a new layer without configuring any types.

get_type_config(layer: str, c_type: str, **attributes: Any) CapellaTypeConfig | None

Get the type config for a given layer and capella_type.

layers_and_types() Iterator[tuple[str, str]]

Yield the layer and Capella type of the config.

read_config_file(synchronize_config: TextIO | str, type_prefix: str = '', role_prefix: str = '') None

Read a given yaml file as config.

set_diagram_config(diagram_config: dict[str, Any], type_prefix: str = '', role_prefix: str = '') None

Set the diagram config.

set_global_config(c_type: str, type_config: dict[str, Any], type_prefix: str = '', role_prefix: str = '') None

Set a global config for a specific type.

set_layer_config(c_type: str, c_type_config: dict[str, Any] | list[dict[str, Any]] | None, layer: str, type_prefix: str = '', role_prefix: str = '') None

Set one or multiple configs for a type to an existing layer.

class capella2polarion.elements.converter_config.LinkConfig(capella_attr: str, polarion_role: str, include: dict[str, str] = <factory>, link_field: str = '', reverse_field: str = '')

Bases: object

A single Capella Link configuration.

capella_attr: str

The Attribute name on the capellambse model object.

Generate LinkConfigs based on a list dict.

include: dict[str, str]

A list of identifiers that are attribute names on the Capella objects link targets.

The requested objects are then included in the list display in the grouped link custom field as nested lists. They also need be migrated for working references.

polarion_role: str

The identifier used in the Polarion configuration for this work item link (role).

reverse_field: str = ''
capella2polarion.elements.converter_config.add_prefix(polarion_type: str, prefix: str) str

Add a prefix to the given polarion_type.

capella2polarion.elements.converter_config.config_matches(config: CapellaTypeConfig | None, **kwargs: Any) bool

Check whether the given config matches the given kwargs.

capella2polarion.elements.converter_config.merge_converters(base_converters: dict[str, dict[str, Any]], additional_converters: dict[str, dict[str, Any]] | None) dict[str, dict[str, Any]]

Merge converters properly handling add_attributes.

capella2polarion.elements.data_session module

A module to store data during the conversion process.

class capella2polarion.elements.data_session.ConverterData(layer: str, type_config: ~capella2polarion.elements.converter_config.CapellaTypeConfig, capella_element: ~capellambse.model._obj.ModelElement | ~capellambse.model.diagram.DRepresentationDescriptor, work_item: ~capella2polarion.data_model.work_items.CapellaWorkItem | None = None, description_references: list[str] = <factory>, errors: set[str] = <factory>)

Bases: object

Data class holding all information needed during Conversion.

capella_element: ModelElement | DRepresentationDescriptor
description_references: list[str]
errors: set[str]
layer: str
type_config: CapellaTypeConfig
work_item: CapellaWorkItem | None = None

capella2polarion.elements.element_converter module

Objects for serialization of capella objects to workitems.

class capella2polarion.elements.element_converter.CapellaWorkItemSerializer(model: MelodyModel, capella_polarion_mapping: PolarionDataRepository, converter_session: dict[str, ConverterData], generate_attachments: bool, generate_figure_captions: bool = False)

Bases: object

The general serializer class for CapellaWorkItems.

serialize(uuid: str) CapellaWorkItem | None

Return a CapellaWorkItem for the given diagram or element.

serialize_all() list[CapellaWorkItem]

Serialize all items of the converter_session.

capella2polarion.elements.element_converter.resolve_element_type(type_: str) str

Return a valid Type ID for polarion for a given obj.

capella2polarion.elements.model_converter module

A module containing the overall model conversion class.

class capella2polarion.elements.model_converter.ModelConverter(model: MelodyModel, project_id: str)

Bases: object

Class to convert elements of a model and store related data.

Generate links for all work items and add custom fields for them.

generate_work_items(polarion_data_repo: PolarionDataRepository, generate_links: bool = False, generate_attachments: bool = False, generate_grouped_links_custom_fields: bool = False, generate_figure_captions: bool = False) dict[str, CapellaWorkItem]

Return a work items mapping from model elements for Polarion.

The dictionary maps Capella UUIDs to CapellaWorkItem s. In addition, it is ensured that neither title nor type are None, Links are not created in this step by default.

Parameters:
  • polarion_data_repo – The PolarionDataRepository object storing current work item data.

  • generate_links – A boolean flag to control linked work item generation.

  • generate_attachments – A boolean flag to control attachments generation. For SVG attachments, PNGs are generated and attached automatically.

  • generate_grouped_links_custom_fields – A boolean flag to control grouped links custom fields generation.

  • generate_figure_captions – A boolean flag to enable the generation of figure captions

read_model(config: ConverterConfig) None

Read the model using a given config and diagram_idx.

capella2polarion.elements.model_converter.get_layer_name(diagram: DRepresentationDescriptor) str

Return the layer name for a diagram.