csv2ifc - add header validation

This commit is contained in:
Andrej730
2024-11-14 18:29:32 +05:00
parent 2c9c3e6c7f
commit d0b3ecad42
+11
View File
@@ -86,12 +86,23 @@ class Csv2Ifc:
if not row[0]: if not row[0]:
continue continue
if row[0] == "HIERARCHY": if row[0] == "HIERARCHY":
missing_columns = set(self.SUPPORTED_COLUMNS) - set(row)
if missing_columns:
raise Exception(
f"Header is missing some of the required columns: {', '.join(missing_columns)}."
)
for i, col in enumerate(row): for i, col in enumerate(row):
if not col: if not col:
continue continue
self.headers[col] = i self.headers[col] = i
continue continue
if not self.headers:
raise Exception(
f"No header found in CSV file before data row: '{row}'. Note that header should start with 'HIERARCHY' column."
)
resource_data = self.get_row_resource_data(row) resource_data = self.get_row_resource_data(row)
hierarchy_key = int(row[0]) hierarchy_key = int(row[0])
if hierarchy_key == 1: if hierarchy_key == 1: