mirror of
https://github.com/lllyasviel/stable-diffusion-webui-forge.git
synced 2026-03-14 01:19:49 +00:00
Gradio 4 + WebUI 1.10
This commit is contained in:
@@ -81,6 +81,17 @@ class MassFileListerCachedDir:
|
||||
self.files = {x[0].lower(): x for x in files}
|
||||
self.files_cased = {x[0]: x for x in files}
|
||||
|
||||
def update_entry(self, filename):
|
||||
"""Add a file to the cache"""
|
||||
file_path = os.path.join(self.dirname, filename)
|
||||
try:
|
||||
stat = os.stat(file_path)
|
||||
entry = (filename, stat.st_mtime, stat.st_ctime)
|
||||
self.files[filename.lower()] = entry
|
||||
self.files_cased[filename] = entry
|
||||
except FileNotFoundError as e:
|
||||
print(f'MassFileListerCachedDir.add_entry: "{file_path}" {e}')
|
||||
|
||||
|
||||
class MassFileLister:
|
||||
"""A class that provides a way to check for the existence and mtime/ctile of files without doing more than one stat call per file."""
|
||||
@@ -136,3 +147,67 @@ class MassFileLister:
|
||||
def reset(self):
|
||||
"""Clear the cache of all directories."""
|
||||
self.cached_dirs.clear()
|
||||
|
||||
def update_file_entry(self, path):
|
||||
"""Update the cache for a specific directory."""
|
||||
dirname, filename = os.path.split(path)
|
||||
if cached_dir := self.cached_dirs.get(dirname):
|
||||
cached_dir.update_entry(filename)
|
||||
|
||||
def topological_sort(dependencies):
|
||||
"""Accepts a dictionary mapping name to its dependencies, returns a list of names ordered according to dependencies.
|
||||
Ignores errors relating to missing dependencies or circular dependencies
|
||||
"""
|
||||
|
||||
visited = {}
|
||||
result = []
|
||||
|
||||
def inner(name):
|
||||
visited[name] = True
|
||||
|
||||
for dep in dependencies.get(name, []):
|
||||
if dep in dependencies and dep not in visited:
|
||||
inner(dep)
|
||||
|
||||
result.append(name)
|
||||
|
||||
for depname in dependencies:
|
||||
if depname not in visited:
|
||||
inner(depname)
|
||||
|
||||
return result
|
||||
|
||||
|
||||
def open_folder(path):
|
||||
"""Open a folder in the file manager of the respect OS."""
|
||||
# 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(["explorer.exe", subprocess.check_output(["wslpath", "-w", path])])
|
||||
else:
|
||||
subprocess.Popen(["xdg-open", path])
|
||||
|
||||
Reference in New Issue
Block a user