go back to single path for filenames in extra networks metadata dialog
This commit is contained in:
parent
4aaae3dc65
commit
edf3ad5aed
|
@ -2,22 +2,13 @@ import datetime
|
||||||
import html
|
import html
|
||||||
import json
|
import json
|
||||||
import os.path
|
import os.path
|
||||||
from pathlib import Path
|
|
||||||
|
|
||||||
import gradio as gr
|
import gradio as gr
|
||||||
|
|
||||||
from modules import generation_parameters_copypaste, images, sysinfo, errors
|
from modules import generation_parameters_copypaste, images, sysinfo, errors, ui_extra_networks
|
||||||
from modules.paths_internal import models_path
|
from modules.paths_internal import models_path
|
||||||
|
|
||||||
|
|
||||||
def exclude_root_path(root_path, path):
|
|
||||||
path_object = Path(path)
|
|
||||||
if path_object.is_relative_to(root_path):
|
|
||||||
path_object = path_object.relative_to(root_path)
|
|
||||||
|
|
||||||
return path_object.as_posix()
|
|
||||||
|
|
||||||
|
|
||||||
class UserMetadataEditor:
|
class UserMetadataEditor:
|
||||||
|
|
||||||
def __init__(self, ui, tabname, page):
|
def __init__(self, ui, tabname, page):
|
||||||
|
@ -99,6 +90,13 @@ class UserMetadataEditor:
|
||||||
|
|
||||||
return preview
|
return preview
|
||||||
|
|
||||||
|
def relative_path(self, path):
|
||||||
|
for parent_path in self.page.allowed_directories_for_previews():
|
||||||
|
if ui_extra_networks.path_is_parent(parent_path, path):
|
||||||
|
return os.path.relpath(path, parent_path)
|
||||||
|
|
||||||
|
return os.path.basename(path)
|
||||||
|
|
||||||
def get_metadata_table(self, name):
|
def get_metadata_table(self, name):
|
||||||
item = self.page.items.get(name, {})
|
item = self.page.items.get(name, {})
|
||||||
try:
|
try:
|
||||||
|
@ -107,8 +105,7 @@ class UserMetadataEditor:
|
||||||
|
|
||||||
stats = os.stat(filename)
|
stats = os.stat(filename)
|
||||||
params = [
|
params = [
|
||||||
('Filename: ', os.path.basename(filename)),
|
('Filename: ', self.relative_path(filename)),
|
||||||
('Path: ', exclude_root_path(models_path, filename)),
|
|
||||||
('File size: ', sysinfo.pretty_bytes(stats.st_size)),
|
('File size: ', sysinfo.pretty_bytes(stats.st_size)),
|
||||||
('Hash: ', shorthash),
|
('Hash: ', shorthash),
|
||||||
('Modified: ', datetime.datetime.fromtimestamp(stats.st_mtime).strftime('%Y-%m-%d %H:%M')),
|
('Modified: ', datetime.datetime.fromtimestamp(stats.st_mtime).strftime('%Y-%m-%d %H:%M')),
|
||||||
|
|
Loading…
Reference in New Issue