6 from pysize
.ui
.ascii
import ui_ascii
7 from pysize
.ui
.curses
import ui_curses
8 from pysize
.ui
.gtk
import ui_gtk
9 from pysize
.core
.sigquit_traceback
import install_sigquit_traceback
11 def _ui_auto(options
, args
):
12 """Automatically choose the best available UI."""
13 if ui_gtk
.is_available():
14 return ui_gtk
.run(options
, args
)
16 if ui_curses
.is_available():
17 return ui_curses
.run(options
, args
)
19 if ui_ascii
.is_available():
20 return ui_ascii
.run(options
, args
)
22 print 'No UI available'
24 UI
= {'ascii': ui_ascii
.run
, 'curses': ui_curses
.run
,
25 'gtk': ui_gtk
.run
, 'auto': _ui_auto
}
27 def _profile(continuation
):
31 print 'Profiling using cProfile'
32 cProfile
.runctx('continuation()', globals(), locals(), 'pysize.prof')
33 stats
= pstats
.Stats('pysize.prof')
37 prof
= hotshot
.Profile('pysize.prof')
38 print 'Profiling using hotshot'
39 prof
.runcall(continuation
)
41 stats
= hotshot
.stats
.load('pysize.prof')
43 stats
.sort_stats('time', 'calls')
48 # Try to use psyco if available
55 install_sigquit_traceback()
57 locale
.setlocale(locale
.LC_ALL
, '')
58 usage
= '%s [OPTIONS] [DIRECTORIES...]' % (sys
.argv
[0])
59 parser
= optparse
.OptionParser(usage
=usage
)
60 parser
.add_option('--ui', type='choice', choices
=UI
.keys(), default
='auto',
61 help='choose the ui between: [auto], gtk, curses, ascii')
62 parser
.add_option('--max-depth', type='int', dest
='max_depth', default
=5,
64 help='maximum depth of the displayed tree [5]')
65 parser
.add_option('--min-size', type='str', dest
='min_size', default
='auto',
66 metavar
='SIZE', help='minimum size to consider drawing')
67 parser
.add_option('--profile', action
='store_true', dest
='profile',
68 default
=False, help=optparse
.SUPPRESS_HELP
)
69 (options
, args
) = parser
.parse_args()
71 if options
.max_depth
< 2:
72 parser
.error('maximum depth must be at least 2')
74 # Default path if none given
78 args
= map(os
.path
.realpath
, args
)
79 continuation
= lambda: UI
[options
.ui
](options
, args
)
82 _profile(continuation
)
86 if __name__
== '__main__':