From 440844bfabbba0ae63f7a27fda68e456f48edb97 Mon Sep 17 00:00:00 2001 From: Tom Willemsen Date: Wed, 16 Oct 2024 20:05:06 +0100 Subject: [PATCH] lint --- .../ibex_install_utils/admin_runner.py | 20 +++++++++++-------- .../ibex_install_utils/tasks/mysql_tasks.py | 11 ++++------ 2 files changed, 16 insertions(+), 15 deletions(-) diff --git a/installation_and_upgrade/ibex_install_utils/admin_runner.py b/installation_and_upgrade/ibex_install_utils/admin_runner.py index d14ab96..8624a39 100644 --- a/installation_and_upgrade/ibex_install_utils/admin_runner.py +++ b/installation_and_upgrade/ibex_install_utils/admin_runner.py @@ -2,11 +2,12 @@ import os import tempfile from time import sleep +from typing import Any, Generator class AdminRunner: @staticmethod - def run_command(command, parameters, expected_return_val=0): + def run_command(command: str, parameters: str, expected_return_val: int | None = 0) -> None: try: import win32api import win32con @@ -40,13 +41,15 @@ class AdminCommandBuilder: Builder for running multiple commands sequentially as admin. """ - def __init__(self): - self._commands = [] + def __init__(self) -> None: + self._commands: list[tuple[str, str, int | None]] = [] - def add_command(self, command, parameters, expected_return_val=0): + def add_command( + self, command: str, parameters: str, expected_return_val: int | None = 0 + ) -> None: self._commands.append((command, parameters, expected_return_val)) - def run_all(self): + def run_all(self) -> str: bat_file = "" log_file = tempfile.NamedTemporaryFile(mode="w+t", suffix=".log", delete=False) @@ -63,7 +66,8 @@ def run_all(self): with temp_bat_file(bat_file) as f: print( - f"Executing bat script as admin. Saved as {f}. Check for an admin prompt. Log at {log_file.name}." + f"Executing bat script as admin. Saved as {f}. Check for an admin prompt. " + f"Log at {log_file.name}." ) sleep(1) # Wait for file handle to be closed etc try: @@ -80,9 +84,9 @@ def run_all(self): @contextlib.contextmanager -def temp_bat_file(contents): +def temp_bat_file(contents: str) -> Generator[str, None, Any]: + f = tempfile.NamedTemporaryFile(mode="w+t", suffix=".bat", delete=False) try: - f = tempfile.NamedTemporaryFile(mode="w+t", suffix=".bat", delete=False) f.write(contents) f.close() yield f.name diff --git a/installation_and_upgrade/ibex_install_utils/tasks/mysql_tasks.py b/installation_and_upgrade/ibex_install_utils/tasks/mysql_tasks.py index 312aeab..3ea2240 100644 --- a/installation_and_upgrade/ibex_install_utils/tasks/mysql_tasks.py +++ b/installation_and_upgrade/ibex_install_utils/tasks/mysql_tasks.py @@ -4,6 +4,7 @@ import subprocess import zipfile from time import sleep +from typing import Generator from ibex_install_utils.admin_runner import AdminCommandBuilder from ibex_install_utils.exceptions import ErrorInRun @@ -27,11 +28,7 @@ # For Py2 compatibility, can be removed once we are on Py3. DETACHED_PROCESS = 0x00000008 -try: - from contextlib import closing -except ImportError: - from contextlib2 import closing - +from contextlib import closing MYSQL8_INSTALL_DIR = os.path.join(APPS_BASE_DIR, "MySQL") MYSQL57_INSTALL_DIR = os.path.join("C:\\", "Program Files", "MySQL", "MySQL Server 5.7") @@ -193,7 +190,7 @@ def _initialize_mysql_data_area_for_vhd(self) -> None: ).run() @contextlib.contextmanager - def temporarily_run_mysql(self, sql_password: str) -> None: + def temporarily_run_mysql(self, sql_password: str) -> Generator[None, None, None]: mysqld = os.path.join(MYSQL8_INSTALL_DIR, "bin", "mysqld.exe") # spawn service in background @@ -325,7 +322,7 @@ def install_mysql_for_vhd(self) -> None: Ensure we start from a clean slate. We are creating VHDs so we can assume that no files should exist in - C:\instrument\apps\mysql or c:\instrument\var\mysql and + C:\\instrument\\apps\\mysql or c:\\instrument\\var\\mysql and delete them if they do exist. This facilitates developer testing/resuming the script if it failed halfway through """