From 8383bd5528ad8c6f3395ab2aaac5f068514965fe Mon Sep 17 00:00:00 2001 From: Oleg Broytman Date: Sun, 15 Mar 2015 23:32:23 +0300 Subject: [PATCH] gen-sitemap: build tree --- gen-sitemap.py | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/gen-sitemap.py b/gen-sitemap.py index 1afe424..1a78a7f 100755 --- a/gen-sitemap.py +++ b/gen-sitemap.py @@ -20,6 +20,10 @@ os.chdir(args.root_dir) fullpath = os.getcwd() fp_len = len(fullpath) +tree = ('', []) +current_subtree = tree[1] +save_level = 0 + for dirpath, dirs, files in sorted(os.walk(fullpath)): try: dirpath = dirpath[fp_len:] @@ -30,6 +34,17 @@ for dirpath, dirs, files in sorted(os.walk(fullpath)): raise StopIteration parts = dirpath.split('/') level = len(parts) - 2 - print ' ' * level + parts[-1] + if level < save_level: + current_subtree = tree[1] + for i in range(level): + current_subtree = current_subtree[-1][1] + current_subtree.append((parts[-1], [])) + elif level == save_level: + current_subtree.append((parts[-1], [])) + elif level > save_level: + assert level - save_level == 1 + current_subtree = current_subtree[-1][1] + current_subtree.append((parts[-1], [])) + save_level = level except StopIteration: pass -- 2.39.5