Finally fixed the directory list!
This commit is contained in:
parent
2e76729d6d
commit
1ea6a3396f
@ -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
|
||||
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')
|
||||
|
Reference in New Issue
Block a user