import argparse import sys import os from voussoirkit import bytestring from voussoirkit import treeclass HTML_TREE_HEAD = ''' ''' HTML_FORMAT_DIRECTORY = '''
{directory_anchor}
' else: # This helps put some space between sibling directories yield '| ' * (depth) if depth == 0: if footer is not None: yield footer if use_html: yield '\n' def pathtree_argparse(args): from voussoirkit import safeprint from voussoirkit import spinal paths = spinal.walk_generator() paths = [{'path': path.absolute_path, 'size': path.size} for path in paths] tree = from_paths(paths, '.') recursive_get_size(tree) if args.output_file: output_file = open(args.output_file, 'w', encoding='utf-8') else: output_file = None for line in recursive_print_node(tree, use_html=args.use_html): if output_file: print(line, file=output_file) else: safeprint.safeprint(line) def main(argv): parser = argparse.ArgumentParser() parser.add_argument('output_file', nargs='?', default=None) parser.add_argument('--html', dest='use_html', action='store_true') parser.set_defaults(func=pathtree_argparse) args = parser.parse_args(argv) return args.func(args) if __name__ == '__main__': raise SystemExit(main(sys.argv[1:]))