Skip to content

Commit 054923f

Browse files
committed
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.
1 parent 22763f4 commit 054923f

1 file changed

Lines changed: 5 additions & 8 deletions

File tree

archinstall/lib/locale/utils.py

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
import os
1+
from functools import lru_cache
2+
from pathlib import Path
23

34
from archinstall.lib.command import SysCommand
45
from archinstall.lib.exceptions import ServiceException, SysCallError
@@ -28,14 +29,10 @@ def list_locales() -> list[str]:
2829
return locales
2930

3031

32+
@lru_cache
3133
def list_console_fonts() -> list[str]:
32-
fonts: set[str] = set()
33-
34-
for entry in os.listdir('/usr/share/kbd/consolefonts'):
35-
if entry.endswith('.gz'):
36-
name = entry.removesuffix('.gz').removesuffix('.psfu').removesuffix('.psf').removesuffix('.cp').removesuffix('.fnt')
37-
fonts.add(name)
38-
34+
directory = Path('/usr/share/kbd/consolefonts')
35+
fonts = {path.name.split('.')[0] for path in directory.glob('*.gz')}
3936
return sorted(fonts)
4037

4138

0 commit comments

Comments
 (0)