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.
This commit is contained in:
Softer 2026-04-26 13:52:47 +03:00
parent 22763f425c
commit 054923f068
1 changed files with 5 additions and 8 deletions

View File

@ -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)