Coverage for pyEDAA/IPXACT/DesignConfiguration.py: 43%

63 statements  

« prev     ^ index     » next       coverage.py v7.8.2, created at 2025-05-30 22:17 +0000

1# ==================================================================================================================== # 

2# _____ ____ _ _ ___ ______ __ _ ____ _____ # 

3# _ __ _ _| ____| _ \ / \ / \ |_ _| _ \ \/ / / \ / ___|_ _| # 

4# | '_ \| | | | _| | | | |/ _ \ / _ \ | || |_) \ / / _ \| | | | # 

5# | |_) | |_| | |___| |_| / ___ \ / ___ \ _ | || __// \ / ___ \ |___ | | # 

6# | .__/ \__, |_____|____/_/ \_\/_/ \_(_)___|_| /_/\_\/_/ \_\____| |_| # 

7# |_| |___/ # 

8# ==================================================================================================================== # 

9# Authors: # 

10# Patrick Lehmann # 

11# # 

12# License: # 

13# ==================================================================================================================== # 

14# Copyright 2017-2025 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 pathlib import Path 

33from textwrap import dedent 

34from typing import Optional as Nullable, ClassVar 

35 

36from lxml.etree import _Element, QName 

37from pyTooling.Decorators import export 

38 

39from pyEDAA.IPXACT import RootElement, __DEFAULT_SCHEMA__, VLNV, IPXACTSchema, IPXACTException 

40 

41 

42@export 

43class DesignConfiguration(RootElement): 

44 """Represents an IP-XACT design configuration.""" 

45 

46 _rootTagName: ClassVar[str] = "designConfiguration" 

47 

48 _generatorChainConfiguration: Nullable["GeneratorChainConfiguration"] 

49 _interconnectionConfiguration: Nullable["InterconnectionConfiguration"] 

50 _viewConfiguration: Nullable["ViewConfiguration"] 

51 

52 def __init__( 

53 self, 

54 designConfigurationFile: Nullable[Path] = None, 

55 parse: bool = False, 

56 vlnv: Nullable[VLNV] = None, 

57 description: Nullable[str] = None 

58 ): 

59 self._generatorChainConfiguration = None 

60 self._interconnectionConfiguration = None 

61 self._viewConfiguration = None 

62 

63 super().__init__(designConfigurationFile, parse, vlnv, description) 

64 

65 def Parse(self, element: _Element) -> None: 

66 elementLocalname = QName(element).localname 

67 # if elementLocalname == "catalogs": 

68 # for ipxactFileElement in element: 

69 # self.AddItem(IpxactFile.FromXml(ipxactFileElement)) 

70 # else: 

71 raise IPXACTException(f"Unsupported tag '{elementLocalname}' at root-level.") 

72 

73 def SetItem(self, item): 

74 if isinstance(item, GeneratorChainConfiguration): 

75 self._generatorChainConfiguration = item 

76 elif isinstance(item, InterconnectionConfiguration): 

77 self._interconnectionConfiguration = item 

78 elif isinstance(item, ViewConfiguration): 

79 self._viewConfiguration = item 

80 else: 

81 raise ValueError() 

82 

83 def ToXml(self, schema: IPXACTSchema = __DEFAULT_SCHEMA__) -> str: 

84 """Converts the object's data into XML format.""" 

85 

86 xmlns = schema.NamespacePrefix 

87 buffer = dedent(f"""\ 

88 <?xml version="1.0" encoding="UTF-8"?> 

89 <{xmlns}:designConfiguration 

90 \txmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 

91 \txmlns:{xmlns}="{schema.SchemaUri}" 

92 \txsi:schemaLocation="{schema.SchemaUri} {schema.SchemaUrl}"> 

93 {self._vlnv.ToXml(schema, isVersionedIdentifier=True)} 

94 \t<{xmlns}:description>{self._description}</{xmlns}:description> 

95 """) 

96 

97 if self._generatorChainConfiguration: 

98 buffer += f"\t<{xmlns}:componentInstances>\n" 

99 buffer += self._generatorChainConfiguration.ToXml(2, schema) 

100 buffer += f"\t</{xmlns}:componentInstances>\n" 

101 

102 if self._interconnectionConfiguration: 

103 buffer += f"\t<{xmlns}:interconnectionConfiguration>\n" 

104 buffer += self._interconnectionConfiguration.ToXml(2, schema) 

105 buffer += f"\t</{xmlns}:interconnectionConfiguration>\n" 

106 

107 if self._viewConfiguration: 

108 buffer += f"\t<{xmlns}:viewConfiguration>\n" 

109 buffer += self._viewConfiguration.ToXml(2, schema) 

110 buffer += f"\t</{xmlns}:viewConfiguration>\n" 

111 

112 buffer += dedent(f"""\ 

113 </{xmlns}:designConfiguration> 

114 """) 

115 

116 return buffer 

117 

118 

119@export 

120class GeneratorChainConfiguration: 

121 """Represents an IP-XACT generator chain configuration.""" 

122 

123 def __init__(self) -> None: 

124 pass 

125 

126 def ToXml(self, indent: int = 0, schema: IPXACTSchema = __DEFAULT_SCHEMA__) -> str: 

127 """Converts the object's data into XML format.""" 

128 

129 return "" 

130 

131 

132@export 

133class InterconnectionConfiguration: 

134 """Represents an IP-XACT interconnection configuration.""" 

135 

136 def __init__(self) -> None: 

137 pass 

138 

139 def ToXml(self, indent: int = 0, schema: IPXACTSchema = __DEFAULT_SCHEMA__) -> str: 

140 """Converts the object's data into XML format.""" 

141 

142 return "" 

143 

144 

145@export 

146class ViewConfiguration: 

147 """Represents an IP-XACT view configuration.""" 

148 

149 def __init__(self) -> None: 

150 pass 

151 

152 def ToXml(self, indent: int = 0, schema: IPXACTSchema = __DEFAULT_SCHEMA__) -> str: 

153 """Converts the object's data into XML format.""" 

154 

155 return ""