From 33b4502d1dcad1f76f68c040addc0bce6bc9b614 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ga=C3=ABl=20=C3=89corchard?= Date: Wed, 17 Jan 2024 08:22:44 +0100 Subject: [PATCH] Exclude non directories from icon path cache MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Gaël Écorchard --- mounch.py | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/mounch.py b/mounch.py index 67abf3a..49029e0 100755 --- a/mounch.py +++ b/mounch.py @@ -50,7 +50,7 @@ import collections import glob import os -import pathlib +from pathlib import Path import shutil import subprocess import sys @@ -83,16 +83,17 @@ class MounchExp(Exception): def cache_iconpath(): - def gpath(bpath: str, wildcards: str) -> list[pathlib.Path]: + def gpath(bpath: str, wildcards: str) -> list[Path]: return [ - pathlib.Path(x) + Path(x) for x in glob.glob(f"{os.path.expanduser(bpath)}/{wildcards}") + if Path(x).is_dir() ] paths = [ - pathlib.Path("~/.local/share/icons/").expanduser(), - pathlib.Path("/usr/share/icons"), - pathlib.Path("/usr/share/pixmaps"), + Path("~/.local/share/icons/").expanduser(), + Path("/usr/share/icons"), + Path("/usr/share/pixmaps"), ] paths += gpath("/usr/share/icons", "*/64x64/*") paths += gpath("/usr/share/icons", "*/48x48/*") @@ -164,7 +165,7 @@ def parse_arguments(): def generate_desktop_entries(directory: str, config: dict): - dexpanded: pathlib.Path = pathlib.Path(directory).expanduser() + dexpanded: Path = Path(directory).expanduser() if not dexpanded.exists(): print(f"{dexpanded} does not exists") sys.exit(1) @@ -196,8 +197,8 @@ def main(): print("we can't have both rofi and wofi") sys.exit(1) - cache_file = pathlib.Path("~/.cache/mounch/cache").expanduser() - configfile = pathlib.Path("~/.config/mounch/mounch.yaml").expanduser() + cache_file = Path("~/.cache/mounch/cache").expanduser() + configfile = Path("~/.config/mounch/mounch.yaml").expanduser() cached_entries = {} if not configfile.exists(): @@ -304,7 +305,7 @@ def main(): encoding="utf-8", ) - binarypath = pathlib.Path(chosen["binary"]).expanduser() + binarypath = Path(chosen["binary"]).expanduser() binary = shutil.which(binarypath) if not binary: print(f"Cannot find executable \"{chosen['binary']}\"")