1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
|
# ==================================================================================================================== #
# _____ ____ _ _ ____ __ _ #
# _ __ _ _| ____| _ \ / \ / \ / ___|___ _ __ / _(_) __ _ _ _ _ __ ___ #
# | '_ \| | | | _| | | | |/ _ \ / _ \ | | / _ \| '_ \| |_| |/ _` | | | | '__/ _ \ #
# | |_) | |_| | |___| |_| / ___ \ / ___ \ | |__| (_) | | | | _| | (_| | |_| | | | __/ #
# | .__/ \__, |_____|____/_/ \_\/_/ \_(_)____\___/|_| |_|_| |_|\__, |\__,_|_| \___| #
# |_| |___/ |___/ #
# ==================================================================================================================== #
# Authors: #
# Patrick Lehmann #
# #
# License: #
# ==================================================================================================================== #
# Copyright 2021-2022 Patrick Lehmann - Bötzingen, Germany #
# #
# Licensed under the Apache License, Version 2.0 (the "License"); #
# you may not use this file except in compliance with the License. #
# You may obtain a copy of the License at #
# #
# http://www.apache.org/licenses/LICENSE-2.0 #
# #
# Unless required by applicable law or agreed to in writing, software #
# distributed under the License is distributed on an "AS IS" BASIS, #
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. #
# See the License for the specific language governing permissions and #
# limitations under the License. #
# #
# SPDX-License-Identifier: Apache-2.0 #
# ==================================================================================================================== #
#
"""Abstract data model for tool configurations."""
from pathlib import Path
from typing import Optional as Nullable, Dict, ClassVar, Type
from pyTooling.Decorators import export
@export
class ToolInformation:
_installationDirectory: Path
_binaryDirectory: Path
_version: Nullable[str]
_edition: Nullable[str]
def __init__(self, installationDirectory: Path, binaryDirectory: Path, version: str = None, edition: str = None):
self._installationDirectory = installationDirectory
self._binaryDirectory = binaryDirectory
self._version = version
self._edition = edition
@property
def InstallationDirectory(self) -> Path:
return self._installationDirectory
@property
def BinaryDirectory(self) -> Path:
return self._binaryDirectory
@property
def Version(self) -> str:
return self._version
@property
def Edition(self) -> str:
return self._edition
@export
class VendorInformation:
_installationDirectory: Path
def __init__(self, installationDirectory: Path):
self._installationDirectory = installationDirectory
@property
def InstallationDirectory(self) -> Path:
return self._installationDirectory
@export
class ToolInstance(ToolInformation):
_tool: Nullable["Tool"]
def __init__(self, installationDirectory: Path, binaryDirectory: Path, version: str = None, edition: str = None, parent: "Tool" = None):
super().__init__(installationDirectory, binaryDirectory, version, edition)
self._tool = parent
@property
def Tool(self) -> "Tool":
return self._tool
@export
class Tool:
_vendor: Nullable["Vendor"]
_name: str
_allLoaded: bool
_variants: Dict[str, ToolInstance]
_instanceClass: ClassVar[Type[ToolInstance]]
def __init__(self, name: str, parent: "Vendor" = None):
self._vendor = parent
self._name = name
self._allLoaded = False
self._variants = {}
def __contains__(self, key: str) -> bool:
self._LoadAllVariants()
return key in self._variants
def __getitem__(self, key: str) -> ToolInstance:
try:
return self._variants[key]
except KeyError:
return self._LoadVariant(key)
@property
def Vendor(self) -> "Vendor":
return self._vendor
@property
def Variants(self) -> Dict[str, ToolInstance]:
self._LoadAllVariants()
return self._variants
@property
def Default(self) -> ToolInstance:
raise NotImplementedError()
def _LoadVariant(self, key: str) -> ToolInstance:
raise NotImplementedError()
def _LoadAllVariants(self) -> None:
raise NotImplementedError()
@export
class Vendor(VendorInformation):
_installation: Nullable["Installation"]
_name: str
_allLoaded: bool
_tools: Dict[str, Tool]
def __init__(self, name: str, installationDirectory: Path, parent: "Installation" = None):
super().__init__(installationDirectory)
self._installation = parent
self._name = name
self._allLoaded = False
self._tools = {}
def __contains__(self, key: str) -> bool:
self._LoadAllTools()
return key in self._tools
def __getitem__(self, key: str) -> Tool:
try:
return self._tools[key]
except KeyError:
return self._LoadTool(key)
def _LoadTool(self, key: str) -> Tool:
raise NotImplementedError()
def _LoadAllTools(self) -> None:
raise NotImplementedError()
@property
def Installation(self) -> "Installation":
return self._installation
@property
def Tools(self) -> Dict[str, Tool]:
self._LoadAllTools()
return self._tools
@export
class Installation:
_allLoaded: bool
_vendors: Dict[str, Vendor]
def __init__(self):
self._allLoaded = False
self._vendors = {}
def __contains__(self, key: str) -> bool:
self._LoadAllVendors()
return key in self._vendor
def __getitem__(self, key: str) -> Vendor:
try:
return self._vendors[key]
except KeyError:
return self._LoadVendor(key)
def _LoadVendor(self, key: str) -> Vendor:
raise NotImplementedError()
def _LoadAllVendors(self) -> None:
raise NotImplementedError()
|