@@ -0,0 +1,1948 @@
+from StringIO import StringIO%0Aimport urllib2%0Aimport logging%0Aimport json%0Aimport simplejson%0Afrom pycsvw import metadata%0Afrom pycsvw import json_generator%0Afrom pycsvw import parser%0Aimport metadata_extractor%0A%0Adef validate_file(csv_file_path, schema_file_path):%0A    csv_handle = open(csv_file_path, 'rb')%0A    schema_handle = open(schema_file_path, 'rb')%0A    return validate_handle(csv_handle, schema_handle)%0A    %0A%0Adef validate_handle(csv_handle, schema_handle):%0A    table, embedded_schema = parser.parse(csv_handle, None)%0A    schema = simplejson.load(schema_handle)%0A    %0A    return validate_columns_name(embedded_schema, schema)%0A%0Adef validate_columns_name(embedded_schema, schema):%0A    columns_in_table = embedded_schema%5B%22tableSchema%22%5D%5B%22columns%22%5D%0A    columns_in_schema = schema%5B%22tableSchema%22%5D%5B%22columns%22%5D%0A    %0A    valid = True;    %0A    error_message = %22%22%0A    if len(columns_in_schema) != len(columns_in_table):%0A        error_message = error_message + %22Column number mismatch! Csv has %25s columns, but schema has %25s columns.%5Cn%22 %25 (len(columns_in_table), len(columns_in_schema))%0A        valid = valid and False                                                                                                                         %0A    %0A    for i, column in enumerate(columns_in_schema):%0A        if %22name%22 in column and not column%5B%22name%22%5D in columns_in_table%5Bi%5D%5B%22titles%22%5D:%0A            error_message = error_message + %22Column: %25s defined in schema, but not found in csv table!%5Cn%22 %25 column%5B%22name%22%5D%0A            valid = valid and False%0A        %0A    return (valid, error_message)%0A%0A%0Adef test_validate():%0A    table_path = %22F:%5CWorkRecord%5CFeature%5CMCT%5CCsvSchema%5CAdyenAcquirerCode.csv%22%0A    schema_path = %22F:%5CWorkRecord%5CFeature%5CMCT%5CCsvSchema%5CAdyenAcquirerCode.schema%22%0A    (ret, error_message) = validate_file(table_path, schema_path)%0A    print(%22Is valid: %25s%5CnError message: %25s%5Cn%22 %25 (ret, error_message))%0A          %0A%0A    %0Aif __name__ == '__main__':%0A    test_validate()%0A%0A

Add validator to validate csv file content against metadata file