"""Various utils."""

import os

root_path = os.path.dirname(os.path.realpath(__file__))


def t_path(filename="."):
	"""Get the path of the test file inside test directory."""
	return os.path.join(root_path, filename)


def list_files(startpath):
	"""tree unix command replacement."""
	for root, dirs, files in os.walk(startpath):
		level = root.replace(startpath, '').count(os.sep)
		indent = ' ' * 4 * (level)
		print('{}{}/'.format(indent, os.path.basename(root)))
		subindent = ' ' * 4 * (level + 1)
		for f in files:
			print('{}{}'.format(subindent, f))

@@ -24,16 +24,45 @@
 mport os
+%0Afrom functools import reduce
 %0A%0Aroot_p
@@ -139,17 +139,20 @@
 e=%22.%22):%0A
-%09
+    
 %22%22%22Get t
@@ -202,17 +202,20 @@
 ory.%22%22%22%0A
-%09
+    
 return o
@@ -276,17 +276,20 @@
 tpath):%0A
-%09
+    
 %22%22%22tree 
@@ -317,17 +317,20 @@
 ent.%22%22%22%0A
-%09
+    
 for root
@@ -366,18 +366,24 @@
 tpath):%0A
-%09%09
+        
 level = 
@@ -424,18 +424,24 @@
 os.sep)%0A
-%09%09
+        
 indent =
@@ -459,18 +459,24 @@
 (level)%0A
-%09%09
+        
 print('%7B
@@ -521,18 +521,24 @@
 root)))%0A
-%09%09
+        
 subinden
@@ -563,18 +563,24 @@
 el + 1)%0A
-%09%09
+        
 for f in
@@ -591,11 +591,20 @@
 es:%0A
-%09%09%09
+            
 prin
@@ -634,8 +634,572 @@
 nt, f))%0A
+%0A%0Adef file_tree(startpath):%0A    %22%22%22%0A    Create a nested dictionary that represents the folder structure of rootdir.%0A%0A    Liberally adapted from%0A    http://code.activestate.com/recipes/577879-create-a-nested-dictionary-from-oswalk/%0A    %22%22%22%0A    dir = %7B%7D%0A    rootdir = startpath.rstrip(os.sep)%0A    start = rootdir.rfind(os.sep) + 1%0A    for path, dirs, files in os.walk(rootdir):%0A        folders = path%5Bstart:%5D.split(os.sep)%0A        subdir = dict.fromkeys(files)%0A        parent = reduce(dict.get, folders%5B:-1%5D, dir)%0A        parent%5Bfolders%5B-1%5D%5D = subdir%0A    return dir%0A

add directory tree as dictionary function