-
Notifications
You must be signed in to change notification settings - Fork 380
/
check-files-size.py
executable file
·55 lines (41 loc) · 1.32 KB
/
check-files-size.py
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
50
51
52
53
54
55
#!/usr/bin/env python3
import os, sys, argparse, json
def check_json(filepath):
ok = True
f = open(filepath, "r")
jsondata = json.load(f)
if args.verbose:
print('json data:', str(jsondata), '\n')
for j in jsondata:
if os.path.exists(j):
fsize = os.path.getsize(j)
if fsize > 1000000:
if args.verbose:
print(f"{j}: is {fsize}: NOT OK")
ok = False
else:
if args.verbose:
print(f"{j}: is {fsize}: OK")
else:
if args.verbose:
print(f"{j}: FILE NOT FOUND")
return ok
if __name__ == "__main__":
try:
parser = argparse.ArgumentParser()
parser.add_argument('-v', '--verbose', default=False, action='store_true', help='Verbose mode')
parser.add_argument('file', default='', help='Json file to check')
args = parser.parse_args()
if not args.file:
sys.exit()
if args.verbose:
print('json file:', args.file, '\n')
checks = check_json(args.file)
if not checks:
if args.verbose:
print('FAILURE')
sys.exit(1)
elif args.verbose:
print('SUCCESS')
except KeyboardInterrupt:
sys.exit()