summaryrefslogtreecommitdiff
path: root/contrib/ledger-du
blob: fe5a07062596f4bc21a72199c5aaacabe04f1153 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#!/usr/bin/env python3

import string
import sys
import os
import time

from stat import *
from os.path import *

def report_file(path):
    dir_elems = dirname(path).split(os.sep)
    if dir_elems[0] == "." or dir_elems[0] == "":
      dir_elems = dir_elems[1 :]
    account = ":".join(dir_elems)

    info = os.stat(path)
    print(time.strftime("%Y/%m/%d", time.localtime(info[ST_MTIME])))

    print(f'''{basename(path)}
    \t{account}  {info[ST_SIZE]}b
    \tEquity:Files
    ''')

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)