blob: 5ccf7447e3a32ae41c0ac307c3111bb655897cba (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
|
import os
from pathlib import Path, PurePosixPath
def sitemap_tree(path):
tree = dict(name=PurePosixPath(path).name, children=[])
try:
mylist = os.listdir(path)
except OSError:
pass
else:
for name in mylist:
fn = os.path.join(path, name)
if os.path.isdir(fn):
tree['children'].append(sitemap_tree(fn))
else:
np = os.path.join(name)
if np.startswith('/'):
np = np[1:]
tree['children'].append(dict(name=np))
return tree
|