Skip to content

Commit 00dc700

Browse files
authored
initial attempt to check version of tl-install
1 parent 71d2832 commit 00dc700

File tree

1 file changed

+83
-0
lines changed

1 file changed

+83
-0
lines changed

platform.py

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,84 @@ def packages_dir(self) -> str:
159159
self._packages_dir = config.get("platformio", "packages_dir")
160160
return self._packages_dir
161161

162+
def _check_tl_install_version(self) -> bool:
163+
"""
164+
Prüft ob tl-install in der korrekten Version installiert ist.
165+
Installiert die korrekte Version falls erforderlich.
166+
"""
167+
tl_install_name = "tl-install"
168+
169+
# Hole die erforderliche Version aus platform.json
170+
required_version = self.packages.get(tl_install_name, {}).get("version")
171+
if not required_version:
172+
logger.debug(f"Keine Versionsprüfung für {tl_install_name} erforderlich")
173+
return True
174+
175+
# Prüfe ob das Tool bereits installiert ist
176+
tl_install_path = os.path.join(self.packages_dir, tl_install_name)
177+
package_json_path = os.path.join(tl_install_path, "package.json")
178+
179+
if not os.path.exists(package_json_path):
180+
logger.info(f"{tl_install_name} nicht installiert, installiere Version {required_version}")
181+
return self._install_tl_install(required_version)
182+
183+
# Lese die installierte Version
184+
try:
185+
with open(package_json_path, 'r', encoding='utf-8') as f:
186+
package_data = json.load(f)
187+
188+
installed_version = package_data.get("version")
189+
if not installed_version:
190+
logger.warning(f"Installierte Version für {tl_install_name} unbekannt")
191+
return self._install_tl_install(required_version)
192+
193+
# Vergleiche Versionen
194+
if installed_version != required_version:
195+
logger.info(
196+
f"Versionsfehler für {tl_install_name}: "
197+
f"{installed_version} != {required_version}, installiere korrekte Version"
198+
)
199+
return self._install_tl_install(required_version)
200+
201+
logger.debug(f"{tl_install_name} Version {installed_version} ist korrekt")
202+
return True
203+
204+
except (json.JSONDecodeError, FileNotFoundError) as e:
205+
logger.error(f"Fehler beim Lesen der Paketdaten für {tl_install_name}: {e}")
206+
return self._install_tl_install(required_version)
207+
208+
def _install_tl_install(self, version: str) -> bool:
209+
"""
210+
Installiert tl-install in der angegebenen Version.
211+
"""
212+
tl_install_name = "tl-install"
213+
tl_install_path = os.path.join(self.packages_dir, tl_install_name)
214+
215+
try:
216+
# Entferne alte Installation
217+
if os.path.exists(tl_install_path):
218+
logger.info(f"Entferne alte {tl_install_name} Installation")
219+
safe_remove_directory(tl_install_path)
220+
221+
# Entferne auch versionierte Verzeichnisse
222+
safe_remove_directory_pattern(self.packages_dir, f"{tl_install_name}@*")
223+
safe_remove_directory_pattern(self.packages_dir, f"{tl_install_name}.*")
224+
225+
# Installiere neue Version
226+
logger.info(f"Installiere {tl_install_name} Version {version}")
227+
self.packages[tl_install_name]["optional"] = False
228+
self.packages[tl_install_name]["version"] = version
229+
230+
# Verwende den Package Manager für die Installation
231+
pm.install(f"{tl_install_name}@{version}")
232+
233+
logger.info(f"{tl_install_name} Version {version} erfolgreich installiert")
234+
return True
235+
236+
except Exception as e:
237+
logger.error(f"Fehler bei der Installation von {tl_install_name}: {e}")
238+
return False
239+
162240
def _get_tool_paths(self, tool_name: str) -> Dict[str, str]:
163241
"""Get centralized path calculation for tools with caching."""
164242
if tool_name not in self._tools_cache:
@@ -424,6 +502,11 @@ def _configure_mcu_toolchains(
424502

425503
def _configure_installer(self) -> None:
426504
"""Configure the ESP-IDF tools installer."""
505+
506+
if not self._check_tl_install_version():
507+
logger.error("Error during tl-install version check / installation")
508+
return
509+
427510
installer_path = os.path.join(
428511
self.packages_dir, "tl-install", "tools", "idf_tools.py"
429512
)

0 commit comments

Comments
 (0)