Skip to content

Commit

Permalink
lint
Browse files Browse the repository at this point in the history
  • Loading branch information
Tom-Willemsen committed Oct 16, 2024
1 parent 2d28d16 commit 440844b
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 15 deletions.
20 changes: 12 additions & 8 deletions installation_and_upgrade/ibex_install_utils/admin_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand All @@ -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:
Expand All @@ -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
Expand Down
11 changes: 4 additions & 7 deletions installation_and_upgrade/ibex_install_utils/tasks/mysql_tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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")
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
"""
Expand Down

0 comments on commit 440844b

Please sign in to comment.