18323: Revise in line with the cwltool version of this feature
[arvados.git] / doc / user / cwl / federated / extract.py
1 import csv
2 import sys
3
4 select_column = sys.argv[1]
5 select_values = sys.argv[2]
6 dataset = sys.argv[3]
7 cluster = sys.argv[4]
8
9 sv = open(select_values, "rt")
10 selectvals = [s.strip() for s in sv]
11
12 print("selectvals", selectvals)
13
14 ds = csv.reader(open(dataset, "rt"))
15 header = next(ds)
16 print("header is", header)
17 columnindex = None
18 for i,v in enumerate(header):
19     if v == select_column:
20         columnindex = i
21 if columnindex is None:
22     raise Exception("Column %s not found" % select_column)
23
24 print("column index", columnindex)
25
26 ex = csv.writer(open("extracted.csv", "wt"))
27 ex.writerow(["cluster"]+list(header))
28
29 for row in ds:
30     if row[columnindex] in selectvals:
31         ex.writerow([cluster]+list(row))