munyal-client/munyal/flatten_dirs.py

20 lines
513 B
Python

from munyal.misc import path_join
def _flatten_dirs(content, path=""):
for item in content:
item["name"] = path_join(path, item["name"])
if item["is_file"]:
yield item
else:
yield from _flatten_dirs(item["content"], item["name"])
del item["content"]
yield item
def flatten_dirs(content, path=""):
dirs = _flatten_dirs(content, path=path)
output = {}
for item in dirs:
output[item["name"]] = item
return output