/usr/share/pyshared/gnatpython/tree.py is in python-gnatpython 54-3.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 | ############################################################################
# #
# TREE.PY #
# #
# Copyright (C) 2008 - 2010 Ada Core Technologies, Inc. #
# #
# This program is free software: you can redistribute it and/or modify #
# it under the terms of the GNU General Public License as published by #
# the Free Software Foundation, either version 3 of the License, or #
# (at your option) any later version. #
# #
# This program is distributed in the hope that it will be useful, #
# but WITHOUT ANY WARRANTY; without even the implied warranty of #
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
# GNU General Public License for more details. #
# #
# You should have received a copy of the GNU General Public License #
# along with this program. If not, see <http://www.gnu.org/licenses/> #
# #
############################################################################
"""list contents of directories in a tree-like format.
Produces a depth indented listing of files.
"""
import os
from os.path import walk
def tree(directory, stdout=False):
"""Returns a depth indented listing of files
If stdout is true, print directly on stdout
else return the list of indented lines
"""
def print_line(output, line):
"""Print line to stdout or append in output"""
if output is None:
print line
else:
output.append(line)
if not stdout:
output = []
else:
# Do not return a list but print all lines to stdout
output = None
print_line(output, directory)
def print_files(output, dirname, fnames):
"""Add filename to the output"""
dir_relative_path = os.path.normpath(dirname[len(directory):])
indent = '| '
nb_indent = 0
_, tail = os.path.split(dir_relative_path)
# Count number of / in the path to compute the indent
nb_indent = dir_relative_path.count(os.path.sep)
if tail and tail != ".":
# If not the root directory, output the directory name
print_line(output, "%s|-- %s" % (indent * nb_indent, tail))
else:
# Else no indent
nb_indent = -1
# Print all file names in the current directory
fnames.sort()
for fname in fnames:
if not os.path.isdir(os.path.join(dirname, fname)):
if fname == fnames[-1] and nb_indent != -1:
# Pretty print the last file
sep = '`'
else:
sep = '|'
print_line(output, "%s%s-- %s" % (indent * (nb_indent + 1),
sep, fname))
walk(directory, print_files, output)
return output
|