def tree_api(name): """ Returns the tree of the CONTENT_FOLDER """ print('tree: ', name) if name == '/': path = app.config['UPLOAD_FOLDER'] else: path = os.path.join(app.config['UPLOAD_FOLDER'], name) if path[-1] == os.sep: path = path[:-1] tree = {} for (dirpath, directories, files) in os.walk(path): dirpath = helpers.convert_to_web_slashes(dirpath) name, parent = helpers.get_trunc_path(dirpath, LEN_CONTENT_FOLDER) directories.sort() files.sort() file_info = {} for file in files: filename = os.path.join(dirpath, file) stats = os.stat(filename) if '.' in filename: file_type = filename.rsplit('.', 1)[-1] else: file_type = '' file_info[file] = { 'mtime': time.ctime(stats.st_mtime), 'ctime': time.ctime(stats.st_ctime), 'size': stats.st_size / (1024 * 1024), 'file_type': file_type, } tree[name] = { 'directories': directories, 'files': files, 'clean': True, 'parent': parent, 'file_info': file_info, } try: if '.do-not-delete-this-file' in tree['/']['files']: tree['/']['files'].remove('.do-not-delete-this-file') tree['/']['file_info'].pop('.do-not-delete-this-file') except: pass return jsonify(tree)
def tree_api(name): """ Returns the tree of the CONTENT_FOLDER """ if name == 'root': path = app.config['UPLOAD_FOLDER'] else: path = os.path.join(app.config['UPLOAD_FOLDER'], name) if path[-1] == os.sep: path = path[:-1] tree = {} for (dirpath, directories, files) in os.walk(path): dirpath = helpers.convert_to_web_slashes(dirpath) name, parent = helpers.get_trunc_path(dirpath, LEN_CONTENT_FOLDER) tree[name] = { 'directories': directories, 'files': files, 'clean': True, 'parent': parent, } if '.do-not-delete-this-file' in tree['/']['files']: tree['/']['files'].remove('.do-not-delete-this-file') return jsonify(tree)