Coverage for pyEDAA/ToolSetup/DataModel.py: 92%

120 statements  

« prev     ^ index     » next       coverage.py v7.6.5, created at 2024-11-15 01:13 +0000

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

2# _____ ____ _ _ ____ __ _ # 

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

4# | '_ \| | | | _| | | | |/ _ \ / _ \ | | / _ \| '_ \| |_| |/ _` | | | | '__/ _ \ # 

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

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

7# |_| |___/ |___/ # 

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

9# Authors: # 

10# Patrick Lehmann # 

11# # 

12# License: # 

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

14# Copyright 2021-2022 Patrick Lehmann - Bötzingen, Germany # 

15# # 

16# Licensed under the Apache License, Version 2.0 (the "License"); # 

17# you may not use this file except in compliance with the License. # 

18# You may obtain a copy of the License at # 

19# # 

20# http://www.apache.org/licenses/LICENSE-2.0 # 

21# # 

22# Unless required by applicable law or agreed to in writing, software # 

23# distributed under the License is distributed on an "AS IS" BASIS, # 

24# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # 

25# See the License for the specific language governing permissions and # 

26# limitations under the License. # 

27# # 

28# SPDX-License-Identifier: Apache-2.0 # 

29# ==================================================================================================================== # 

30# 

31"""Abstract data model for tool configurations.""" 

32from pathlib import Path 

33from typing import Optional as Nullable, Dict, ClassVar, Type 

34 

35from pyTooling.Decorators import export 

36 

37 

38@export 

39class ToolInformation: 

40 _installationDirectory: Path 

41 _binaryDirectory: Path 

42 _version: Nullable[str] 

43 _edition: Nullable[str] 

44 

45 def __init__(self, installationDirectory: Path, binaryDirectory: Path, version: str = None, edition: str = None): 

46 self._installationDirectory = installationDirectory 

47 self._binaryDirectory = binaryDirectory 

48 self._version = version 

49 self._edition = edition 

50 

51 @property 

52 def InstallationDirectory(self) -> Path: 

53 return self._installationDirectory 

54 

55 @property 

56 def BinaryDirectory(self) -> Path: 

57 return self._binaryDirectory 

58 

59 @property 

60 def Version(self) -> str: 

61 return self._version 

62 

63 @property 

64 def Edition(self) -> str: 

65 return self._edition 

66 

67 

68@export 

69class VendorInformation: 

70 _installationDirectory: Path 

71 

72 def __init__(self, installationDirectory: Path): 

73 self._installationDirectory = installationDirectory 

74 

75 @property 

76 def InstallationDirectory(self) -> Path: 

77 return self._installationDirectory 

78 

79 

80@export 

81class ToolInstance(ToolInformation): 

82 _tool: Nullable["Tool"] 

83 

84 def __init__(self, installationDirectory: Path, binaryDirectory: Path, version: str = None, edition: str = None, parent: "Tool" = None): 

85 super().__init__(installationDirectory, binaryDirectory, version, edition) 

86 self._tool = parent 

87 

88 @property 

89 def Tool(self) -> "Tool": 

90 return self._tool 

91 

92 

93@export 

94class Tool: 

95 _vendor: Nullable["Vendor"] 

96 _name: str 

97 _allLoaded: bool 

98 _variants: Dict[str, ToolInstance] 

99 _instanceClass: ClassVar[Type[ToolInstance]] 

100 

101 def __init__(self, name: str, parent: "Vendor" = None): 

102 self._vendor = parent 

103 self._name = name 

104 self._allLoaded = False 

105 self._variants = {} 

106 

107 def __contains__(self, key: str) -> bool: 

108 self._LoadAllVariants() 

109 return key in self._variants 

110 

111 def __getitem__(self, key: str) -> ToolInstance: 

112 try: 

113 return self._variants[key] 

114 except KeyError: 

115 return self._LoadVariant(key) 

116 

117 @property 

118 def Vendor(self) -> "Vendor": 

119 return self._vendor 

120 

121 @property 

122 def Variants(self) -> Dict[str, ToolInstance]: 

123 self._LoadAllVariants() 

124 return self._variants 

125 

126 @property 

127 def Default(self) -> ToolInstance: 

128 raise NotImplementedError() 

129 

130 def _LoadVariant(self, key: str) -> ToolInstance: 

131 raise NotImplementedError() 

132 

133 def _LoadAllVariants(self) -> None: 

134 raise NotImplementedError() 

135 

136 

137@export 

138class Vendor(VendorInformation): 

139 _installation: Nullable["Installation"] 

140 _name: str 

141 _allLoaded: bool 

142 _tools: Dict[str, Tool] 

143 

144 def __init__(self, name: str, installationDirectory: Path, parent: "Installation" = None): 

145 super().__init__(installationDirectory) 

146 self._installation = parent 

147 self._name = name 

148 self._allLoaded = False 

149 self._tools = {} 

150 

151 def __contains__(self, key: str) -> bool: 

152 self._LoadAllTools() 

153 return key in self._tools 

154 

155 def __getitem__(self, key: str) -> Tool: 

156 try: 

157 return self._tools[key] 

158 except KeyError: 

159 return self._LoadTool(key) 

160 

161 def _LoadTool(self, key: str) -> Tool: 

162 raise NotImplementedError() 

163 

164 def _LoadAllTools(self) -> None: 

165 raise NotImplementedError() 

166 

167 @property 

168 def Installation(self) -> "Installation": 

169 return self._installation 

170 

171 @property 

172 def Tools(self) -> Dict[str, Tool]: 

173 self._LoadAllTools() 

174 return self._tools 

175 

176 

177@export 

178class Installation: 

179 _allLoaded: bool 

180 _vendors: Dict[str, Vendor] 

181 

182 def __init__(self): 

183 self._allLoaded = False 

184 self._vendors = {} 

185 

186 def __contains__(self, key: str) -> bool: 

187 self._LoadAllVendors() 

188 return key in self._vendor 

189 

190 def __getitem__(self, key: str) -> Vendor: 

191 try: 

192 return self._vendors[key] 

193 except KeyError: 

194 return self._LoadVendor(key) 

195 

196 def _LoadVendor(self, key: str) -> Vendor: 

197 raise NotImplementedError() 

198 

199 def _LoadAllVendors(self) -> None: 

200 raise NotImplementedError()