2019-02-27 17:39:27 +01:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
|
|
|
|
import glob
|
2025-04-07 19:33:55 +02:00
|
|
|
import hashlib
|
|
|
|
import json
|
2019-02-27 17:39:27 +01:00
|
|
|
import os
|
2025-04-07 19:33:55 +02:00
|
|
|
import subprocess
|
|
|
|
|
|
|
|
CHECK_NAME = os.path.basename(__file__)
|
|
|
|
CODEQUALITY_REPORT = list()
|
|
|
|
|
|
|
|
|
|
|
|
def append(myfile):
|
|
|
|
m = hashlib.sha256()
|
|
|
|
with open(myfile, 'rb') as myfp:
|
|
|
|
m.update(myfp.read())
|
|
|
|
fingerprint = m.hexdigest()
|
|
|
|
CODEQUALITY_REPORT.append(
|
|
|
|
{
|
|
|
|
"description": "metadata .txt file has incorrect whitespace",
|
|
|
|
"check_name": CHECK_NAME,
|
|
|
|
"fingerprint": CHECK_NAME + myfile + fingerprint,
|
|
|
|
"severity": "minor",
|
|
|
|
"location": {"path": myfile, "lines": {"begin": 0}},
|
|
|
|
}
|
|
|
|
)
|
2019-02-27 17:39:27 +01:00
|
|
|
|
|
|
|
|
2025-04-07 19:33:55 +02:00
|
|
|
os.chdir(os.path.join(os.path.dirname(__file__), '..'))
|
2021-05-29 10:31:17 +02:00
|
|
|
for f in glob.glob('metadata/*/*/*.txt') + glob.glob('metadata/*/*/*/*.txt'):
|
2019-02-27 17:39:27 +01:00
|
|
|
if os.path.getsize(f) == 0:
|
2025-04-07 19:33:55 +02:00
|
|
|
append(f)
|
2019-02-27 17:39:27 +01:00
|
|
|
os.remove(f)
|
|
|
|
continue
|
|
|
|
|
|
|
|
with open(f) as fp:
|
|
|
|
data = fp.read()
|
|
|
|
with open(f, 'w') as fp:
|
|
|
|
fp.write(data.strip().rstrip())
|
|
|
|
fp.write('\n')
|
2025-04-07 19:33:55 +02:00
|
|
|
|
|
|
|
for f in subprocess.check_output(['git', 'diff', '--name-only']).split():
|
|
|
|
append(f.decode())
|
|
|
|
|
|
|
|
with open(f"{CHECK_NAME}.json", "w") as fp:
|
|
|
|
json.dump(CODEQUALITY_REPORT, fp)
|