diff options
author | AUTOMATIC1111 <16777216c@gmail.com> | 2023-12-30 11:45:28 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-12-30 11:45:28 +0000 |
commit | c9c105c7dbdca65c0fe62f78cd9c9d41f9a5af1f (patch) | |
tree | bb1f0cfec4cc874941f2429d43f68005bf00456f /modules/util.py | |
parent | a79890efd6774098a652887c20238f6c108be172 (diff) | |
parent | 892e703b59b2f867d8a202a52fab1db89882ef86 (diff) | |
download | stable-diffusion-webui-gfx803-c9c105c7dbdca65c0fe62f78cd9c9d41f9a5af1f.tar.gz stable-diffusion-webui-gfx803-c9c105c7dbdca65c0fe62f78cd9c9d41f9a5af1f.tar.bz2 stable-diffusion-webui-gfx803-c9c105c7dbdca65c0fe62f78cd9c9d41f9a5af1f.zip |
Merge pull request #14446 from AUTOMATIC1111/base-output-path-off-data_path
Base output path off data path
Diffstat (limited to 'modules/util.py')
-rw-r--r-- | modules/util.py | 12 |
1 files changed, 11 insertions, 1 deletions
diff --git a/modules/util.py b/modules/util.py index 60afc067..4861bcb0 100644 --- a/modules/util.py +++ b/modules/util.py @@ -2,7 +2,7 @@ import os import re
from modules import shared
-from modules.paths_internal import script_path
+from modules.paths_internal import script_path, cwd
def natural_sort_key(s, regex=re.compile('([0-9]+)')):
@@ -56,3 +56,13 @@ def ldm_print(*args, **kwargs): return
print(*args, **kwargs)
+
+
+def truncate_path(target_path, base_path=cwd):
+ abs_target, abs_base = os.path.abspath(target_path), os.path.abspath(base_path)
+ try:
+ if os.path.commonpath([abs_target, abs_base]) == abs_base:
+ return os.path.relpath(abs_target, abs_base)
+ except ValueError:
+ pass
+ return abs_target
|