Mercurial > hg > config
comparison python/tree2.py @ 386:bea5f2fe4ea4
it works even more!
author | Jeff Hammel <jhammel@mozilla.com> |
---|---|
date | Fri, 26 Jul 2013 14:58:18 -0700 |
parents | 6ef0ea2f10e3 |
children | 0aee0da6b06b |
comparison
equal
deleted
inserted
replaced
385:6ef0ea2f10e3 | 386:bea5f2fe4ea4 |
---|---|
25 level += 1 | 25 level += 1 |
26 if not remainder: | 26 if not remainder: |
27 break | 27 break |
28 return level | 28 return level |
29 | 29 |
30 def tree(directory): | 30 def tree(directory, sort_key=lambda x: x.lower()): |
31 | 31 |
32 sort_key=lambda x: x.lower() | |
33 retval = [] | 32 retval = [] |
34 top = depth(directory) | |
35 indent = [] | 33 indent = [] |
36 last = {} | 34 last = {} |
35 top = depth(directory) | |
36 | |
37 for dirpath, dirnames, filenames in os.walk(directory, topdown=True): | 37 for dirpath, dirnames, filenames in os.walk(directory, topdown=True): |
38 | 38 |
39 abspath = os.path.abspath(dirpath) | 39 abspath = os.path.abspath(dirpath) |
40 basename = os.path.basename(abspath) | 40 basename = os.path.basename(abspath) |
41 parent = os.path.dirname(abspath) | 41 parent = os.path.dirname(abspath) |
66 elif not indent: | 66 elif not indent: |
67 dirpath_mark = '' | 67 dirpath_mark = '' |
68 else: | 68 else: |
69 dirpath_mark = ITEM | 69 dirpath_mark = ITEM |
70 | 70 |
71 | |
72 # if basename == 'bin': | |
73 # import pdb; pdb.set_trace() | |
74 | |
75 str_indent = ''.join(indent) | |
76 retval.append('%s%s%s'% (''.join(indent[:-1]), dirpath_mark, basename)) | 71 retval.append('%s%s%s'% (''.join(indent[:-1]), dirpath_mark, basename)) |
77 if filenames: | 72 if filenames: |
78 last_file = filenames[-1] | 73 last_file = filenames[-1] |
79 retval.extend([('%s%s%s' % (str_indent, | 74 retval.extend([('%s%s%s' % (str_indent, |
80 files_end if filename == last_file else ITEM, | 75 files_end if filename == last_file else ITEM, |