Created
August 12, 2012 22:32
-
-
Save Ceasar/3334992 to your computer and use it in GitHub Desktop.
Proof of concept code to solve the problem of how to build a sitemap or file system tree.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
from pprint import pprint | |
MAP = {} | |
CHILDREN_KEY = 'children' | |
for path, _, filenames in os.walk('./templates'): | |
path = path.split("/")[2:] | |
spot = MAP | |
for p in path[:-1]: | |
spot = spot[p] | |
try: | |
spot[path[-1]] = {CHILDREN_KEY: filenames} | |
except IndexError: | |
spot[CHILDREN_KEY] = filenames | |
pprint(MAP, indent=4) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment