Trying to fix the directories.
This commit is contained in:
parent
63950167b1
commit
2e76729d6d
@ -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')
|
||||
|
Reference in New Issue
Block a user