1 # This program is free software; you can redistribute it and/or modify
2 # it under the terms of the GNU General Public License as published by
3 # the Free Software Foundation; either version 2 of the License, or
4 # (at your option) any later version.
6 # This program is distributed in the hope that it will be useful,
7 # but WITHOUT ANY WARRANTY; without even the implied warranty of
8 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9 # GNU Library General Public License for more details.
11 # You should have received a copy of the GNU General Public License
12 # along with this program; if not, write to the Free Software
13 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
15 # See the COPYING file for license information.
17 # Copyright (c) 2006, 2007, 2008 Guillaume Chazarain <guichaz@gmail.com>
23 from pysize
.core
.pysize_fs_tree
import pysize_tree
24 from pysize
.core
.compute_size
import size_observable
25 from pysize
.ui
.utils
import human_unit
, update_progress
26 from pysize
.ui
.utils
import sanitize_string
27 from pysize
.ui
.char_matrix
import CharMatrix
, HLINE_START
, HLINE
, HLINE_END
28 from pysize
.ui
.char_matrix
import VLINE_START
, VLINE
, VLINE_END
29 from pysize
.ui
.ascii
.terminal_size
import terminal_size
33 HLINE_START
: '-', HLINE
: '-', HLINE_END
: '-',
34 VLINE_START
: '|', VLINE
: '|', VLINE_END
: '|'
38 if isinstance(char
, int):
39 return MATRIX_TO_ASCII
.get(char
, '+')
43 progress
= update_progress()
45 print '', progress
, '\r',
48 def run(options
, args
):
49 columns
, lines
= terminal_size()
50 lines
-= 3 # Summary + Prompt + Last line
51 size_observable
.add_observer(_draw_progress
)
52 args
= args
or [os
.getcwd()]
53 # An entry needs 2 lines
54 tree
= pysize_tree(args
, options
.max_depth
, 2.0 / lines
, options
)
57 # The last entry needs an additional terminating line
58 total_lines
= int(math
.ceil(2.0 * tree
.root
.size
/
59 max(1, tree
.root
.minimum_node_size()))) + 1
60 matrix
= CharMatrix(columns
, total_lines
, tree
)
61 print '\n'.join([''.join(map(_transform
, line
)) for line
in matrix
.matrix
])
62 print sanitize_string(tree
.root
.get_name()), human_unit(tree
.root
.size
)