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
« 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
35from pyTooling.Decorators import export
38@export
39class ToolInformation:
40 _installationDirectory: Path
41 _binaryDirectory: Path
42 _version: Nullable[str]
43 _edition: Nullable[str]
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
51 @property
52 def InstallationDirectory(self) -> Path:
53 return self._installationDirectory
55 @property
56 def BinaryDirectory(self) -> Path:
57 return self._binaryDirectory
59 @property
60 def Version(self) -> str:
61 return self._version
63 @property
64 def Edition(self) -> str:
65 return self._edition
68@export
69class VendorInformation:
70 _installationDirectory: Path
72 def __init__(self, installationDirectory: Path):
73 self._installationDirectory = installationDirectory
75 @property
76 def InstallationDirectory(self) -> Path:
77 return self._installationDirectory
80@export
81class ToolInstance(ToolInformation):
82 _tool: Nullable["Tool"]
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
88 @property
89 def Tool(self) -> "Tool":
90 return self._tool
93@export
94class Tool:
95 _vendor: Nullable["Vendor"]
96 _name: str
97 _allLoaded: bool
98 _variants: Dict[str, ToolInstance]
99 _instanceClass: ClassVar[Type[ToolInstance]]
101 def __init__(self, name: str, parent: "Vendor" = None):
102 self._vendor = parent
103 self._name = name
104 self._allLoaded = False
105 self._variants = {}
107 def __contains__(self, key: str) -> bool:
108 self._LoadAllVariants()
109 return key in self._variants
111 def __getitem__(self, key: str) -> ToolInstance:
112 try:
113 return self._variants[key]
114 except KeyError:
115 return self._LoadVariant(key)
117 @property
118 def Vendor(self) -> "Vendor":
119 return self._vendor
121 @property
122 def Variants(self) -> Dict[str, ToolInstance]:
123 self._LoadAllVariants()
124 return self._variants
126 @property
127 def Default(self) -> ToolInstance:
128 raise NotImplementedError()
130 def _LoadVariant(self, key: str) -> ToolInstance:
131 raise NotImplementedError()
133 def _LoadAllVariants(self) -> None:
134 raise NotImplementedError()
137@export
138class Vendor(VendorInformation):
139 _installation: Nullable["Installation"]
140 _name: str
141 _allLoaded: bool
142 _tools: Dict[str, Tool]
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 = {}
151 def __contains__(self, key: str) -> bool:
152 self._LoadAllTools()
153 return key in self._tools
155 def __getitem__(self, key: str) -> Tool:
156 try:
157 return self._tools[key]
158 except KeyError:
159 return self._LoadTool(key)
161 def _LoadTool(self, key: str) -> Tool:
162 raise NotImplementedError()
164 def _LoadAllTools(self) -> None:
165 raise NotImplementedError()
167 @property
168 def Installation(self) -> "Installation":
169 return self._installation
171 @property
172 def Tools(self) -> Dict[str, Tool]:
173 self._LoadAllTools()
174 return self._tools
177@export
178class Installation:
179 _allLoaded: bool
180 _vendors: Dict[str, Vendor]
182 def __init__(self):
183 self._allLoaded = False
184 self._vendors = {}
186 def __contains__(self, key: str) -> bool:
187 self._LoadAllVendors()
188 return key in self._vendor
190 def __getitem__(self, key: str) -> Vendor:
191 try:
192 return self._vendors[key]
193 except KeyError:
194 return self._LoadVendor(key)
196 def _LoadVendor(self, key: str) -> Vendor:
197 raise NotImplementedError()
199 def _LoadAllVendors(self) -> None:
200 raise NotImplementedError()