mirror of
https://github.com/AUTOMATIC1111/stable-diffusion-webui.git
synced 2025-08-03 10:50:23 +00:00
open_folder as util
This commit is contained in:
@@ -136,3 +136,36 @@ class MassFileLister:
|
||||
def reset(self):
|
||||
"""Clear the cache of all directories."""
|
||||
self.cached_dirs.clear()
|
||||
|
||||
def open_folder(path):
|
||||
# import at function level to avoid potential issues
|
||||
import gradio as gr
|
||||
import platform
|
||||
import sys
|
||||
import subprocess
|
||||
|
||||
if not os.path.exists(path):
|
||||
msg = f'Folder "{path}" does not exist. after you save an image, the folder will be created.'
|
||||
print(msg)
|
||||
gr.Info(msg)
|
||||
return
|
||||
elif not os.path.isdir(path):
|
||||
msg = f"""
|
||||
WARNING
|
||||
An open_folder request was made with an path that is not a folder.
|
||||
This could be an error or a malicious attempt to run code on your computer.
|
||||
Requested path was: {path}
|
||||
"""
|
||||
print(msg, file=sys.stderr)
|
||||
gr.Warning(msg)
|
||||
return
|
||||
|
||||
path = os.path.normpath(path)
|
||||
if platform.system() == "Windows":
|
||||
os.startfile(path)
|
||||
elif platform.system() == "Darwin":
|
||||
subprocess.Popen(["open", path])
|
||||
elif "microsoft-standard-WSL2" in platform.uname().release:
|
||||
subprocess.Popen(["wsl-open", path])
|
||||
else:
|
||||
subprocess.Popen(["xdg-open", path])
|
||||
|
Reference in New Issue
Block a user