add a wrapper script around does-desktop-entry-exist so it can be easily ran from the command line

This commit is contained in:
Seaswimmer 2024-12-12 11:51:19 -05:00
parent 626df1980d
commit fd4ded438e
Signed by: cswimr
GPG key ID: 0EC431A8DA8F8087
2 changed files with 36 additions and 3 deletions

View file

@ -47,7 +47,7 @@ def read_secret_file(secret: str, home: bool = False) -> str:
return secret
def does_desktop_entry_exist(desktop_entry: str) -> bool:
def does_desktop_entry_exist(desktop_entry: str, show_all_paths: bool = True) -> bool:
if not desktop_entry:
raise ValueError("Please provide the full filename of the desktop entry.")
@ -71,11 +71,15 @@ def does_desktop_entry_exist(desktop_entry: str) -> bool:
entry_paths = [os.path.join(path, "applications") for path in xdg_data_dirs]
entry_paths.append(os.path.expanduser("~/.local/share/applications"))
print(f"Checking the following paths for {desktop_entry}:\n{entry_paths}\n{'-'*20}")
if show_all_paths:
print(
f"Checking the following paths for {desktop_entry}:\n{entry_paths}\n{'-'*20}"
)
for entry_path in entry_paths:
entry_file = Path(entry_path) / f"{desktop_entry}"
print(f"Checking for {entry_file}")
if show_all_paths:
print(f"Checking for {entry_file}")
if entry_file.is_file():
print(f"{desktop_entry} found in {entry_path}")
return True

View file

@ -0,0 +1,29 @@
#! /usr/bin/env nix-shell
#! nix-shell /etc/nixos/scripts/nix/python.nix -i python
import argparse
from common.common import does_desktop_entry_exist # type: ignore
if __name__ == "__main__":
parser = argparse.ArgumentParser(
prog="does-desktop-entry-exist.py",
description="Check if a desktop entry exists.",
epilog="Example usage: does-desktop-entry-exist.py org.kde.konsole",
)
parser.add_argument(
"desktop_entry",
help="The desktop entry to check for.",
)
parser.add_argument(
"-v",
"--verbose",
help="Prints all of the paths that will be checked by the script. Exists so NixOS users don't get their terminals flooded when running the script.",
action="store_true",
)
args = parser.parse_args()
does_desktop_entry_exist(
desktop_entry=args.desktop_entry, show_all_paths=args.verbose
)