Bigger window by default to see the spinbutton.
[pysize.git] / pysize.py
blob19631ad819e3e2fa364f28f2c2fcef2e930da82a
1 #!/usr/bin/env python
3 import sys
4 import os
5 import optparse
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):
29 try:
30 import cProfile
31 import pstats
32 print 'Profiling using cProfile'
33 cProfile.runctx('continuation()', globals(), locals(), 'pysize.prof')
34 stats = pstats.Stats('pysize.prof')
35 except ImportError:
36 import hotshot
37 import hotshot.stats
38 prof = hotshot.Profile('pysize.prof')
39 print 'Profiling using hotshot'
40 prof.runcall(continuation)
41 prof.close()
42 stats = hotshot.stats.load('pysize.prof')
43 stats.strip_dirs()
44 stats.sort_stats('time', 'calls')
45 stats.print_stats(40)
47 def _main():
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,
54 metavar='DEPTH',
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()
62 if len(args) == 0:
63 args = ['.']
64 elif len(args) == 1:
65 args[0] = os.path.realpath(args[0])
66 else:
67 print parser.error('at most a single argument is expected')
69 continuation = lambda: UI[options.ui](options, args)
71 if options.profile:
72 _profile(continuation)
73 else:
74 continuation()
76 if __name__ == '__main__':
77 try:
78 # Try to use psyco if available
79 import psyco
80 psyco.full()
81 except ImportError:
82 pass
83 _main()