ledger/contrib/ledger-du
John Wiegley 944c63e6f2 The Great Renaming, Part II
The last commit did not contain the majority of changes because of a
slight mishap.  This contains the real changeset.
2009-02-23 19:07:30 -04:00

49 lines
950 B
Python
Executable file

#!/usr/bin/env python
import string
import sys
import os
import time
from stat import *
from os.path import *
def report_file(path):
dir_elems = string.split(dirname(path), os.sep)
if dir_elems[0] == "." or dir_elems[0] == "":
dir_elems = dir_elems[1 :]
account = string.join(dir_elems, ":")
info = os.stat(path)
print time.strftime("%Y/%m/%d", time.localtime(info[ST_MTIME])),
print basename(path)
print " ", account, " ", info[ST_SIZE], "b"
print " Equity:Files"
print
def find_files(path):
xacts = os.listdir(path)
for xact in xacts:
xact = join(path, xact)
if not islink(xact):
if isdir(xact) and xact != "/proc":
find_files(xact)
else:
report_file(xact)
args = sys.argv[1:]
if len(args):
paths = args
else:
paths = ["."]
print """
C 1.00 Kb = 1024 b
C 1.00 Mb = 1024 Kb
C 1.00 Gb = 1024 Mb
C 1.00 Tb = 1024 Gb
"""
for path in paths:
find_files(path)