Implement feedback for filepicker optimalisations

This commit is contained in:
suchmememanyskill
2023-04-05 19:49:39 +02:00
parent 75b43746a0
commit 82397cc5d1
+13 -13
View File
@@ -188,23 +188,23 @@ class Utilities:
# return 0 # return 0
# file_names = sorted(os.listdir(path), key=sorter, reverse=True) # TODO provide more sort options # file_names = sorted(os.listdir(path), key=sorter, reverse=True) # TODO provide more sort options
items = list(os.scandir(path)) realpath = os.path.realpath(path)
files = sorted([x for x in items if x.is_file()], key=lambda x: x.name) files, folders = [], []
folders = sorted([x for x in items if x.is_dir()], key=lambda x: x.name)
def to_dict(entry : os.DirEntry[str], is_dir : bool): for x in os.scandir(realpath):
return { if x.is_dir():
"isdir": is_dir, folders.append(x)
"name": entry.name, elif include_files:
"realpath": os.path.realpath(entry.path) files.append(x)
}
files = sorted(files, key=lambda x: x.name)
all = [to_dict(x, True) for x in folders] + ([to_dict(x, False) for x in files] if include_files else []) folders = sorted(folders, key=lambda x: x.name)
all = [{ "isdir": x.is_dir(), "name": x.name, "realpath": x.path } for x in folders + files]
return { return {
"realpath": os.path.realpath(path), "realpath": realpath,
"files": all[(page-1)*max:(page)*max], "files": all[(page-1)*max:(page)*max],
"total": len(items) "total": len(all)
} }
# Based on https://stackoverflow.com/a/46422554/13174603 # Based on https://stackoverflow.com/a/46422554/13174603