Eclectic Media Git ptree / ee349a3
Made package follow distutils standards Ariana Giroux 1 year, 6 months ago
3 changed file(s) with 121 addition(s) and 82 deletion(s). Raw diff Collapse all Expand all
0 from setuptools import setup, find_packages
1
2 # with open("README.rst", "r") as fh:
3 # long_description = fh.read()
4 #
5 # with open("requirements.txt", "r") as f:
6 # required = f.read().splitlines()
7
8 setup(
9 name='ptree',
10 version='0.1',
11 description='Simple python file tree visualizer with long level truncation',
12 # url='http://gitlab.com/eclectickmediasolutions/pingstats',
13 author='Ariana Giroux',
14 author_email='me@arianagiroux.ca',
15 license='MIT',
16 packages=find_packages(),
17 # setup_requires=["pytest-runner"],
18 # tests_require=["pytest"],
19 # install_requires=required,
20 zip_safe=True,
21 entry_points={
22 'console_scripts': ['ptree=tree:_main'],
23 },
24 classifiers=(
25 "Programming Language :: Python :: 3",
26 "License :: OSI Approved :: MIT License",
27 "Operating System :: OS Independent",
28 "Development Status :: 4 - Beta",
29 "Environment :: Console",
30 "Intended Audience :: Developers",
31 "Intended Audience :: End Users/Desktop",
32 "Intended Audience :: Information Technology",
33 "License :: OSI Approved :: MIT License",
34 "Operating System :: Unix",
35 "Topic :: Utilities",
36 ),
37 )
0 #! /usr/bin/env python
1
2 # tree.py
3 #
4 # Written by Doug Dahms
5 #
6 # Prints the tree structure for the path specified on the command line
7
8 from os import listdir, sep
9 from os.path import abspath, basename, isdir
10
11 from argparse import ArgumentParser
12
13
14 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. """
16 print(padding[:-1] + '+-' + basename(abspath(origin_path)) + '/')
17 padding = padding + ' '
18 files = []
19
20 dirs = [x for x in listdir(origin_path) if isdir(origin_path + sep + x)]
21 files = [x for x in listdir(origin_path) if not isdir(origin_path + sep + x)]
22
23 if print_files:
24 padding += '| '
25
26 for i, file in enumerate(files):
27 print(padding + '+-' + file)
28
29 if len(files) > 3 and i + 1 == 3 and truncate_files:
30 print(padding + '+- ...')
31 break
32
33 padding = padding[:-2]
34
35 # count = 0
36 for i, dir in enumerate(dirs):
37
38 path = origin_path + sep + dir
39
40 if truncate_dirs:
41 if len(dirs) < 3:
42 tree(path, padding + '|', print_files, truncate_files, truncate_dirs)
43 else:
44 print(padding + '+-' + basename(abspath(dir)) + '/')
45
46 if i + 1 == 3:
47 print(padding + '+- ...')
48 break
49
50 else:
51 tree(path, padding + '|', print_files, truncate_files, truncate_dirs)
52
53
54 def _main():
55 parser = ArgumentParser()
56
57 parser.add_argument('path', default='./', type=str,
58 help='The path to map.')
59
60 parser.add_argument('-f', '--print_files', action='store_true',
61 help='Output files alongside directories.')
62
63 parser.add_argument('-F', '--truncate_files', action='store_true',
64 help='Only output 3 files of any given level. '
65 '(Implies `-f`)')
66
67 parser.add_argument('-D', '--truncate_directories', action='store_true',
68 help='Only output 3 directories of any given level.')
69
70 parsed = parser.parse_args()
71
72 if parsed.truncate_files:
73 parsed.print_files = True
74
75 if isdir(parsed.path):
76 tree(parsed.path, ' ', parsed.print_files, parsed.truncate_files, parsed.truncate_directories)
77 else:
78 print('%s is not a valid path...' % parsed.path)
79
80
81 if __name__ == '__main__':
82 _main()
+0
-82
tree.py less more
0 #! /usr/bin/env python
1
2 # tree.py
3 #
4 # Written by Doug Dahms
5 #
6 # Prints the tree structure for the path specified on the command line
7
8 from os import listdir, sep
9 from os.path import abspath, basename, isdir
10
11 from argparse import ArgumentParser
12
13
14 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. """
16 print(padding[:-1] + '+-' + basename(abspath(origin_path)) + '/')
17 padding = padding + ' '
18 files = []
19
20 dirs = [x for x in listdir(origin_path) if isdir(origin_path + sep + x)]
21 files = [x for x in listdir(origin_path) if not isdir(origin_path + sep + x)]
22
23 if print_files:
24 padding += '| '
25
26 for i, file in enumerate(files):
27 print(padding + '+-' + file)
28
29 if len(files) > 3 and i + 1 == 3 and truncate_files:
30 print(padding + '+- ...')
31 break
32
33 padding = padding[:-2]
34
35 # count = 0
36 for i, dir in enumerate(dirs):
37
38 path = origin_path + sep + dir
39
40 if truncate_dirs:
41 if len(dirs) < 3:
42 tree(path, padding + '|', print_files, truncate_files, truncate_dirs)
43 else:
44 print(padding + '+-' + basename(abspath(dir)) + '/')
45
46 if i + 1 == 3:
47 print(padding + '+- ...')
48 break
49
50 else:
51 tree(path, padding + '|', print_files, truncate_files, truncate_dirs)
52
53
54 def main():
55 parser = ArgumentParser()
56
57 parser.add_argument('path', default='./', type=str,
58 help='The path to map.')
59
60 parser.add_argument('-f', '--print_files', action='store_true',
61 help='Output files alongside directories.')
62
63 parser.add_argument('-F', '--truncate_files', action='store_true',
64 help='Only output 3 files of any given level. '
65 '(Implies `-f`)')
66
67 parser.add_argument('-D', '--truncate_directories', action='store_true',
68 help='Only output 3 directories of any given level.')
69
70 parsed = parser.parse_args()
71
72 if parsed.truncate_files:
73 parsed.print_files = True
74
75 if isdir(parsed.path):
76 tree(parsed.path, ' ', parsed.print_files, parsed.truncate_files, parsed.truncate_directories)
77 else:
78 print('%s is not a valid path...' % parsed.path)
79
80 if __name__ == '__main__':
81 main()