changeset 384:5ae5ada91ac8

simple numbering
author Jeff Hammel <jhammel@mozilla.com>
date Fri, 26 Jul 2013 09:45:46 -0700
parents 8d1ad56761b0
children 6ef0ea2f10e3
files python/tree.py python/tree2.py
diffstat 2 files changed, 10 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/python/tree.py	Fri Jul 26 05:56:18 2013 -0700
+++ b/python/tree.py	Fri Jul 26 09:45:46 2013 -0700
@@ -36,12 +36,11 @@
         basename = os.path.basename(dirpath)
         parent = os.path.abspath(os.path.dirname(dirpath))
         indent = depth(dirpath) - level
-        import pdb; pdb.set_trace()
         dirnames[:] = sorted(dirnames, key=lambda x: x.lower())
         last[os.path.abspath(dirpath)] = dirnames and dirnames[-1] or None
         directories[dirpath] = dirnames
 
-        retval.append('%s%s%s %s' % ('│' * (indent-1),
+        retval.append('%s%s%s' % ('│' * (indent-1),
                                      ('├' if basename == basename else '└') if indent else '',
                                      basename))
         filenames = sorted(filenames, key=lambda x: x.lower())
--- a/python/tree2.py	Fri Jul 26 05:56:18 2013 -0700
+++ b/python/tree2.py	Fri Jul 26 09:45:46 2013 -0700
@@ -23,14 +23,16 @@
 
 def tree(directory):
 
-    sort_key=lambda x: x.lower())
+    sort_key=lambda x: x.lower()
     retval = [directory]
     top = depth(directory)
     indent = []
+    last = {}
     for dirpath, dirnames, filenames in os.walk(directory, topdown=True):
 
         abspath = os.path.abspath(dirpath)
-        parent = os.path.dirname(abspath))
+        basename = os.path.basename(abspath)
+        parent = os.path.dirname(abspath)
         level = depth(abspath) - top
 
         # sort articles of interest
@@ -43,6 +45,11 @@
             if last.get(parent) == os.path.basename(abspath):
                 pass
 
+        retval.append('%s%s'% (str(level) * level, basename))
+        level += 1
+        retval.extend([('%s%s' % (str(level) * level, filename))
+                       for filename in filenames])
+
         # retval.append('%s%s%s %s' % ('│' * (indent-1),
         #                              ('├' if basename == basename else '└') if indent else '',
         #                              basename))