File: data-size

package info (click to toggle)
bup 0.33.9-1.2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 2,712 kB
  • sloc: python: 15,897; sh: 5,764; ansic: 2,965; pascal: 669; makefile: 21
file content (30 lines) | stat: -rwxr-xr-x 649 bytes parent folder | download | duplicates (4)
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
#!/bin/sh
"""": # -*-python-*-
bup_exec="$(dirname "$0")/bup-exec" || exit $?
exec "$bup_exec" "$0" ${1+"$@"}
"""

from __future__ import absolute_import, print_function

from os.path import getsize, isdir
from sys import stderr
import os

from bup.compat import get_argvb


def listdir_failure(ex):
    raise ex

def usage():
    print('Usage: data-size PATH ...', file=sys.stderr)

total = 0
for path in get_argvb()[1:]:
    if isdir(path):
        for root, dirs, files in os.walk(path, onerror=listdir_failure):
            total += sum(getsize(os.path.join(root, name)) for name in files)
    else:
        total += getsize(path)

print(total)