Commit bd47149b authored by iregon's avatar iregon
Browse files

Changed supported_file_formats to supported_data_models

parent 89de8882
......@@ -3,17 +3,10 @@
"""
Created on Thu Sep 13 15:14:51 2018
Read data file format json schema to dictionary
Add schema validation:
- check mandatory are not null
- check fixed options
..and return None if it does not validate
"""
import os
import sys
import json
......@@ -34,34 +27,12 @@ toolPath = os.path.dirname(os.path.abspath(__file__))
schema_lib = os.path.join(toolPath,'lib')
templates_path = os.path.join(schema_lib,'templates','schemas')
def templates():
schemas = glob.glob(os.path.join(templates_path,'*.json'))
return [ os.path.basename(x).split(".")[0] for x in schemas ]
def copy_template(schema, out_dir = None,out_path = None):
schemas = templates()
if schema in schemas:
schema_path = os.path.join(templates_path,schema + '.json')
schema_out = out_path if out_path else os.path.join(out_dir,schema + '.json')
shutil.copyfile(schema_path, schema_out)
if os.path.isfile( schema_out):
print('Schema template {0} copied to {1}'.format(schema, schema_out))
return
else:
print('copy_template ERROR:')
print('\tError copying schema template {0} copied to {1}'.format(schema, schema_out))
return
else:
print('copy_template ERROR:')
print('\tRequested template {} must be a valid name.'.format(schema))
print('\tValid names are: {}'.format(", ".join(schemas)))
return
def read_schema(schema_name = None, ext_schema_path = None):
if schema_name:
if schema_name not in properties.supported_file_formats:
print('ERROR: \n\tInput schema "{}" not supported. See mdf_reader.properties.supported_file_formats for supported file format schemas'.format(schema_name))
if schema_name not in properties.supported_data_models:
print('ERROR: \n\tInput data model "{}" not supported. See mdf_reader.properties.supported_data_models for supported data models'.format(schema_name))
return
else:
schema_path = os.path.join(schema_lib,schema_name)
......@@ -153,3 +124,27 @@ def df_schema(df_columns, schema):
return flat_schema
def templates():
schemas = glob.glob(os.path.join(templates_path,'*.json'))
return [ os.path.basename(x).split(".")[0] for x in schemas ]
def copy_template(schema, out_dir = None,out_path = None):
schemas = templates()
if schema in schemas:
schema_path = os.path.join(templates_path,schema + '.json')
schema_out = out_path if out_path else os.path.join(out_dir,schema + '.json')
shutil.copyfile(schema_path, schema_out)
if os.path.isfile( schema_out):
print('Schema template {0} copied to {1}'.format(schema, schema_out))
return
else:
print('copy_template ERROR:')
print('\tError copying schema template {0} copied to {1}'.format(schema, schema_out))
return
else:
print('copy_template ERROR:')
print('\tRequested template {} must be a valid name.'.format(schema))
print('\tValid names are: {}'.format(", ".join(schemas)))
return
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment