1
# Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009 Canonical Ltd
3
# This program is free software; you can redistribute it and/or modify
4
# it under the terms of the GNU General Public License as published by
5
# the Free Software Foundation; either version 2 of the License, or
6
# (at your option) any later version.
8
# This program is distributed in the hope that it will be useful,
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
# GNU General Public License for more details.
13
# You should have received a copy of the GNU General Public License
14
# along with this program; if not, write to the Free Software
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17
"""List files in a tree."""
20
from bzrlib.lazy_import import lazy_import
21
lazy_import(globals(), """
26
from bzrlib.trace import mutter, note
27
from bzrlib.workingtree import WorkingTree
31
def ls(tree, outf, from_dir=None, recursive=False, kind=None, unknown=False,
32
versioned=False, ignored=False, verbose=False, null=False, show_ids=False,
33
prefix=None, from_root=False):
34
"""List files for a tree.
36
If unknown, versioned and ignored are all False, then all are displayed.
38
:param tree: the tree to display files for
39
:param outf: the output stream
40
:param from_dir: just from this directory
41
:param recursive: whether to recurse into subdirectories or not
42
:param kind: one of 'file', 'symlink', 'directory' or None for all
43
:param unknown: include unknown files or not
44
:param versioned: include versioned files or not
45
:param ignored: include ignored files or not
46
:param verbose: show file kinds, not just paths
47
:param null: separate entries with null characters instead of newlines
48
:param show_ids: show file_ids or not
49
:param prefix: prefix paths with this string or None for no prefix
50
:param from_root: show paths from the root instead of relative
52
mutter("ls from: %s" % (from_dir,))
53
# Tell the user if a view if being applied
55
if isinstance(tree, WorkingTree) and tree.supports_views():
56
view_files = tree.views.lookup_view()
59
view_str = views.view_display_str(view_files)
60
note("Ignoring files outside view. View is %s" % view_str)
62
# Find and display the files
63
all = not (unknown or versioned or ignored)
64
selection = {'I':ignored, '?':unknown, 'V':versioned}
65
#if from_dir and from_root:
71
for fp, fc, fkind, fid, entry in tree.list_files(include_root=False,
72
from_dir=from_dir, recursive=recursive):
73
# Apply additional masking
74
if not all and not selection[fc]:
76
if kind is not None and fkind != kind:
80
fullpath = osutils.pathjoin(from_dir, fp)
84
views.check_path_in_view(tree, fullpath)
85
except errors.FileOutsideView:
89
kindch = entry.kind_character()
90
if prefix is not None:
91
fp = osutils.pathjoin(prefix, fp)
92
outstring = fp + kindch
94
outstring = '%-8s %s' % (fc, outstring)
95
if show_ids and fid is not None:
96
outstring = "%-50s %s" % (outstring, fid)
97
outf.write(outstring + '\n')
111
outf.write('%-50s %s\n' % (outstring, my_id))
113
outf.write(outstring + '\n')