From 6bc2ca4803d7dc99340bf1eab9a7866ca0617482 Mon Sep 17 00:00:00 2001 From: Concedo <39025047+LostRuins@users.noreply.github.com> Date: Mon, 14 Apr 2025 15:06:08 +0800 Subject: [PATCH] added more sanity checks on zenity --- koboldcpp.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/koboldcpp.py b/koboldcpp.py index bc4787691..921b790a3 100644 --- a/koboldcpp.py +++ b/koboldcpp.py @@ -3513,6 +3513,20 @@ def zenity(filetypes=None, initialdir="", initialfile="", **kwargs) -> Tuple[int .replace("?", "\\?").replace("&", "&").replace("|", "|").replace("<", "<").replace(">", ">")\ .replace("(", "\\(").replace(")", "\\)").replace("[", "\\[").replace("]", "\\]").replace("{", "\\{").replace("}", "\\}") + def zenity_sanity_check(): #make sure zenity is sane + nonlocal zenity_bin + try: # Run `zenity --help` and pipe to grep + result = subprocess.run(f"{zenity_bin} --help | grep Usage", shell=True, capture_output=True, text=True) + if result.returncode == 0 and "Usage" in result.stdout: + return True + else: + return False + except FileNotFoundError: + return False + + if not zenity_sanity_check(): + raise Exception("Zenity not working correctly, falling back to TK GUI.") + # Build args based on keywords args = ['/usr/bin/env', zenity_bin, '--file-selection'] for k, v in kwargs.items():