6 from ui
.ascii
import ui_ascii
7 from ui
.curses
import ui_curses
8 from ui
.gtk
import ui_gtk
9 from 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')
47 install_sigquit_traceback()
48 parser
= optparse
.OptionParser(usage
='pysize [OPTIONS] DIRECTORY')
49 parser
.add_option('--ui', type='choice', choices
=UI
.keys(), default
='auto')
50 parser
.add_option('--max-depth', type='int', dest
='max_depth', default
=5)
51 parser
.add_option('--min-size', type='str', dest
='min_size', default
='auto')
52 parser
.add_option('--profile', action
='store_true', dest
='profile',
54 (options
, args
) = parser
.parse_args()
57 print parser
.error('A single argument is expected')
59 args
[0] = os
.path
.realpath(args
[0])
60 continuation
= lambda: UI
[options
.ui
](options
, args
)
63 _profile(continuation
)
67 if __name__
== '__main__':
69 # Try to use psyco if available