4 from ui
.ascii
import ui_ascii
5 from ui
.curses
import ui_curses
6 from ui
.gtk
import ui_gtk
8 def _ui_auto(options
, args
):
9 """Automatically choose the best available UI."""
10 if ui_gtk
.is_available():
11 return ui_gtk
.run(options
, args
)
13 if ui_curses
.is_available():
14 return ui_curses
.run(options
, args
)
16 if ui_ascii
.is_available():
17 return ui_ascii
.run(options
, args
)
19 print 'No UI available'
21 UI
= {'ascii': ui_ascii
.run
, 'curses': ui_curses
.run
,
22 'gtk': ui_gtk
.run
, 'auto': _ui_auto
}
25 parser
= optparse
.OptionParser(usage
='pysize [OPTIONS] DIRECTORY')
26 parser
.add_option('--ui', type='choice', choices
=UI
.keys(), default
='auto')
27 parser
.add_option('--max-depth', type='int', dest
='max_depth', default
=5)
28 (options
, args
) = parser
.parse_args()
30 print parser
.error('A single argument is expected')
32 UI
[options
.ui
](options
, args
)
38 cProfile
.run('_main()', 'pysize.prof')
39 stats
= pstats
.Stats('pysize.prof')
43 prof
= hotshot
.Profile('pysize.prof')
46 stats
= hotshot
.stats
.load('pysize.prof')
48 stats
.sort_stats('time', 'calls')
51 if __name__
== '__main__':
53 # Try to use psyco if available