7 from ui
.ascii
import ui_ascii
8 from ui
.curses
import ui_curses
9 from ui
.gtk
import ui_gtk
10 from core
.sigquit_traceback
import install_sigquit_traceback
12 def _ui_auto(options
, args
):
13 """Automatically choose the best available UI."""
14 if ui_gtk
.is_available():
15 return ui_gtk
.run(options
, args
)
17 if ui_curses
.is_available():
18 return ui_curses
.run(options
, args
)
20 if ui_ascii
.is_available():
21 return ui_ascii
.run(options
, args
)
23 print 'No UI available'
25 UI
= {'ascii': ui_ascii
.run
, 'curses': ui_curses
.run
,
26 'gtk': ui_gtk
.run
, 'auto': _ui_auto
}
28 def _profile(continuation
):
32 print 'Profiling using cProfile'
33 cProfile
.runctx('continuation()', globals(), locals(), 'pysize.prof')
34 stats
= pstats
.Stats('pysize.prof')
38 prof
= hotshot
.Profile('pysize.prof')
39 print 'Profiling using hotshot'
40 prof
.runcall(continuation
)
42 stats
= hotshot
.stats
.load('pysize.prof')
44 stats
.sort_stats('time', 'calls')
48 install_sigquit_traceback()
49 usage
= '%s [OPTIONS] [DIRECTORY]' % (sys
.argv
[0])
50 parser
= optparse
.OptionParser(usage
=usage
)
51 parser
.add_option('--ui', type='choice', choices
=UI
.keys(), default
='auto',
52 help='choose the ui between: [auto], gtk, curses, ascii')
53 parser
.add_option('--max-depth', type='int', dest
='max_depth', default
=5,
55 help='maximum depth of the displayed tree [5]')
56 parser
.add_option('--min-size', type='str', dest
='min_size', default
='auto',
57 metavar
='SIZE', help='minimum size to consider drawing')
58 parser
.add_option('--profile', action
='store_true', dest
='profile',
59 default
=False, help=optparse
.SUPPRESS_HELP
)
60 (options
, args
) = parser
.parse_args()
65 args
[0] = os
.path
.realpath(args
[0])
67 print parser
.error('at most a single argument is expected')
69 continuation
= lambda: UI
[options
.ui
](options
, args
)
72 _profile(continuation
)
76 if __name__
== '__main__':
78 # Try to use psyco if available