Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
chenpangpang
ComfyUI
Commits
8ef197f0
"...git@developer.sourcefind.cn:wangsen/paddle_dbnet.git" did not exist on "b1623d69a57e2277545bf1cf511ec82458bbd106"
Commit
8ef197f0
authored
May 29, 2023
by
comfyanonymous
Browse files
Keep list of filenames and only refresh it when something changes.
parent
2260802d
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
43 additions
and
4 deletions
+43
-4
folder_paths.py
folder_paths.py
+43
-4
No files found.
folder_paths.py
View file @
8ef197f0
...
@@ -31,6 +31,8 @@ output_directory = os.path.join(os.path.dirname(os.path.realpath(__file__)), "ou
...
@@ -31,6 +31,8 @@ output_directory = os.path.join(os.path.dirname(os.path.realpath(__file__)), "ou
temp_directory
=
os
.
path
.
join
(
os
.
path
.
dirname
(
os
.
path
.
realpath
(
__file__
)),
"temp"
)
temp_directory
=
os
.
path
.
join
(
os
.
path
.
dirname
(
os
.
path
.
realpath
(
__file__
)),
"temp"
)
input_directory
=
os
.
path
.
join
(
os
.
path
.
dirname
(
os
.
path
.
realpath
(
__file__
)),
"input"
)
input_directory
=
os
.
path
.
join
(
os
.
path
.
dirname
(
os
.
path
.
realpath
(
__file__
)),
"input"
)
filename_list_cache
=
{}
if
not
os
.
path
.
exists
(
input_directory
):
if
not
os
.
path
.
exists
(
input_directory
):
os
.
makedirs
(
input_directory
)
os
.
makedirs
(
input_directory
)
...
@@ -111,12 +113,18 @@ def get_folder_paths(folder_name):
...
@@ -111,12 +113,18 @@ def get_folder_paths(folder_name):
return
folder_names_and_paths
[
folder_name
][
0
][:]
return
folder_names_and_paths
[
folder_name
][
0
][:]
def
recursive_search
(
directory
):
def
recursive_search
(
directory
):
if
not
os
.
path
.
isdir
(
directory
):
return
[],
{}
result
=
[]
result
=
[]
dirs
=
{
directory
:
os
.
path
.
getmtime
(
directory
)}
for
root
,
subdir
,
file
in
os
.
walk
(
directory
,
followlinks
=
True
):
for
root
,
subdir
,
file
in
os
.
walk
(
directory
,
followlinks
=
True
):
for
filepath
in
file
:
for
filepath
in
file
:
#we os.path,join directory with a blank string to generate a path separator at the end.
#we os.path,join directory with a blank string to generate a path separator at the end.
result
.
append
(
os
.
path
.
join
(
root
,
filepath
).
replace
(
os
.
path
.
join
(
directory
,
''
),
''
))
result
.
append
(
os
.
path
.
join
(
root
,
filepath
).
replace
(
os
.
path
.
join
(
directory
,
''
),
''
))
return
result
for
d
in
subdir
:
path
=
os
.
path
.
join
(
root
,
d
)
dirs
[
path
]
=
os
.
path
.
getmtime
(
path
)
return
result
,
dirs
def
filter_files_extensions
(
files
,
extensions
):
def
filter_files_extensions
(
files
,
extensions
):
return
sorted
(
list
(
filter
(
lambda
a
:
os
.
path
.
splitext
(
a
)[
-
1
].
lower
()
in
extensions
,
files
)))
return
sorted
(
list
(
filter
(
lambda
a
:
os
.
path
.
splitext
(
a
)[
-
1
].
lower
()
in
extensions
,
files
)))
...
@@ -136,13 +144,44 @@ def get_full_path(folder_name, filename):
...
@@ -136,13 +144,44 @@ def get_full_path(folder_name, filename):
return
None
return
None
def
get_filename_list
(
folder_name
):
def
get_filename_list
_
(
folder_name
):
global
folder_names_and_paths
global
folder_names_and_paths
output_list
=
set
()
output_list
=
set
()
folders
=
folder_names_and_paths
[
folder_name
]
output_folders
=
{}
for
x
in
folders
[
0
]:
files
,
folders_all
=
recursive_search
(
x
)
output_list
.
update
(
filter_files_extensions
(
files
,
folders
[
1
]))
output_folders
=
{
**
output_folders
,
**
folders_all
}
return
(
sorted
(
list
(
output_list
)),
output_folders
)
def
cached_filename_list_
(
folder_name
):
global
filename_list_cache
global
folder_names_and_paths
if
folder_name
not
in
filename_list_cache
:
return
None
out
=
filename_list_cache
[
folder_name
]
for
x
in
out
[
1
]:
time_modified
=
out
[
1
][
x
]
folder
=
x
if
os
.
path
.
getmtime
(
folder
)
!=
time_modified
:
return
None
folders
=
folder_names_and_paths
[
folder_name
]
folders
=
folder_names_and_paths
[
folder_name
]
for
x
in
folders
[
0
]:
for
x
in
folders
[
0
]:
output_list
.
update
(
filter_files_extensions
(
recursive_search
(
x
),
folders
[
1
]))
if
x
not
in
out
[
1
]:
return
sorted
(
list
(
output_list
))
return
None
return
out
def
get_filename_list
(
folder_name
):
out
=
cached_filename_list_
(
folder_name
)
if
out
is
None
:
out
=
get_filename_list_
(
folder_name
)
global
filename_list_cache
filename_list_cache
[
folder_name
]
=
out
return
out
[
0
]
def
get_save_image_path
(
filename_prefix
,
output_dir
,
image_width
=
0
,
image_height
=
0
):
def
get_save_image_path
(
filename_prefix
,
output_dir
,
image_width
=
0
,
image_height
=
0
):
def
map_filename
(
filename
):
def
map_filename
(
filename
):
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment