Eclectic Media Git ptree / 2e55681
Updated docs for package Ariana Giroux 1 year, 10 months ago
1 changed file(s) with 17 addition(s) and 11 deletion(s). Raw diff Collapse all Expand all
00 #! /usr/bin/env python
1 """ Prints the tree structure for the path specified on the command line
12
2 # tree.py
3 #
4 # Written by Doug Dahms
5 #
6 # Prints the tree structure for the path specified on the command line
3 Original written by Doug Dahms (see http://code.activestate.com/recipes/217212-treepy-graphically-displays-the-directory-structur/)
4
5 Current version written by Ariana Giroux <me@arianagiroux.ca>, circa 2019
6 """
77
88 from os import listdir, sep
99 from os.path import abspath, basename, isdir
1212
1313
1414 def tree(origin_path, padding, print_files=False, truncate_files=False, truncate_dirs=False):
15 """ :truncate_dirs: If true, don't follow dir depths deeper than 3. """
15 """ Traverses the file system, outputting file structure as it goes.
16
17 :origin_path: The path to start the traversal from.
18 :print_files: If true, output files in directories.
19 :truncate_files: If true, don't output more than 3 files per level.
20 :truncate_dirs: If true, don't follow dir depths deeper than 3.
21 """
1622 print(padding[:-1] + '+-' + basename(abspath(origin_path)) + '/')
1723 padding = padding + ' '
1824 files = []
3238
3339 padding = padding[:-2]
3440
35 # count = 0
3641 for i, dir in enumerate(dirs):
3742
3843 path = origin_path + sep + dir
5257
5358
5459 def _main():
60 """ Main function, runs tree function.
61
62 Also ensures clean run time, performs basic sanitation on command line
63 arguments."""
64
5565 parser = ArgumentParser()
5666
5767 parser.add_argument('path', default='./', type=str,
7686 tree(parsed.path, ' ', parsed.print_files, parsed.truncate_files, parsed.truncate_directories)
7787 else:
7888 print('%s is not a valid path...' % parsed.path)
79
80
81 if __name__ == '__main__':
82 _main()