From 2e76729d6d82e44f53b3a12f57ee4c9270357d6c Mon Sep 17 00:00:00 2001 From: Raoul Snyman Date: Wed, 21 Apr 2010 15:32:12 +0200 Subject: [PATCH] Trying to fix the directories. --- scribeengine/controllers/media.py | 33 ++++++++++++++++++++++++++----- 1 file changed, 28 insertions(+), 5 deletions(-) diff --git a/scribeengine/controllers/media.py b/scribeengine/controllers/media.py index 38a431a..b71e112 100644 --- a/scribeengine/controllers/media.py +++ b/scribeengine/controllers/media.py @@ -22,6 +22,7 @@ import os import logging +from pprint import pprint from scribeengine.lib.base import * from scribeengine.lib import utils @@ -35,12 +36,34 @@ class MediaController(BaseController): def _get_directories(self, parent=None, tree={}): if not parent: parent = config[u'paths.media'] + parent = os.path.abspath(parent) + dir_start = os.path.split(parent)[1] + tree[dir_start] = {} + for root, dirs, files in os.walk(parent): + root_parts = root.split(os.sep) + root_start = u'' + for root_part in root_parts: + if root_part == dir_start: + root_start = root_part + break + + for dirpath in dirs: + root_parts = + full_dirpath = os.path.join(root, dirpath) + tree[full_dirpath] = {} + for dirpath in os.listdir(parent): - if os.path.isdir(dirpath): - tree[os.path.abspath(dirpath)] = {u'path': dirpath, u'children': {}} - self._get_directories(os.path.abspath(dirpath), - tree[os.path.abspath(dirpath)][u'children']) + full_dirpath = os.path.abspath(dirpath) + print 'path:', full_dirpath + if os.path.isdir(full_dirpath): + tree[full_dirpath] = { + u'path': dirpath, + u'children': self._get_directories(full_dirpath) + } + return tree def index(self): c.directories = self._get_directories() - return render(u'/media/index.html') + pprint(c.directories) + return c.directories + #return render(u'/media/index.html')