Coverage for pyEDAA/IPXACT/Design.py: 35%
66 statements
« prev ^ index » next coverage.py v7.6.7, created at 2024-11-17 01:13 +0000
« prev ^ index » next coverage.py v7.6.7, created at 2024-11-17 01:13 +0000
1# ==================================================================================================================== #
2# _____ ____ _ _ ___ ______ __ _ ____ _____ #
3# _ __ _ _| ____| _ \ / \ / \ |_ _| _ \ \/ / / \ / ___|_ _| #
4# | '_ \| | | | _| | | | |/ _ \ / _ \ | || |_) \ / / _ \| | | | #
5# | |_) | |_| | |___| |_| / ___ \ / ___ \ _ | || __// \ / ___ \ |___ | | #
6# | .__/ \__, |_____|____/_/ \_\/_/ \_(_)___|_| /_/\_\/_/ \_\____| |_| #
7# |_| |___/ #
8# ==================================================================================================================== #
9# Authors: #
10# Patrick Lehmann #
11# #
12# License: #
13# ==================================================================================================================== #
14# Copyright 2017-2024 Patrick Lehmann - Bötzingen, Germany #
15# Copyright 2016-2016 Patrick Lehmann - Dresden, Germany #
16# #
17# Licensed under the Apache License, Version 2.0 (the "License"); #
18# you may not use this file except in compliance with the License. #
19# You may obtain a copy of the License at #
20# #
21# http://www.apache.org/licenses/LICENSE-2.0 #
22# #
23# Unless required by applicable law or agreed to in writing, software #
24# distributed under the License is distributed on an "AS IS" BASIS, #
25# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. #
26# See the License for the specific language governing permissions and #
27# limitations under the License. #
28# #
29# SPDX-License-Identifier: Apache-2.0 #
30# ==================================================================================================================== #
31#
32from textwrap import dedent
34from pyTooling.Decorators import export
36from pyEDAA.IPXACT import RootElement, __DEFAULT_SCHEMA__, Vlnv
39@export
40class Design(RootElement):
41 """Represents an IP-XACT design."""
43 def __init__(self, vlnv: Vlnv, description: str):
44 super().__init__(vlnv)
46 self._description = description
47 self._componentInstances = []
48 self._interconnections = []
49 self._adHocConnections = []
51 def AddItem(self, item) -> None:
52 if isinstance(item, ComponentInstance):
53 self._componentInstances.append(item)
54 elif isinstance(item, Interconnection):
55 self._interconnections.append(item)
56 elif isinstance(item, AdHocConnection):
57 self._adHocConnections.append(item)
58 else:
59 raise ValueError()
61 def ToXml(self) -> str:
62 """Converts the object's data into XML format."""
64 buffer = dedent("""\
65 <?xml version="1.0" encoding="UTF-8"?>
66 <{xmlns}:design
67 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
68 xmlns:{xmlns}="{schemaUri}"
69 xsi:schemaLocation="{schemaUri} {schemaUrl}">
70 {versionedIdentifier}
71 <{xmlns}:description>{description}</{xmlns}:description>
72 """).format(
73 xmlns=__DEFAULT_SCHEMA__.NamespacePrefix,
74 schemaUri=__DEFAULT_SCHEMA__.SchemaUri,
75 schemaUrl=__DEFAULT_SCHEMA__.SchemaUrl,
76 versionedIdentifier=self._vlnv.ToXml(isVersionedIdentifier=True),
77 description=self._description
78 )
80 if self._componentInstances:
81 buffer += "\t<{xmlns}:componentInstances>\n"
82 for componentInstance in self._componentInstances:
83 buffer += componentInstance.ToXml(2)
84 buffer += "\t</{xmlns}:componentInstances>\n"
86 if self._interconnections:
87 buffer += "\t<{xmlns}:interconnections>\n"
88 for interconnection in self._interconnections:
89 buffer += interconnection.ToXml(2)
90 buffer += "\t</{xmlns}:interconnections>\n"
92 if self._adHocConnections:
93 buffer += "\t<{xmlns}:adHocConnections>\n"
94 for adHocConnection in self._adHocConnections:
95 buffer += adHocConnection.ToXml(2)
96 buffer += "\t</{xmlns}:adHocConnections>\n"
98 buffer += dedent("""\
99 </{xmlns}:design>
100 """)
102 return buffer.format(xmlns=__DEFAULT_SCHEMA__.NamespacePrefix)
105@export
106class IpxactFile:
107 def __init__(self, vlnv, name, description):
108 self._vlnv = vlnv
109 self._name = name
110 self._description = description
112 def ToXml(self, indent):
113 """Converts the object's data into XML format."""
115 _indent = "\t" * indent
116 buffer = dedent("""\
117 {indent}<{xmlns}:ipxactFile>
118 {indent} {vlnv}
119 {indent} <{xmlns}:name>{path}</{xmlns}:name>
120 {indent} <{xmlns}:description>{description}</{xmlns}:description>
121 {indent}</{xmlns}:ipxactFile>
122 """).format(indent=_indent, xmlns=__DEFAULT_SCHEMA__.NamespacePrefix, vlnv=self._vlnv.ToXml(0), path=self._name, description=self._description)
124 return buffer
127@export
128class ComponentInstance:
129 """Represents an IP-XACT component instance."""
131 def __init__(self) -> None:
132 pass
134 def ToXml(self, indent=0):
135 """Converts the object's data into XML format."""
137 return ""
140@export
141class Interconnection:
142 """Represents an IP-XACT interconnection."""
144 def __init__(self) -> None:
145 pass
147 def ToXml(self, indent=0):
148 """Converts the object's data into XML format."""
150 return ""
153@export
154class AdHocConnection:
155 """Represents an IP-XACT ad-hoc connection."""
157 def __init__(self) -> None:
158 pass
160 def ToXml(self, indent=0):
161 """Converts the object's data into XML format."""
163 return ""