-
Notifications
You must be signed in to change notification settings - Fork 0
/
bz2-size
executable file
·48 lines (37 loc) · 1.26 KB
/
bz2-size
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
#!/usr/bin/env python3
try:
import common
except ImportError:
import sys
import os
from os import path
home = path.abspath(path.dirname(sys.argv[0]))
sys.path.append(path.join(home, "src"))
import common
from common import finish, human_size
import multiprocessing
import concurrent.futures
import subprocess
import shlex
def get_size(filename):
return (filename, int(subprocess.check_output("bzcat " + shlex.quote(filename) + " | wc -c", shell=True)))
def main():
import argparse
parser = argparse.ArgumentParser(description="Clusters a directory containing Salento JSON datasets.")
get_input_files = common.parser_add_input_files(parser)
get_nprocs = common.parser_add_parallelism(parser)
args = parser.parse_args()
class Accum:
def __init__(self):
self.total_size = 0
def __call__(self, elem):
filename, x = elem
print(filename, x)
self.total_size += x
accum = Accum()
with finish(concurrent.futures.ThreadPoolExecutor(max_workers=get_nprocs(args)), accum) as executor:
for x in get_input_files(args, lazy=True, globs=["*.bz2"]):
executor.submit(get_size, x)
print(human_size(accum.total_size))
if __name__ == '__main__':
main()