From 1ea6a3396f1215e445b639cbeb084d81753c1603 Mon Sep 17 00:00:00 2001 From: Raoul Snyman Date: Wed, 21 Apr 2010 15:50:16 +0200 Subject: [PATCH] Finally fixed the directory list! --- scribeengine/controllers/media.py | 37 +++++++++---------------------- 1 file changed, 10 insertions(+), 27 deletions(-) diff --git a/scribeengine/controllers/media.py b/scribeengine/controllers/media.py index b71e112..35f30d1 100644 --- a/scribeengine/controllers/media.py +++ b/scribeengine/controllers/media.py @@ -22,7 +22,7 @@ import os import logging -from pprint import pprint +from pprint import pprint, pformat from scribeengine.lib.base import * from scribeengine.lib import utils @@ -34,36 +34,19 @@ log = logging.getLogger(__name__) 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] = {} + old_root = parent + dirname = os.path.split(parent)[1] + tree[dirname] = {u'dirpath': parent, u'children': {}} 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 - + if root != old_root: + break for dirpath in dirs: - root_parts = full_dirpath = os.path.join(root, dirpath) - tree[full_dirpath] = {} - - for dirpath in os.listdir(parent): - 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 + self._get_directories(full_dirpath, tree[dirname][u'children']) def index(self): - c.directories = self._get_directories() + c.directories = {} + self._get_directories(config[u'paths.media'], c.directories) pprint(c.directories) - return c.directories + return pformat(c.directories, indent=2) #return render(u'/media/index.html')