Improved command line options, formatting, increased GUI font size
* Added -h/--help/-? arguments explaining usage * Added ability to accept plain and gzipped du output as first argument * Increased font size and min height * Changed mixed tabs/spaces formatting to all spaces
This commit is contained in:
parent
12a6501522
commit
eb684a6e49
58
tkdu.py
Normal file → Executable file
58
tkdu.py
Normal file → Executable file
@ -1,3 +1,5 @@
|
|||||||
|
#!/usr/bin/env python
|
||||||
|
|
||||||
# This is tkdu.py, an interactive program to display disk usage
|
# This is tkdu.py, an interactive program to display disk usage
|
||||||
# Copyright 2004 Jeff Epler <jepler@unpythonic.net>
|
# Copyright 2004 Jeff Epler <jepler@unpythonic.net>
|
||||||
#
|
#
|
||||||
@ -15,19 +17,19 @@
|
|||||||
# along with this program; if not, write to the Free Software
|
# along with this program; if not, write to the Free Software
|
||||||
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||||
|
|
||||||
import math, Tkinter, sys, os, stat, string, time, FileDialog
|
import math, Tkinter, sys, os, stat, string, time, gzip, FileDialog
|
||||||
from tkFileDialog import askdirectory
|
from tkFileDialog import askdirectory
|
||||||
|
|
||||||
MIN_PSZ = 1000
|
MIN_PSZ = 1000
|
||||||
MIN_IPSZ = 240
|
MIN_IPSZ = 240
|
||||||
MIN_W = 50
|
MIN_W = 50
|
||||||
MIN_H = 10
|
MIN_H = 15
|
||||||
VERTICAL = "vertical"
|
VERTICAL = "vertical"
|
||||||
HORIZONTAL = "horizontal"
|
HORIZONTAL = "horizontal"
|
||||||
NUM_QUEUE = 25
|
NUM_QUEUE = 25
|
||||||
FONT_FACE = ("helvetica", 8)
|
FONT_FACE = ("helvetica", 12)
|
||||||
BORDER = 2
|
BORDER = 2
|
||||||
FONT_HEIGHT = 8
|
FONT_HEIGHT = 12
|
||||||
FONT_HEIGHT2 = 20
|
FONT_HEIGHT2 = 20
|
||||||
|
|
||||||
dircolors = ['#ff7070', '#70ff70', '#7070ff']
|
dircolors = ['#ff7070', '#70ff70', '#7070ff']
|
||||||
@ -347,7 +349,7 @@ def doit(dir, files):
|
|||||||
t.bind("<Key-%d>" % i, lambda e, c=c, i=i: setdepth(e, c, i))
|
t.bind("<Key-%d>" % i, lambda e, c=c, i=i: setdepth(e, c, i))
|
||||||
c.bind("<Button-4>", lambda e: scroll(e, -1))
|
c.bind("<Button-4>", lambda e: scroll(e, -1))
|
||||||
c.bind("<Button-5>", lambda e: scroll(e, 1))
|
c.bind("<Button-5>", lambda e: scroll(e, 1))
|
||||||
c.bind("<Button-3>", ascend)
|
c.bind("<Button-2>", ascend)
|
||||||
c.tag_bind("all", "<Button-1>", descend)
|
c.tag_bind("all", "<Button-1>", descend)
|
||||||
c.tag_bind("all", "<Enter>", schedule_tip)
|
c.tag_bind("all", "<Enter>", schedule_tip)
|
||||||
c.tag_bind("all", "<Leave>", cancel_tip)
|
c.tag_bind("all", "<Leave>", cancel_tip)
|
||||||
@ -360,10 +362,10 @@ def setdepth(e, c, i):
|
|||||||
c.depth = i
|
c.depth = i
|
||||||
reconfigure(e)
|
reconfigure(e)
|
||||||
|
|
||||||
def main_pipe():
|
def main(f = sys.stdin):
|
||||||
files = {}
|
files = {}
|
||||||
firstfile = None
|
firstfile = None
|
||||||
for line in sys.stdin.readlines():
|
for line in f.readlines():
|
||||||
sz, name = string.split(line[:-1], None, 1)
|
sz, name = string.split(line[:-1], None, 1)
|
||||||
# name = name.split("/")
|
# name = name.split("/")
|
||||||
sz = long(sz)*1024
|
sz = long(sz)*1024
|
||||||
@ -438,22 +440,48 @@ class DirDialog(FileDialog.LoadFileDialog):
|
|||||||
def main_builtin_du(args):
|
def main_builtin_du(args):
|
||||||
import sys
|
import sys
|
||||||
if len(args) > 1:
|
if len(args) > 1:
|
||||||
dir = args[1]
|
p = args[1]
|
||||||
else:
|
else:
|
||||||
t = Tkinter.Tk()
|
t = Tkinter.Tk()
|
||||||
t.wm_withdraw()
|
t.wm_withdraw()
|
||||||
dir = askdirectory()
|
p = askdirectory()
|
||||||
if Tkinter._default_root is t:
|
if Tkinter._default_root is t:
|
||||||
Tkinter._default_root = None
|
Tkinter._default_root = None
|
||||||
t.destroy()
|
t.destroy()
|
||||||
if dir is None: return
|
if p is None:
|
||||||
|
return
|
||||||
files = {}
|
files = {}
|
||||||
if dir == "-":
|
|
||||||
main_pipe()
|
if p == '-h' or p == '--help' or p == '-?':
|
||||||
|
base = os.path.basename(args[0])
|
||||||
|
print 'Usage:'
|
||||||
|
print ' ', base, '<file.gz> interpret file as gzipped du -ak output and visualize it'
|
||||||
|
print ' ', base, '<file> interpret file as du -ak output and visualize it'
|
||||||
|
print ' ', base, '<folder> analyze disk usage in that folder'
|
||||||
|
print ' ', base, '- interpret stdin input as du -ak output and visualize it'
|
||||||
|
print ' ', base, ' ask for folder to analyze'
|
||||||
|
print
|
||||||
|
print 'Controls:'
|
||||||
|
print ' * Press `q` to quit'
|
||||||
|
print ' * LMB: zoom in to item'
|
||||||
|
print ' * RMB: zoom out one level'
|
||||||
|
print ' * Press `1`..`9`: Show that many nested levels'
|
||||||
|
print ' * Press `0`: Show man nested levels'
|
||||||
|
return
|
||||||
|
|
||||||
|
if p == "-":
|
||||||
|
main()
|
||||||
else:
|
else:
|
||||||
dir = abspath(dir)
|
p = abspath(p)
|
||||||
putname(files, dir, du(dir, files))
|
if os.path.isfile(p):
|
||||||
doit(dir, files)
|
if p.endswith('.gz'):
|
||||||
|
# gzipped file
|
||||||
|
main(gzip.open(p, 'r'))
|
||||||
|
else:
|
||||||
|
main(open(p, 'r'))
|
||||||
|
else:
|
||||||
|
putname(files, p, du(p, files))
|
||||||
|
doit(p, files)
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
import sys
|
import sys
|
||||||
|
Loading…
Reference in New Issue
Block a user