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 Guillaume Chazarain <guichaz@yahoo.fr>
24 from pysize
.ui
.ascii
import ui_ascii
25 from pysize
.ui
.curses
import ui_curses
26 from pysize
.ui
.gtk
import ui_gtk
27 from pysize
.core
.sigquit_traceback
import install_sigquit_traceback
29 def _ui_auto(options
, args
):
30 """Automatically choose the best available UI."""
31 if ui_gtk
.is_available():
32 return ui_gtk
.run(options
, args
)
34 if ui_curses
.is_available():
35 return ui_curses
.run(options
, args
)
37 if ui_ascii
.is_available():
38 return ui_ascii
.run(options
, args
)
40 print 'No UI available'
42 UI
= {'ascii': ui_ascii
.run
, 'curses': ui_curses
.run
,
43 'gtk': ui_gtk
.run
, 'auto': _ui_auto
}
45 def _profile(continuation
):
49 print 'Profiling using cProfile'
50 cProfile
.runctx('continuation()', globals(), locals(), 'pysize.prof')
51 stats
= pstats
.Stats('pysize.prof')
55 prof
= hotshot
.Profile('pysize.prof')
56 print 'Profiling using hotshot'
57 prof
.runcall(continuation
)
59 stats
= hotshot
.stats
.load('pysize.prof')
61 stats
.sort_stats('time', 'calls')
66 # Try to use psyco if available
73 install_sigquit_traceback()
75 locale
.setlocale(locale
.LC_ALL
, '')
76 usage
= '%s [OPTIONS] [DIRECTORIES...]' % (sys
.argv
[0])
77 parser
= optparse
.OptionParser(usage
=usage
)
78 parser
.add_option('--ui', type='choice', choices
=UI
.keys(), default
='auto',
79 help='choose the ui between: [auto], gtk, curses, ascii')
80 parser
.add_option('--xdev', action
='store_false', dest
='cross_device',
82 help="ignore directories on other filesystems")
83 parser
.add_option('--max-depth', type='int', dest
='max_depth', default
=5,
85 help='maximum depth of the displayed tree [5]')
86 parser
.add_option('--min-size', type='str', dest
='min_size', default
='auto',
88 help='minimum size to consider drawing [auto]')
89 parser
.add_option('--fast-drawing', action
='store_true', dest
='fast',
90 default
=False, help='faster but simpler drawing with GTK')
91 parser
.add_option('--profile', action
='store_true', dest
='profile',
92 default
=False, help=optparse
.SUPPRESS_HELP
)
93 options
, args
= parser
.parse_args()
95 if options
.max_depth
< 2:
96 parser
.error('maximum depth must be at least 2')
98 args
= map(os
.path
.realpath
, args
)
99 continuation
= lambda: UI
[options
.ui
](options
, args
)
102 _profile(continuation
)