Commit fd76d546 authored by LE GAC Renaud's avatar LE GAC Renaud
Browse files

Update helper to use Path in get_file_paths.

parent b5eeed51
...@@ -294,33 +294,37 @@ def get_file_paths(path, ext=None, alpha=True): ...@@ -294,33 +294,37 @@ def get_file_paths(path, ext=None, alpha=True):
alpha (bool): sort the paths in alphabetic order alpha (bool): sort the paths in alphabetic order
Returns: Returns:
list: list or string:
local paths for all selected files. * paths for all selected files,
* absolute path with respect to application
* for example: /myapp/static/myapp-min.js
""" """
li = []
if path is None: if path is None:
return li return []
server_path, client_path = get_reference_paths() lst = []
application = current.request.application
app_path = Path("applications", application)
for el in as_list(path): for el in as_list(path):
p = os.path.join(server_path, el) p = app_path / el
if os.path.isfile(p): if p.is_file():
if ext and (not el.endswith(ext)): if (ext is not None) and (p.suffix != ext):
continue continue
li.append(os.path.join(client_path, el)) lst.append(Path("/", application, el))
elif os.path.isdir(p): elif p.is_dir():
for filename in os.listdir(p): for pfile in p.iterdir():
pfile = os.path.join(el, filename) new_path = str(pfile.relative_to(app_path))
li.extend(get_file_paths(pfile, ext, alpha)) lst.extend(get_file_paths(new_path, ext, alpha))
lst = [str(el) for el in lst]
if alpha: if alpha:
li.sort() lst.sort()
return li return lst
def get_foreign_field(field): def get_foreign_field(field):
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment