Compare commits

...

2 Commits

Author SHA1 Message Date
suchmememanyskill 82397cc5d1 Implement feedback for filepicker optimalisations 2023-04-05 19:49:39 +02:00
suchmememanyskill 75b43746a0 Use os.scandir vs os.listdir for filepicker_ls 2023-04-04 18:02:49 +02:00
+14 -14
View File
@@ -181,30 +181,30 @@ class Utilities:
await service_stop(helpers.REMOTE_DEBUGGER_UNIT)
return True
async def filepicker_ls(self, path, include_files=True):
async def filepicker_ls(self, path, include_files : bool = True, max : int = 1000, page : int = 1):
# def sorter(file): # Modification time
# if os.path.isdir(os.path.join(path, file)) or os.path.isfile(os.path.join(path, file)):
# return os.path.getmtime(os.path.join(path, file))
# return 0
# file_names = sorted(os.listdir(path), key=sorter, reverse=True) # TODO provide more sort options
file_names = sorted(os.listdir(path)) # Alphabetical
files = []
realpath = os.path.realpath(path)
files, folders = [], []
for file in file_names:
full_path = os.path.join(path, file)
is_dir = os.path.isdir(full_path)
for x in os.scandir(realpath):
if x.is_dir():
folders.append(x)
elif include_files:
files.append(x)
if is_dir or include_files:
files.append({
"isdir": is_dir,
"name": file,
"realpath": os.path.realpath(full_path)
})
files = sorted(files, key=lambda x: x.name)
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 {
"realpath": os.path.realpath(path),
"files": files
"realpath": realpath,
"files": all[(page-1)*max:(page)*max],
"total": len(all)
}
# Based on https://stackoverflow.com/a/46422554/13174603