Mercurial > hg > config
comparison python/tree2.py @ 388:3678770e8c52
changes
author | Jeff Hammel <jhammel@mozilla.com> |
---|---|
date | Sat, 27 Jul 2013 18:45:43 -0700 |
parents | 0aee0da6b06b |
children | 2d4dfe1dc632 |
comparison
equal
deleted
inserted
replaced
387:0aee0da6b06b | 388:3678770e8c52 |
---|---|
8 import optparse | 8 import optparse |
9 import os | 9 import os |
10 import sys | 10 import sys |
11 | 11 |
12 # ASCII delimeters | 12 # ASCII delimeters |
13 VERTICAL_LINE = '|' | 13 ascii_delimeters = { |
14 ITEM = '+' | 14 VERTICAL_LINE = '|' |
15 END = '\\' | 15 ITEM = '+' |
16 END = '\\' | |
17 } | |
16 | 18 |
17 # unicode delimiters | 19 # unicode delimiters |
18 VERTICAL_LINE = '│' | 20 VERTICAL_LINE = '│' |
19 ITEM = '├' | 21 ITEM = '├' |
20 END = '└' | 22 END = '└' |
29 level += 1 | 31 level += 1 |
30 if not remainder: | 32 if not remainder: |
31 break | 33 break |
32 return level | 34 return level |
33 | 35 |
34 def tree(directory, sort_key=lambda x: x.lower()): | 36 def tree(directory, |
37 item_marker='', | |
38 sort_key=lambda x: x.lower()): | |
39 """ | |
40 display tree directory structure for `directory` | |
41 """ | |
35 | 42 |
36 retval = [] | 43 retval = [] |
37 indent = [] | 44 indent = [] |
38 last = {} | 45 last = {} |
39 top = depth(directory) | 46 top = depth(directory) |
69 elif not indent: | 76 elif not indent: |
70 dirpath_mark = '' | 77 dirpath_mark = '' |
71 else: | 78 else: |
72 dirpath_mark = ITEM | 79 dirpath_mark = ITEM |
73 | 80 |
74 retval.append('%s%s%s'% (''.join(indent[:-1]), dirpath_mark, basename)) | 81 # append the directory and piece of tree structure |
82 # if the top-level entry directory, print as passed | |
83 retval.append('%s%s%s'% (''.join(indent[:-1]), | |
84 dirpath_mark, | |
85 basename if retval else directory)) | |
86 # add the files | |
75 if filenames: | 87 if filenames: |
76 last_file = filenames[-1] | 88 last_file = filenames[-1] |
77 retval.extend([('%s%s%s' % (''.join(indent), | 89 retval.extend([('%s%s%s' % (''.join(indent), |
78 files_end if filename == last_file else ITEM, | 90 files_end if filename == last_file else ITEM, |
79 filename)) | 91 filename)) |