add a wrapper script around does-desktop-entry-exist
so it can be easily ran from the command line
This commit is contained in:
parent
626df1980d
commit
fd4ded438e
2 changed files with 36 additions and 3 deletions
|
@ -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,10 +71,14 @@ 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}"
|
||||
if show_all_paths:
|
||||
print(f"Checking for {entry_file}")
|
||||
if entry_file.is_file():
|
||||
print(f"{desktop_entry} found in {entry_path}")
|
||||
|
|
29
scripts/py/does-desktop-entry-exist.py
Executable file
29
scripts/py/does-desktop-entry-exist.py
Executable 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
|
||||
)
|
Loading…
Reference in a new issue