-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_updater.py
50 lines (42 loc) · 1.93 KB
/
test_updater.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
import csv
import sys
def update_nf_test_file(csv_file, nf_test_file):
# Read the CSV file and filter rows
files_to_change = set() # Using a set to automatically handle duplicates
with open(csv_file, 'r') as csvfile:
csvreader = csv.DictReader(csvfile)
# Ensure the CSV file has 6 columns
if len(csvreader.fieldnames) != 6:
print("Error: The CSV file must contain exactly 6 columns.")
return
# Filter rows where "Match" column has value "NO"
for row in csvreader:
if row.get("Match") == "NO":
files_to_change.add(row.get("file1")) # Add to set to handle duplicates
files_to_change = list(files_to_change) # Convert set back to list
# Read the .nf.test file and update lines
output_file = nf_test_file + '.v2'
with open(nf_test_file, 'r') as nf_file, open(output_file, 'w') as nf_file_v2:
for line in nf_file:
stripped_line = line.rstrip()
if any(file in stripped_line for file in files_to_change):
# Skip lines already containing ".exists()"
if ".exists()" in stripped_line:
nf_file_v2.write(line)
continue
# If line ends with ",", replace it with ".exists(),"
if stripped_line.endswith(','):
updated_line = stripped_line[:-1] + '.exists(),'
else:
updated_line = stripped_line + '.exists()'
nf_file_v2.write(updated_line + '\n')
else:
nf_file_v2.write(line)
print(f"Updated .nf.test file saved as {output_file}")
if __name__ == "__main__":
if len(sys.argv) != 3:
print("Usage: python script.py <csv_file> <nf_test_file>")
else:
csv_file = sys.argv[1]
nf_test_file = sys.argv[2]
update_nf_test_file(csv_file, nf_test_file)