From 054923f068bbc25d9ecd059f92d2868087ea38f0 Mon Sep 17 00:00:00 2001 From: Softer Date: Sun, 26 Apr 2026 13:52:47 +0300 Subject: [PATCH] Switch list_console_fonts to pathlib and add @lru_cache Address svartkanin's review on #4469. Replace os.listdir + chained removesuffix with Path.glob('*.gz') + split('.')[0], and cache the result via lru_cache - the kbd consolefonts directory is static at runtime so re-scanning on every menu reopen was wasted I/O. --- archinstall/lib/locale/utils.py | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/archinstall/lib/locale/utils.py b/archinstall/lib/locale/utils.py index f29dcccd..497e1fcb 100644 --- a/archinstall/lib/locale/utils.py +++ b/archinstall/lib/locale/utils.py @@ -1,4 +1,5 @@ -import os +from functools import lru_cache +from pathlib import Path from archinstall.lib.command import SysCommand from archinstall.lib.exceptions import ServiceException, SysCallError @@ -28,14 +29,10 @@ def list_locales() -> list[str]: return locales +@lru_cache def list_console_fonts() -> list[str]: - fonts: set[str] = set() - - for entry in os.listdir('/usr/share/kbd/consolefonts'): - if entry.endswith('.gz'): - name = entry.removesuffix('.gz').removesuffix('.psfu').removesuffix('.psf').removesuffix('.cp').removesuffix('.fnt') - fonts.add(name) - + directory = Path('/usr/share/kbd/consolefonts') + fonts = {path.name.split('.')[0] for path in directory.glob('*.gz')} return sorted(fonts)