diff options
author | AUTOMATIC1111 <16777216c@gmail.com> | 2024-01-03 23:28:05 +0000 |
---|---|---|
committer | AUTOMATIC1111 <16777216c@gmail.com> | 2024-01-03 23:28:05 +0000 |
commit | 420f56c2e85ebbd3f530cf2c7b22022fda13ae13 (patch) | |
tree | fc11a8c4cb10138a1673f9b758539ddc37414fca /modules/ui_extra_networks.py | |
parent | 04a005f0e98ebade44b33237bf4ccaa64f12600a (diff) | |
download | stable-diffusion-webui-gfx803-420f56c2e85ebbd3f530cf2c7b22022fda13ae13.tar.gz stable-diffusion-webui-gfx803-420f56c2e85ebbd3f530cf2c7b22022fda13ae13.tar.bz2 stable-diffusion-webui-gfx803-420f56c2e85ebbd3f530cf2c7b22022fda13ae13.zip |
mass file lister as an attempt to tackle #14507
Diffstat (limited to 'modules/ui_extra_networks.py')
-rw-r--r-- | modules/ui_extra_networks.py | 18 |
1 files changed, 12 insertions, 6 deletions
diff --git a/modules/ui_extra_networks.py b/modules/ui_extra_networks.py index e1c679ec..c06c8664 100644 --- a/modules/ui_extra_networks.py +++ b/modules/ui_extra_networks.py @@ -3,7 +3,7 @@ import os.path import urllib.parse
from pathlib import Path
-from modules import shared, ui_extra_networks_user_metadata, errors, extra_networks
+from modules import shared, ui_extra_networks_user_metadata, errors, extra_networks, util
from modules.images import read_info_from_image, save_image_with_geninfo
import gradio as gr
import json
@@ -107,6 +107,7 @@ class ExtraNetworksPage: self.allow_negative_prompt = False
self.metadata = {}
self.items = {}
+ self.lister = util.MassFileLister()
def refresh(self):
pass
@@ -123,7 +124,7 @@ class ExtraNetworksPage: def link_preview(self, filename):
quoted_filename = urllib.parse.quote(filename.replace('\\', '/'))
- mtime = os.path.getmtime(filename)
+ mtime, _ = self.lister.mctime(filename)
return f"./sd_extra_networks/thumb?filename={quoted_filename}&mtime={mtime}"
def search_terms_from_path(self, filename, possible_directories=None):
@@ -137,6 +138,8 @@ class ExtraNetworksPage: return ""
def create_html(self, tabname):
+ self.lister.reset()
+
items_html = ''
self.metadata = {}
@@ -282,10 +285,10 @@ class ExtraNetworksPage: List of default keys used for sorting in the UI.
"""
pth = Path(path)
- stat = pth.stat()
+ mtime, ctime = self.lister.mctime(path)
return {
- "date_created": int(stat.st_ctime or 0),
- "date_modified": int(stat.st_mtime or 0),
+ "date_created": int(mtime),
+ "date_modified": int(ctime),
"name": pth.name.lower(),
"path": str(pth.parent).lower(),
}
@@ -298,7 +301,7 @@ class ExtraNetworksPage: potential_files = sum([[path + "." + ext, path + ".preview." + ext] for ext in allowed_preview_extensions()], [])
for file in potential_files:
- if os.path.isfile(file):
+ if self.lister.exists(file):
return self.link_preview(file)
return None
@@ -308,6 +311,9 @@ class ExtraNetworksPage: Find and read a description file for a given path (without extension).
"""
for file in [f"{path}.txt", f"{path}.description.txt"]:
+ if not self.lister.exists(file):
+ continue
+
try:
with open(file, "r", encoding="utf-8", errors="replace") as f:
return f.read()
|