Neon-tech commited on
Commit
6ea58c2
·
verified ·
1 Parent(s): 142c48b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +26 -7
app.py CHANGED
@@ -1,11 +1,30 @@
1
  import os
2
- from pathlib import Path
3
 
4
- total = sum(f.stat().st_size for f in Path("/data/matches").rglob("*") if f.is_file())
5
- print(f"/data/matches: {total / 1024**3:.2f} GB")
6
 
7
- total2 = sum(f.stat().st_size for f in Path("/data/by-language").rglob("*") if f.is_file())
8
- print(f"/data/by-language: {total2 / 1024**3:.2f} GB")
 
 
9
 
10
- total3 = sum(f.stat().st_size for f in Path("/data/image-shards").rglob("*") if f.is_file())
11
- print(f"/data/image-shards: {total3 / 1024**3:.2f} GB")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  import os
 
2
 
3
+ def safe_size(root):
4
+ total = 0
5
 
6
+ for dirpath, dirnames, filenames in os.walk(root, followlinks=False):
7
+ for f in filenames:
8
+ try:
9
+ path = os.path.join(dirpath, f)
10
 
11
+ # skip broken symlinks just in case
12
+ if os.path.islink(path):
13
+ continue
14
+
15
+ total += os.path.getsize(path)
16
+ except OSError:
17
+ continue
18
+
19
+ return total
20
+
21
+
22
+ paths = [
23
+ "/data/matches",
24
+ "/data/by-language",
25
+ "/data/image-shards"
26
+ ]
27
+
28
+ for p in paths:
29
+ size = safe_size(p)
30
+ print(f"{p}: {size / 1024**3:.2f} GB")