use pathlib everywhere

This commit is contained in:
Jörg Thalheim
2024-09-02 18:25:17 +02:00
parent 9de48de991
commit 1fa0e72bea
28 changed files with 88 additions and 113 deletions

View File

@@ -64,7 +64,7 @@ def _init_proc(
os.setsid()
# Open stdout and stderr
with open(out_file, "w") as out_fd:
with out_file.open("w") as out_fd:
os.dup2(out_fd.fileno(), sys.stdout.fileno())
os.dup2(out_fd.fileno(), sys.stderr.fileno())

View File

@@ -21,6 +21,7 @@
import os
import sys
import tempfile
from collections.abc import Callable
from typing import Any, ClassVar
@@ -884,14 +885,8 @@ class Win32Implementation(BaseImplementation):
# No custom icons present, fall back to default icons
ico_buffer = self._load_ico_buffer(icon_name, icon_size)
try:
import tempfile
file_handle = tempfile.NamedTemporaryFile(delete=False)
with file_handle:
file_handle.write(ico_buffer)
with tempfile.NamedTemporaryFile(delete=False) as file_handle:
file_handle.write(ico_buffer)
return windll.user32.LoadImageA(
0,
encode_path(file_handle.name),
@@ -901,9 +896,6 @@ class Win32Implementation(BaseImplementation):
self.LR_LOADFROMFILE,
)
finally:
os.remove(file_handle.name)
def _destroy_h_icon(self):
from ctypes import windll

View File

@@ -279,7 +279,7 @@ class VMObject(GObject.Object):
if not self._log_file:
try:
self._log_file = open(proc.out_file) # noqa: SIM115
self._log_file = Path(proc.out_file).open() # noqa: SIM115
except Exception as ex:
log.exception(ex)
self._log_file = None

View File

@@ -273,8 +273,7 @@ class ClanList(Gtk.Box):
logs.set_title(f"""📄<span weight="normal"> {name}</span>""")
# initial message. Streaming happens automatically when the file is changed by the build process
with open(vm.build_process.out_file) as f:
logs.set_message(f.read())
logs.set_message(vm.build_process.out_file.read_text())
views.set_visible_child_name("logs")