changeset 388:3678770e8c52

changes
author Jeff Hammel <jhammel@mozilla.com>
date Sat, 27 Jul 2013 18:45:43 -0700
parents 0aee0da6b06b
children 2d4dfe1dc632
files python/tree2.py
diffstat 1 files changed, 17 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/python/tree2.py	Fri Jul 26 16:20:22 2013 -0700
+++ b/python/tree2.py	Sat Jul 27 18:45:43 2013 -0700
@@ -10,9 +10,11 @@
 import sys
 
 # ASCII delimeters
-VERTICAL_LINE = '|'
-ITEM = '+'
-END = '\\'
+ascii_delimeters = {
+    VERTICAL_LINE = '|'
+    ITEM = '+'
+    END = '\\'
+    }
 
 # unicode delimiters
 VERTICAL_LINE = '│'
@@ -31,7 +33,12 @@
             break
     return level
 
-def tree(directory, sort_key=lambda x: x.lower()):
+def tree(directory,
+         item_marker='',
+         sort_key=lambda x: x.lower()):
+    """
+    display tree directory structure for `directory`
+    """
 
     retval = []
     indent = []
@@ -71,7 +78,12 @@
         else:
             dirpath_mark = ITEM
 
-        retval.append('%s%s%s'% (''.join(indent[:-1]), dirpath_mark, basename))
+        # append the directory and piece of tree structure
+        # if the top-level entry directory, print as passed
+        retval.append('%s%s%s'% (''.join(indent[:-1]),
+                                 dirpath_mark,
+                                 basename if retval else directory))
+        # add the files
         if filenames:
             last_file = filenames[-1]
             retval.extend([('%s%s%s' % (''.join(indent),