"Fossies" - the Fresh Open Source Software Archive 
Member "pysize-0.2/pysize/ui/ascii/ui_ascii.py" (11 Mar 2007, 2439 Bytes) of package /linux/privat/old/pysize-0.2.tar.gz:
As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Python source code syntax highlighting (style:
standard) with prefixed line numbers.
Alternatively you can here
view or
download the uninterpreted source code file.
For more information about "ui_ascii.py" see the
Fossies "Dox" file reference documentation.
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.
5 #
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.
10 #
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.
14 #
15 # See the COPYING file for license information.
16 #
17 # Copyright (c) 2006, 2007 Guillaume Chazarain <guichaz@yahoo.fr>
18
19 import math
20 import sys
21
22 from pysize.core.pysize_fs_tree import pysize_tree
23 from pysize.core.compute_size import size_observable
24 from pysize.ui.utils import human_unit, min_size_to_consider, update_progress
25 from pysize.ui.utils import sanitize_string
26 from pysize.ui.char_matrix import CharMatrix, HLINE_START, HLINE, HLINE_END
27 from pysize.ui.char_matrix import VLINE_START, VLINE, VLINE_END
28 from pysize.ui.ascii.terminal_size import terminal_size
29
30 MATRIX_TO_ASCII = {
31 0: ' ',
32 HLINE_START: '-', HLINE: '-', HLINE_END: '-',
33 VLINE_START: '|', VLINE: '|', VLINE_END: '|'
34 }
35
36 def _transform(char):
37 if isinstance(char, int):
38 return MATRIX_TO_ASCII.get(char, '+')
39 return char
40
41 def _draw_progress():
42 progress = update_progress()
43 if progress:
44 print '', progress, '\r',
45 sys.stdout.flush()
46
47 def run(options, args):
48 columns, lines = terminal_size()
49 lines -= 3 # Summary + Prompt + Last line
50 # An entry needs 2 lines
51 min_size = min_size_to_consider(options.min_size, lines / 2)
52 size_observable.add_observer(_draw_progress)
53 args = args or ['.']
54 tree = pysize_tree(args, options.max_depth, min_size, options)
55 if not tree.root:
56 sys.exit(1)
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)