Finally fixed the directory list!
This commit is contained in:
parent
2e76729d6d
commit
1ea6a3396f
@ -22,7 +22,7 @@
|
|||||||
|
|
||||||
import os
|
import os
|
||||||
import logging
|
import logging
|
||||||
from pprint import pprint
|
from pprint import pprint, pformat
|
||||||
|
|
||||||
from scribeengine.lib.base import *
|
from scribeengine.lib.base import *
|
||||||
from scribeengine.lib import utils
|
from scribeengine.lib import utils
|
||||||
@ -34,36 +34,19 @@ log = logging.getLogger(__name__)
|
|||||||
class MediaController(BaseController):
|
class MediaController(BaseController):
|
||||||
|
|
||||||
def _get_directories(self, parent=None, tree={}):
|
def _get_directories(self, parent=None, tree={}):
|
||||||
if not parent:
|
old_root = parent
|
||||||
parent = config[u'paths.media']
|
dirname = os.path.split(parent)[1]
|
||||||
parent = os.path.abspath(parent)
|
tree[dirname] = {u'dirpath': parent, u'children': {}}
|
||||||
dir_start = os.path.split(parent)[1]
|
|
||||||
tree[dir_start] = {}
|
|
||||||
for root, dirs, files in os.walk(parent):
|
for root, dirs, files in os.walk(parent):
|
||||||
root_parts = root.split(os.sep)
|
if root != old_root:
|
||||||
root_start = u''
|
break
|
||||||
for root_part in root_parts:
|
|
||||||
if root_part == dir_start:
|
|
||||||
root_start = root_part
|
|
||||||
break
|
|
||||||
|
|
||||||
for dirpath in dirs:
|
for dirpath in dirs:
|
||||||
root_parts =
|
|
||||||
full_dirpath = os.path.join(root, dirpath)
|
full_dirpath = os.path.join(root, dirpath)
|
||||||
tree[full_dirpath] = {}
|
self._get_directories(full_dirpath, tree[dirname][u'children'])
|
||||||
|
|
||||||
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
|
|
||||||
|
|
||||||
def index(self):
|
def index(self):
|
||||||
c.directories = self._get_directories()
|
c.directories = {}
|
||||||
|
self._get_directories(config[u'paths.media'], c.directories)
|
||||||
pprint(c.directories)
|
pprint(c.directories)
|
||||||
return c.directories
|
return pformat(c.directories, indent=2)
|
||||||
#return render(u'/media/index.html')
|
#return render(u'/media/index.html')
|
||||||
|
Reference in New Issue
Block a user