-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdb.py
85 lines (61 loc) · 1.97 KB
/
db.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
74
75
76
77
78
79
80
81
82
83
84
import os
import json
import yaml
class Database:
def __init__(self, db_file):
if not os.path.isdir(os.path.dirname(db_file)):
make_directory(os.path.dirname(db_file))
if not os.path.isfile(db_file):
json_data = json.dumps({}, indent=4)
with open(db_file, 'w') as file:
file.write(json_data)
def make_directory(path):
os.makedirs(path)
def ingest_to_json(file, is_expression_node, *data):
json_data = read_db_json(file)
if is_expression_node:
json_data.update(expression_dictionary_data(*data))
else:
json_data.update(animation_dictionary_data(*data))
write_db_json(file, json_data)
def read_db_json(file):
with open(file, 'r') as db:
return json.load(db)
def write_db_json(json_file, json_data):
with open(json_file, 'w') as file:
json.dump(json_data, file, indent=4)
def remove_db_json(file, key):
json_data = read_db_json(file)
del json_data[key]
write_db_json(file, json_data)
def animation_dictionary_data(*data):
data = data[0]
knob_dict = {data[0]: {
'expression': data[1],
'knobs': data[2]
}
}
return knob_dict
def expression_dictionary_data(*data):
data = data[0]
knob_dict = {
data[0]: {
'temp_name0': data[1],
'temp_name1': data[2],
'temp_name2': data[3],
'temp_name3': data[4],
'temp_expr0': data[5],
'temp_expr1': data[6],
'temp_expr2': data[7],
'temp_expr3': data[8],
'expr0': data[9],
'expr1': data[10],
'expr2': data[11],
'expr3': data[12],
'knobs': data[13]
}
}
return knob_dict
def load_yaml(file):
with open(file, 'r') as kt:
return yaml.load(kt, Loader=yaml.FullLoader)