Skip to content

Commit

Permalink
Handle files that don't start with the id on the first line
Browse files Browse the repository at this point in the history
  • Loading branch information
kickroot committed May 10, 2023
1 parent 0abc068 commit 65090ad
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions dupe_check.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,31 @@

import os

def extract_id(file):
with open(sub_path + file, 'r') as f:
lines = f.readlines()
for line in lines:
line = line.strip().split(":")
if len(line) == 2 and line[0].strip() == "id":
return line[1]
return None


print(f"Initializing in {os.getcwd()}")
sub_path = "resources/rules/"
id_to_files = {}

for file in os.listdir(sub_path):
if file.endswith(".yaml"):
print(f"Processing {file}")
with open(sub_path + file, 'r') as f:
line = f.readline().strip()
uuid = line.split(":")[1].strip()
uuid = extract_id(file)
if uuid is None:
print(f"Couldn't process {file}, ignoring.")
else :
if uuid in id_to_files.keys():
msg = f"Duplicate key found for id={uuid}, file1={id_to_files[uuid]}, file2={file}"
raise Exception(msg)
id_to_files[uuid] = file
print(f"Successfully validated {id_to_files.size()} files for duplicate IDs")
print(f"Successfully validated {len(id_to_files)} files for duplicate IDs")


0 comments on commit 65090ad

Please sign in to comment.