-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathschema_parser.py
73 lines (55 loc) · 1.95 KB
/
schema_parser.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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
import sys
import utils
def parse_properties_dict(props: dict):
properties: list[Property] = []
for key, value in props.items():
properties.append(Property(key,
value["type"],
{k: v for k, v in value.items() if k != "type"}))
return properties
def parse_schema_data(index, schema_data):
try:
return Schema(index,
schema_data["count"],
schema_data["index"],
parse_properties_dict(schema_data["properties"]))
except KeyError as ke:
print("Incorrect schema file:", ke)
sys.exit(1)
def generate_schemas(filename):
schemas = []
_file = utils.read_json_file(filename)
for _index, _schema in _file.items():
schemas.append(parse_schema_data(_index, _schema))
return schemas
class Property:
def __init__(self, name, prop_type, parameters):
self.name = name
self.type = prop_type
self.parameters = parameters
def __repr__(self):
return f"{self.name} ({self.type})"
class Schema:
def validate_schema(self):
pass
def __init__(self, name, count, es_index, properties: list[Property]):
self.name = name
self.count = count
self.es_index = es_index
self.properties = properties
def __repr__(self):
return f"{self.name} - Count: {self.count}, Properties: {self.properties}"
# def get_indexes(self) -> [str]:
# return self.schema.keys()
#
# def get_records_to_generate(self, index) -> int:
# return self.schema[index].get('count', 1000)
#
# def get_index_schema(self, index) -> dict:
# return self.schema[index]
#
# def get_properties(self, index) -> [str]:
# return self.schema[index]['schema'].keys()
#
# def get_property(self, index, property) -> dict:
# return self.schema[index]['schema'][property]