Mercurial > hg > config
comparison python/tree.py @ 376:3f84a96cccf6
minor improvements; need a thought or two for the real answer
| author | Jeff Hammel <jhammel@mozilla.com> |
|---|---|
| date | Wed, 24 Jul 2013 06:59:09 -0700 |
| parents | 9314c1008189 |
| children | b1c43c980b05 |
comparison
equal
deleted
inserted
replaced
| 375:9314c1008189 | 376:3f84a96cccf6 |
|---|---|
| 23 | 23 |
| 24 def tree(directory): | 24 def tree(directory): |
| 25 retval = [] | 25 retval = [] |
| 26 level = depth(directory) | 26 level = depth(directory) |
| 27 directories = {} | 27 directories = {} |
| 28 lvlndctr = [] | |
| 29 last = {} | |
| 30 columns = [] | |
| 31 lastdepth = depth | |
| 28 for dirpath, dirnames, filenames in os.walk(directory, topdown=True): | 32 for dirpath, dirnames, filenames in os.walk(directory, topdown=True): |
| 33 basename = os.path.basename(dirpath) | |
| 34 parent = os.path.abspath(os.path.dirname(dirpath)) | |
| 29 indent = depth(dirpath) - level | 35 indent = depth(dirpath) - level |
| 30 dirnames[:] = sorted(dirnames, key=lambda x: x.lower()) | 36 dirnames[:] = sorted(dirnames, key=lambda x: x.lower()) |
| 37 last[os.path.abspath(dirpath)] = dirnames and dirnames[-1] or None | |
| 31 directories[dirpath] = dirnames | 38 directories[dirpath] = dirnames |
| 32 retval.append('%s%s%s' % ('│' * (indent-1), | 39 retval.append('%s%s%s' % ('│' * (indent-1), |
| 33 '├' if indent else '', | 40 ('├' if basename == basename else '└') if indent else '', |
| 34 os.path.basename(dirpath))) | 41 basename)) |
| 35 filenames = sorted(filenames, key=lambda x: x.lower()) | 42 filenames = sorted(filenames, key=lambda x: x.lower()) |
| 36 retval.extend(['%s%s%s' % ('│' * (indent), | 43 retval.extend(['%s%s%s' % ('│' * (indent), |
| 37 # '├' if (((index < len(filenames) -1)) or dirnames) else '└', | |
| 38 '├' if (((index < len(filenames) -1)) or dirnames) else '└', | 44 '├' if (((index < len(filenames) -1)) or dirnames) else '└', |
| 39 name) | 45 name) |
| 40 for index, name in | 46 for index, name in |
| 41 enumerate(filenames) | 47 enumerate(filenames) |
| 42 ]) | 48 ]) |
