Web Interface ok
This commit is contained in:
46
ums/utils/functions.py
Normal file
46
ums/utils/functions.py
Normal file
@ -0,0 +1,46 @@
|
||||
import os
|
||||
|
||||
from typing import List, Callable
|
||||
|
||||
from ums.utils.const import SHARE_PATH
|
||||
|
||||
def list_path(path:str) -> List[str]:
|
||||
if os.path.isdir(path):
|
||||
items = []
|
||||
for item in os.listdir(path):
|
||||
full = os.path.join(path, item)
|
||||
if os.path.isdir(full):
|
||||
items.extend(list_path(full))
|
||||
elif os.path.isfile(full):
|
||||
items.append(full)
|
||||
return items
|
||||
else:
|
||||
return []
|
||||
|
||||
def list_shared(filter:Callable=lambda p,n,e: True) -> List[str]:
|
||||
files = []
|
||||
for f in list_path(SHARE_PATH):
|
||||
r = f[len(SHARE_PATH)+1:]
|
||||
|
||||
if r[0] == '.' or '/.' in r:
|
||||
# hidden files
|
||||
continue
|
||||
|
||||
if '/' in r and '.' in r:
|
||||
path, name, ending = r[:r.rfind('/')], r[r.rfind('/')+1:r.rfind('.')], r[r.rfind('.')+1:]
|
||||
elif '/' in r:
|
||||
path, name, ending = r[:r.rfind('/')], r[r.rfind('/')+1:], ""
|
||||
elif '.' in r:
|
||||
path, name, ending = "", r[:r.rfind('.')], r[r.rfind('.')+1:]
|
||||
else:
|
||||
path, name, ending = "", r, ""
|
||||
|
||||
if filter(path, name, ending):
|
||||
files.append(r)
|
||||
return files
|
||||
|
||||
def list_shared_data():
|
||||
return list_shared(lambda p,n,e: e != "json")
|
||||
|
||||
def list_shared_schema():
|
||||
return list_shared(lambda p,n,e: e == "json")
|
Reference in New Issue
Block a user