openubmc-bingo 0.5.257__py3-none-any.whl → 0.5.261__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of openubmc-bingo might be problematic. Click here for more details.
- bmcgo/__init__.py +1 -1
- bmcgo/codegen/lua/codegen.py +23 -0
- bmcgo/codegen/lua/script/model_consistency_check.py +242 -0
- bmcgo/codegen/lua/script/render_utils/__init__.py +7 -4
- bmcgo/codegen/lua/script/render_utils/client_lua.py +1 -2
- bmcgo/codegen/lua/script/render_utils/message_lua.py +2 -1
- bmcgo/codegen/lua/script/render_utils/service_lua.py +1 -1
- bmcgo/codegen/lua/script/utils.py +12 -3
- bmcgo/codegen/lua/templates/apps/Makefile +59 -2
- bmcgo/codegen/lua/v1/script/render_utils/client_lua.py +108 -0
- bmcgo/codegen/lua/v1/script/render_utils/db_lua.py +223 -0
- bmcgo/codegen/lua/v1/templates/apps/client.lua.mako +25 -10
- bmcgo/codegen/lua/v1/templates/apps/db.lua.mako +62 -0
- bmcgo/codegen/lua/v1/templates/apps/local_db.lua.mako +184 -0
- bmcgo/codegen/lua/v1/templates/apps/message.lua.mako +35 -0
- bmcgo/codegen/lua/v1/templates/apps/service.lua.mako +5 -6
- bmcgo/codegen/lua/v1/templates/apps/utils/mdb_intf.lua.mako +27 -0
- bmcgo/codegen/lua/v1/templates/apps/utils/mdb_obj.lua.mako +14 -0
- {openubmc_bingo-0.5.257.dist-info → openubmc_bingo-0.5.261.dist-info}/METADATA +1 -1
- {openubmc_bingo-0.5.257.dist-info → openubmc_bingo-0.5.261.dist-info}/RECORD +24 -16
- /bmcgo/codegen/lua/script/{render_utils/mdb_register.py → mdb_register.py} +0 -0
- {openubmc_bingo-0.5.257.dist-info → openubmc_bingo-0.5.261.dist-info}/WHEEL +0 -0
- {openubmc_bingo-0.5.257.dist-info → openubmc_bingo-0.5.261.dist-info}/entry_points.txt +0 -0
- {openubmc_bingo-0.5.257.dist-info → openubmc_bingo-0.5.261.dist-info}/top_level.txt +0 -0
|
@@ -0,0 +1,223 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
# coding=utf-8
|
|
3
|
+
# Copyright (c) 2024 Huawei Technologies Co., Ltd.
|
|
4
|
+
# openUBMC is licensed under Mulan PSL v2.
|
|
5
|
+
# You can use this software according to the terms and conditions of the Mulan PSL v2.
|
|
6
|
+
# You may obtain a copy of Mulan PSL v2 at:
|
|
7
|
+
# http://license.coscl.org.cn/MulanPSL2
|
|
8
|
+
# THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
|
|
9
|
+
# EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
|
|
10
|
+
# MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
|
|
11
|
+
# See the Mulan PSL v2 for more details.
|
|
12
|
+
|
|
13
|
+
import json
|
|
14
|
+
from utils import Utils
|
|
15
|
+
from bmcgo.codegen.lua.script.dto.options import Options
|
|
16
|
+
from bmcgo.codegen.lua.script.base import Base
|
|
17
|
+
from bmcgo.codegen.lua.script.factory import Factory
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
class ConsistencyDbLuaUtils(Base, Utils):
|
|
21
|
+
TYPE_TO_DB_MAP = {
|
|
22
|
+
"int8": 'IntegerField',
|
|
23
|
+
'uint8': 'IntegerField',
|
|
24
|
+
'int16': 'IntegerField',
|
|
25
|
+
'uint16': 'IntegerField',
|
|
26
|
+
'int32': 'IntegerField',
|
|
27
|
+
'uint32': 'IntegerField',
|
|
28
|
+
'int64': 'IntegerField',
|
|
29
|
+
'uint64': 'IntegerField',
|
|
30
|
+
'double': 'RealField',
|
|
31
|
+
'float': 'RealField',
|
|
32
|
+
'bytes': 'BolbField',
|
|
33
|
+
'string': 'TextField',
|
|
34
|
+
'bool': 'BooleandField',
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
per_type_map = {
|
|
38
|
+
'PoweroffPer': 'protect_power_off',
|
|
39
|
+
'ResetPer': 'protect_reset',
|
|
40
|
+
'PermanentPer': 'protect_permanent',
|
|
41
|
+
'TemporaryPer': 'protect_temporary',
|
|
42
|
+
'PoweroffPerRetain': 'protect_power_off_retain',
|
|
43
|
+
'ResetPerRetain': 'protect_reset_retain',
|
|
44
|
+
'TemporaryPerRetain': 'protect_temporary_retain'
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
def __init__(self, data: dict, options: Options):
|
|
48
|
+
super().__init__(data, options=options)
|
|
49
|
+
|
|
50
|
+
@staticmethod
|
|
51
|
+
def table_name(msg):
|
|
52
|
+
if msg['type'] != 'Message' or not msg['options'] or not msg['options']['table_name']:
|
|
53
|
+
return False
|
|
54
|
+
|
|
55
|
+
return msg['options']['table_name']
|
|
56
|
+
|
|
57
|
+
@staticmethod
|
|
58
|
+
def table_max_rows(msg):
|
|
59
|
+
return msg.get('type') == 'Message' and msg.get('options', {}).get('table_max_rows', False)
|
|
60
|
+
|
|
61
|
+
@staticmethod
|
|
62
|
+
def all_persistence(msg):
|
|
63
|
+
if msg['type'] != 'Message' or not msg['options']:
|
|
64
|
+
return 'nil'
|
|
65
|
+
|
|
66
|
+
if 'persistence' in msg['options']:
|
|
67
|
+
return msg['options']['persistence']
|
|
68
|
+
|
|
69
|
+
if 'table_type' in msg['options']:
|
|
70
|
+
if msg['options']['table_type'] in ConsistencyDbLuaUtils.per_type_map:
|
|
71
|
+
return ConsistencyDbLuaUtils.per_type_map[msg['options']['table_type']]
|
|
72
|
+
return 'nil'
|
|
73
|
+
|
|
74
|
+
@staticmethod
|
|
75
|
+
def check_local_per_type(root):
|
|
76
|
+
per_map = {
|
|
77
|
+
"PoweroffPer": False,
|
|
78
|
+
"ResetPer": False,
|
|
79
|
+
"TemporaryPer": False
|
|
80
|
+
}
|
|
81
|
+
for msg in root["data"]:
|
|
82
|
+
table_type = msg["options"].get("table_type", "PoweroffPer")
|
|
83
|
+
if table_type not in per_map:
|
|
84
|
+
continue
|
|
85
|
+
per_map[table_type] = True
|
|
86
|
+
return per_map.values()
|
|
87
|
+
|
|
88
|
+
@staticmethod
|
|
89
|
+
def check_local_per_poweroff(msg):
|
|
90
|
+
if "options" not in msg or "table_type" not in msg["options"]:
|
|
91
|
+
return True
|
|
92
|
+
return "options" in msg and "table_type" in msg["options"] and msg["options"]["table_type"] == "PoweroffPer"
|
|
93
|
+
|
|
94
|
+
@staticmethod
|
|
95
|
+
def check_local_per_reset(msg):
|
|
96
|
+
return "options" in msg and "table_type" in msg["options"] and msg["options"]["table_type"] == "ResetPer"
|
|
97
|
+
|
|
98
|
+
@staticmethod
|
|
99
|
+
def check_local_per_temporary(msg):
|
|
100
|
+
return "options" in msg and "table_type" in msg["options"] and msg["options"]["table_type"] == "TemporaryPer"
|
|
101
|
+
|
|
102
|
+
@staticmethod
|
|
103
|
+
def column_max_len(prop):
|
|
104
|
+
if prop['repeated']:
|
|
105
|
+
return 0
|
|
106
|
+
type_name = prop['type']
|
|
107
|
+
if type_name == "int8" or type_name == 'uint8':
|
|
108
|
+
return 8
|
|
109
|
+
if type_name == "int16" or type_name == 'uint16':
|
|
110
|
+
return 16
|
|
111
|
+
if type_name == "int32" or type_name == 'uint32':
|
|
112
|
+
return 32
|
|
113
|
+
if type_name == "int64" or type_name == 'uint64':
|
|
114
|
+
return 64
|
|
115
|
+
if 'max_len' in prop['options']:
|
|
116
|
+
return prop['options']['max_len']
|
|
117
|
+
return 0
|
|
118
|
+
|
|
119
|
+
@staticmethod
|
|
120
|
+
def unique(prop):
|
|
121
|
+
if 'unique' not in prop['options']:
|
|
122
|
+
return ''
|
|
123
|
+
return f':unique()'
|
|
124
|
+
|
|
125
|
+
@staticmethod
|
|
126
|
+
def primary_key(prop):
|
|
127
|
+
if 'primary_key' not in prop['options']:
|
|
128
|
+
return ''
|
|
129
|
+
return f':primary_key()'
|
|
130
|
+
|
|
131
|
+
@staticmethod
|
|
132
|
+
def persistence_key(prop):
|
|
133
|
+
if 'persistence_ex' in prop['options']:
|
|
134
|
+
val = prop['options']['persistence_ex']
|
|
135
|
+
return f':persistence_key("{val}")'
|
|
136
|
+
|
|
137
|
+
if 'usage' not in prop['options']:
|
|
138
|
+
return ''
|
|
139
|
+
val = ''
|
|
140
|
+
for use_type in prop['options']['usage']:
|
|
141
|
+
if use_type in ConsistencyDbLuaUtils.per_type_map:
|
|
142
|
+
val = ConsistencyDbLuaUtils.per_type_map[use_type]
|
|
143
|
+
break
|
|
144
|
+
if val == '':
|
|
145
|
+
return ''
|
|
146
|
+
|
|
147
|
+
return f':persistence_key("{val}")'
|
|
148
|
+
|
|
149
|
+
@staticmethod
|
|
150
|
+
def allow_null(prop):
|
|
151
|
+
if prop['options'].get('allow_null', False):
|
|
152
|
+
return ':null()'
|
|
153
|
+
return ''
|
|
154
|
+
|
|
155
|
+
@staticmethod
|
|
156
|
+
def extend_field(prop):
|
|
157
|
+
if prop['options'].get('extend_field', False):
|
|
158
|
+
return ':extend_field()'
|
|
159
|
+
return ''
|
|
160
|
+
|
|
161
|
+
@staticmethod
|
|
162
|
+
def deprecated(prop):
|
|
163
|
+
if prop['options'].get('deprecated', False):
|
|
164
|
+
return ':deprecated()'
|
|
165
|
+
return ''
|
|
166
|
+
|
|
167
|
+
@staticmethod
|
|
168
|
+
def critical(prop):
|
|
169
|
+
if prop['options'].get('critical', False):
|
|
170
|
+
return ':critical()'
|
|
171
|
+
return ''
|
|
172
|
+
|
|
173
|
+
def column_type(self, prop):
|
|
174
|
+
type_name = prop['type']
|
|
175
|
+
if type_name in self.TYPE_TO_DB_MAP:
|
|
176
|
+
if prop['repeated']:
|
|
177
|
+
return "JsonField()"
|
|
178
|
+
else:
|
|
179
|
+
return self.TYPE_TO_DB_MAP[type_name] + "()"
|
|
180
|
+
types = Utils(self.data, self.options).load_types(type_name)
|
|
181
|
+
if types and ('type' in types) and types['type'] == 'Enum':
|
|
182
|
+
return f'EnumField({types["package"]}.{types["name"]})'
|
|
183
|
+
return "JsonField()"
|
|
184
|
+
|
|
185
|
+
def max_len(self, prop):
|
|
186
|
+
num = self.column_max_len(prop)
|
|
187
|
+
if num == 0:
|
|
188
|
+
return ''
|
|
189
|
+
return f':max_length({num})'
|
|
190
|
+
|
|
191
|
+
def default(self, class_name, prop):
|
|
192
|
+
if 'default' not in prop['options']:
|
|
193
|
+
return ''
|
|
194
|
+
return f':default({self._convert_default_value(class_name, prop)})'
|
|
195
|
+
|
|
196
|
+
def _convert_default_value(self, class_name, prop):
|
|
197
|
+
d_val = prop['options']['default']
|
|
198
|
+
type_name = prop['type']
|
|
199
|
+
types = Utils(self.data, self.options).load_types(type_name)
|
|
200
|
+
if types and ('type' in types) and types['type'] == 'Enum':
|
|
201
|
+
if isinstance(d_val, list):
|
|
202
|
+
result = "{"
|
|
203
|
+
for val in d_val:
|
|
204
|
+
enum_type = Utils(self.data, self.options).enum_value_name(types["name"], val)
|
|
205
|
+
result += f'{types["package"]}.{types["name"]}.{enum_type},'
|
|
206
|
+
return result + "}"
|
|
207
|
+
value_name = Utils(self.data, self.options).enum_value_name(types["name"], d_val)
|
|
208
|
+
return f'{types["package"]}.{types["name"]}.{value_name}'
|
|
209
|
+
if Utils.get_lua_codegen_version() >= 10:
|
|
210
|
+
if prop.get('repeated') and not isinstance(d_val, list):
|
|
211
|
+
raise RuntimeError(f"model.json中类{class_name}的属性{prop['name']}默认值{d_val}类型与属性类型不一致")
|
|
212
|
+
if isinstance(d_val, list) or isinstance(d_val, dict):
|
|
213
|
+
json_str = json.dumps(d_val).replace("'", "''")
|
|
214
|
+
return f"[['{json_str}']]"
|
|
215
|
+
if type_name == "string" or type_name == 'bytes':
|
|
216
|
+
return f'"\'{d_val}\'"'
|
|
217
|
+
if type_name == "bool":
|
|
218
|
+
return str(bool(d_val)).lower()
|
|
219
|
+
return d_val
|
|
220
|
+
|
|
221
|
+
|
|
222
|
+
Factory().register("v1/templates/apps/db.lua.mako", ConsistencyDbLuaUtils)
|
|
223
|
+
Factory().register("v1/templates/apps/local_db.lua.mako", ConsistencyDbLuaUtils)
|
|
@@ -104,26 +104,41 @@ ${default_intf.render(default_path, ClassName, rpc['intf_class'], rpc['interface
|
|
|
104
104
|
|
|
105
105
|
% for rpc in root['interfaces']:
|
|
106
106
|
% if 'paths' in rpc and not rpc['virtual']:
|
|
107
|
-
function ${ClassName}:MutipleGet${rpc['intf_class']}Objects()
|
|
108
|
-
|
|
107
|
+
function ${ClassName}:MutipleGet${rpc['intf_class']}Objects(${render_utils.get_path_arg(rpc["paths"], False)})
|
|
108
|
+
% for path in rpc["paths"]:
|
|
109
|
+
local ${render_utils.get_path_namespace_name(loop.index)} = ${render_utils.get_path_namespace(path)}
|
|
110
|
+
%endfor
|
|
111
|
+
return get_non_virtual_interface_objects(self:get_bus(), '${rpc['interface']}', ${'true' if rpc['retry'] else 'false'}, ${render_utils.get_path_namespace_list(rpc["paths"])})
|
|
109
112
|
end
|
|
110
113
|
|
|
111
|
-
function ${ClassName}:MutipleForeach${rpc['intf_class']}Objects(cb)
|
|
112
|
-
|
|
114
|
+
function ${ClassName}:MutipleForeach${rpc['intf_class']}Objects(cb${render_utils.get_path_arg(rpc["paths"])})
|
|
115
|
+
% for path in rpc["paths"]:
|
|
116
|
+
local ${render_utils.get_path_namespace_name(loop.index)} = ${render_utils.get_path_namespace(path)}
|
|
117
|
+
%endfor
|
|
118
|
+
return foreach_non_virtual_interface_objects(self:get_bus(), '${rpc['interface']}', cb, ${'true' if rpc['retry'] else 'false'}, ${render_utils.get_path_namespace_list(rpc["paths"])})
|
|
113
119
|
end
|
|
114
120
|
|
|
115
121
|
% if rpc['dep_properties']:
|
|
116
|
-
function ${ClassName}:MutipleOn${rpc['intf_class']}PropertiesChanged(cb)
|
|
117
|
-
|
|
122
|
+
function ${ClassName}:MutipleOn${rpc['intf_class']}PropertiesChanged(cb${render_utils.get_path_arg(rpc["paths"])})
|
|
123
|
+
% for path in rpc["paths"]:
|
|
124
|
+
local ${render_utils.get_path_namespace_name(loop.index)} = ${render_utils.get_path_namespace(path)}
|
|
125
|
+
%endfor
|
|
126
|
+
self.signal_slots[#self.signal_slots + 1] = subscribe_signal.on_properties_changed(self:get_bus(), ${render_utils.get_path_namespace_list(rpc["paths"])}, cb, '${rpc['interface']}'${render_utils.get_dep_properties(rpc["dep_properties"])})
|
|
118
127
|
end
|
|
119
128
|
%endif
|
|
120
129
|
|
|
121
|
-
function ${ClassName}:MutipleOn${rpc['intf_class']}InterfacesAdded(cb)
|
|
122
|
-
|
|
130
|
+
function ${ClassName}:MutipleOn${rpc['intf_class']}InterfacesAdded(cb${render_utils.get_path_arg(rpc["paths"])})
|
|
131
|
+
% for path in rpc["paths"]:
|
|
132
|
+
local ${render_utils.get_path_namespace_name(loop.index)} = ${render_utils.get_path_namespace(path)}
|
|
133
|
+
%endfor
|
|
134
|
+
self.signal_slots[#self.signal_slots + 1] = subscribe_signal.on_interfaces_added(self:get_bus(), ${render_utils.get_path_namespace_list(rpc["paths"])}, cb, '${rpc['interface']}')
|
|
123
135
|
end
|
|
124
136
|
|
|
125
|
-
function ${ClassName}:MutipleOn${rpc['intf_class']}InterfacesRemoved(cb)
|
|
126
|
-
|
|
137
|
+
function ${ClassName}:MutipleOn${rpc['intf_class']}InterfacesRemoved(cb${render_utils.get_path_arg(rpc["paths"])})
|
|
138
|
+
% for path in rpc["paths"]:
|
|
139
|
+
local ${render_utils.get_path_namespace_name(loop.index)} = ${render_utils.get_path_namespace(path)}
|
|
140
|
+
%endfor
|
|
141
|
+
self.signal_slots[#self.signal_slots + 1] = subscribe_signal.on_interfaces_removed(self:get_bus(), ${render_utils.get_path_namespace_list(rpc["paths"])}, cb, '${rpc['interface']}')
|
|
127
142
|
end
|
|
128
143
|
|
|
129
144
|
<% continue %>
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
${make_header('lua')}
|
|
2
|
+
local class = require 'mc.class'
|
|
3
|
+
local db_base = require 'database.db_base'
|
|
4
|
+
local Col = require 'database.column'
|
|
5
|
+
<%namespace name="imports" file="../../../templates/apps/utils/imports.mako"/>
|
|
6
|
+
${imports.render(root)}
|
|
7
|
+
<%
|
|
8
|
+
ClassName = root['package'] + 'Database'
|
|
9
|
+
%>
|
|
10
|
+
|
|
11
|
+
% for msg in root['data']:
|
|
12
|
+
% if render_utils.table_name(msg):
|
|
13
|
+
---@class ${msg['name']}Table: Table
|
|
14
|
+
% for prop in msg['properties']:
|
|
15
|
+
---@field ${prop['name']} FieldBase
|
|
16
|
+
% endfor
|
|
17
|
+
% endif
|
|
18
|
+
|
|
19
|
+
% endfor
|
|
20
|
+
|
|
21
|
+
---@class ${ClassName}
|
|
22
|
+
---@field db DataBase
|
|
23
|
+
% for msg in root['data']:
|
|
24
|
+
% if render_utils.table_name(msg):
|
|
25
|
+
---@field ${msg['name']} ${msg['name']}Table
|
|
26
|
+
% endif
|
|
27
|
+
% endfor
|
|
28
|
+
local ${ClassName} = class(db_base)
|
|
29
|
+
|
|
30
|
+
function ${ClassName}:ctor()
|
|
31
|
+
% for msg in root['data']:
|
|
32
|
+
% if render_utils.table_name(msg):
|
|
33
|
+
self.${msg['name']} = self.db:Table('${render_utils.table_name(msg)}', {
|
|
34
|
+
% for prop in msg['properties']:
|
|
35
|
+
${prop['name']} = Col.${render_utils.column_type(prop)}:cid(${prop['id']})${render_utils.primary_key(prop)}${render_utils.persistence_key(prop)}${render_utils.unique(prop)}${render_utils.allow_null(prop)}${render_utils.max_len(prop)}${render_utils.default(msg['name'], prop)}${render_utils.critical(prop)},
|
|
36
|
+
% endfor
|
|
37
|
+
% if render_utils.all_persistence(msg) != 'nil':
|
|
38
|
+
}, "${render_utils.all_persistence(msg)}"):create_if_not_exist(self.datas and self.datas['${render_utils.table_name(msg)}'])
|
|
39
|
+
% else:
|
|
40
|
+
}):create_if_not_exist(self.datas and self.datas['${render_utils.table_name(msg)}'])
|
|
41
|
+
% endif
|
|
42
|
+
% if render_utils.table_max_rows(msg) and render_utils.get_lua_codegen_version() >= 11:
|
|
43
|
+
self.${msg['name']}.table_max_rows = ${msg['options']['table_max_rows']}
|
|
44
|
+
%endif
|
|
45
|
+
% endif
|
|
46
|
+
% endfor
|
|
47
|
+
|
|
48
|
+
self.tables = self.db.tables
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
% for msg in root['data']:
|
|
52
|
+
% if render_utils.table_name(msg):
|
|
53
|
+
% if render_utils.table_max_rows(msg) and render_utils.get_lua_codegen_version() >= 11:
|
|
54
|
+
|
|
55
|
+
function ${ClassName}:Register${msg['name']}TableMaxRowsCallback(cb)
|
|
56
|
+
self.${msg['name']}.table_max_rows_cb = cb
|
|
57
|
+
end
|
|
58
|
+
% endif
|
|
59
|
+
% endif
|
|
60
|
+
% endfor
|
|
61
|
+
|
|
62
|
+
return ${ClassName}.new
|
|
@@ -0,0 +1,184 @@
|
|
|
1
|
+
${make_header('lua')}
|
|
2
|
+
local class = require 'mc.class'
|
|
3
|
+
local db_base = require 'database.db_base'
|
|
4
|
+
local Col = require 'database.column'
|
|
5
|
+
<%namespace name="imports" file="../../../templates/apps/utils/imports.mako"/>
|
|
6
|
+
${imports.render(root)}
|
|
7
|
+
<%
|
|
8
|
+
has_poweroff, has_reset, has_temporary = render_utils.check_local_per_type(root)
|
|
9
|
+
%>
|
|
10
|
+
|
|
11
|
+
local db_selector = {}
|
|
12
|
+
|
|
13
|
+
% if has_poweroff:
|
|
14
|
+
<% ClassName = root['package'] + 'DatabasePoweroff' %>
|
|
15
|
+
% for msg in root['data']:
|
|
16
|
+
% if render_utils.table_name(msg) and render_utils.check_local_per_poweroff(msg):
|
|
17
|
+
---@class ${msg['name']}Table: Table
|
|
18
|
+
% for prop in msg['properties']:
|
|
19
|
+
---@field ${prop['name']} FieldBase
|
|
20
|
+
% endfor
|
|
21
|
+
% endif
|
|
22
|
+
|
|
23
|
+
% endfor
|
|
24
|
+
|
|
25
|
+
---@class ${ClassName}
|
|
26
|
+
---@field db DataBase
|
|
27
|
+
% for msg in root['data']:
|
|
28
|
+
% if render_utils.table_name(msg) and render_utils.check_local_per_poweroff(msg):
|
|
29
|
+
---@field ${msg['name']} ${msg['name']}Table
|
|
30
|
+
% endif
|
|
31
|
+
% endfor
|
|
32
|
+
|
|
33
|
+
local ${ClassName} = class(db_base)
|
|
34
|
+
|
|
35
|
+
function ${ClassName}:ctor()
|
|
36
|
+
% for msg in root['data']:
|
|
37
|
+
% if render_utils.table_name(msg) and render_utils.check_local_per_poweroff(msg):
|
|
38
|
+
self.${msg['name']} = self.db:Table('${render_utils.table_name(msg)}', {
|
|
39
|
+
% for prop in msg['properties']:
|
|
40
|
+
${prop['name']} = Col.${render_utils.column_type(prop)}${render_utils.extend_field(prop)}:cid(${prop['id']})${render_utils.primary_key(prop)}${render_utils.unique(prop)}${render_utils.allow_null(prop)}${render_utils.max_len(prop)}${render_utils.default(msg['name'], prop)}${render_utils.deprecated(prop)},
|
|
41
|
+
% endfor
|
|
42
|
+
}):create_if_not_exist(self.datas and self.datas['${render_utils.table_name(msg)}'])
|
|
43
|
+
% if render_utils.table_max_rows(msg) and render_utils.get_lua_codegen_version() >= 11:
|
|
44
|
+
self.${msg['name']}.table_max_rows = ${msg['options']['table_max_rows']}
|
|
45
|
+
%endif
|
|
46
|
+
% endif
|
|
47
|
+
% endfor
|
|
48
|
+
|
|
49
|
+
self.tables = self.db.tables
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
% for msg in root['data']:
|
|
53
|
+
% if render_utils.table_name(msg) and render_utils.check_local_per_poweroff(msg):
|
|
54
|
+
% if render_utils.table_max_rows(msg) and render_utils.get_lua_codegen_version() >= 11:
|
|
55
|
+
|
|
56
|
+
function ${ClassName}:Register${msg['name']}TableMaxRowsCallback(cb)
|
|
57
|
+
self.${msg['name']}.table_max_rows_cb = cb
|
|
58
|
+
end
|
|
59
|
+
% endif
|
|
60
|
+
% endif
|
|
61
|
+
% endfor
|
|
62
|
+
|
|
63
|
+
db_selector["poweroff"] = ${ClassName}.new
|
|
64
|
+
% endif
|
|
65
|
+
|
|
66
|
+
% if has_reset:
|
|
67
|
+
<% ClassName = root['package'] + 'DatabaseReset' %>
|
|
68
|
+
% for msg in root['data']:
|
|
69
|
+
% if render_utils.table_name(msg) and render_utils.check_local_per_reset(msg):
|
|
70
|
+
---@class ${msg['name']}Table: Table
|
|
71
|
+
% for prop in msg['properties']:
|
|
72
|
+
---@field ${prop['name']} FieldBase
|
|
73
|
+
% endfor
|
|
74
|
+
% endif
|
|
75
|
+
|
|
76
|
+
% endfor
|
|
77
|
+
|
|
78
|
+
---@class ${ClassName}
|
|
79
|
+
---@field db DataBase
|
|
80
|
+
% for msg in root['data']:
|
|
81
|
+
% if render_utils.table_name(msg) and render_utils.check_local_per_reset(msg):
|
|
82
|
+
---@field ${msg['name']} ${msg['name']}Table
|
|
83
|
+
% endif
|
|
84
|
+
% endfor
|
|
85
|
+
|
|
86
|
+
local ${ClassName} = class(db_base)
|
|
87
|
+
|
|
88
|
+
function ${ClassName}:ctor()
|
|
89
|
+
% for msg in root['data']:
|
|
90
|
+
% if render_utils.table_name(msg) and render_utils.check_local_per_reset(msg):
|
|
91
|
+
self.${msg['name']} = self.db:Table('${render_utils.table_name(msg)}', {
|
|
92
|
+
% for prop in msg['properties']:
|
|
93
|
+
${prop['name']} = Col.${render_utils.column_type(prop)}${render_utils.extend_field(prop)}:cid(${prop['id']})${render_utils.primary_key(prop)}${render_utils.unique(prop)}${render_utils.allow_null(prop)}${render_utils.max_len(prop)}${render_utils.default(msg['name'], prop)}${render_utils.deprecated(prop)},
|
|
94
|
+
% endfor
|
|
95
|
+
}):create_if_not_exist(self.datas and self.datas['${render_utils.table_name(msg)}'])
|
|
96
|
+
% if render_utils.table_max_rows(msg) and render_utils.get_lua_codegen_version() >= 11:
|
|
97
|
+
self.${msg['name']}.table_max_rows = ${msg['options']['table_max_rows']}
|
|
98
|
+
%endif
|
|
99
|
+
% endif
|
|
100
|
+
% endfor
|
|
101
|
+
|
|
102
|
+
self.tables = self.db.tables
|
|
103
|
+
end
|
|
104
|
+
|
|
105
|
+
% for msg in root['data']:
|
|
106
|
+
% if render_utils.table_name(msg) and render_utils.check_local_per_reset(msg):
|
|
107
|
+
% if render_utils.table_max_rows(msg) and render_utils.get_lua_codegen_version() >= 11:
|
|
108
|
+
|
|
109
|
+
function ${ClassName}:Register${msg['name']}TableMaxRowsCallback(cb)
|
|
110
|
+
self.${msg['name']}.table_max_rows_cb = cb
|
|
111
|
+
end
|
|
112
|
+
% endif
|
|
113
|
+
% endif
|
|
114
|
+
% endfor
|
|
115
|
+
|
|
116
|
+
db_selector["reset"] = ${ClassName}.new
|
|
117
|
+
% endif
|
|
118
|
+
|
|
119
|
+
% if has_temporary:
|
|
120
|
+
<% ClassName = root['package'] + 'DatabaseTemporary' %>
|
|
121
|
+
% for msg in root['data']:
|
|
122
|
+
% if render_utils.table_name(msg) and render_utils.check_local_per_temporary(msg):
|
|
123
|
+
---@class ${msg['name']}Table: Table
|
|
124
|
+
% for prop in msg['properties']:
|
|
125
|
+
---@field ${prop['name']} FieldBase
|
|
126
|
+
% endfor
|
|
127
|
+
% endif
|
|
128
|
+
|
|
129
|
+
% endfor
|
|
130
|
+
|
|
131
|
+
---@class ${ClassName}
|
|
132
|
+
---@field db DataBase
|
|
133
|
+
% for msg in root['data']:
|
|
134
|
+
% if render_utils.table_name(msg) and render_utils.check_local_per_temporary(msg):
|
|
135
|
+
---@field ${msg['name']} ${msg['name']}Table
|
|
136
|
+
% endif
|
|
137
|
+
% endfor
|
|
138
|
+
|
|
139
|
+
local ${ClassName} = class(db_base)
|
|
140
|
+
|
|
141
|
+
function ${ClassName}:ctor()
|
|
142
|
+
local db = Databases(path)
|
|
143
|
+
local obj = {db = db}
|
|
144
|
+
|
|
145
|
+
% for msg in root['data']:
|
|
146
|
+
% if render_utils.table_name(msg) and render_utils.check_local_per_temporary(msg):
|
|
147
|
+
self.${msg['name']} = self.db:Table('${render_utils.table_name(msg)}', {
|
|
148
|
+
% for prop in msg['properties']:
|
|
149
|
+
${prop['name']} = Col.${render_utils.column_type(prop)}${render_utils.extend_field(prop)}:cid(${prop['id']})${render_utils.primary_key(prop)}${render_utils.unique(prop)}${render_utils.allow_null(prop)}${render_utils.max_len(prop)}${render_utils.default(msg['name'], prop)}${render_utils.deprecated(prop)},
|
|
150
|
+
% endfor
|
|
151
|
+
}):create_if_not_exist(self.datas and self.datas['${render_utils.table_name(msg)}'])
|
|
152
|
+
% if render_utils.table_max_rows(msg) and render_utils.get_lua_codegen_version() >= 11:
|
|
153
|
+
self.${msg['name']}.table_max_rows = ${msg['options']['table_max_rows']}
|
|
154
|
+
%endif
|
|
155
|
+
% endif
|
|
156
|
+
% endfor
|
|
157
|
+
|
|
158
|
+
self.tables = self.db.tables
|
|
159
|
+
return setmetatable(obj, ${ClassName})
|
|
160
|
+
end
|
|
161
|
+
|
|
162
|
+
% for msg in root['data']:
|
|
163
|
+
% if render_utils.table_name(msg) and render_utils.check_local_per_temporary(msg):
|
|
164
|
+
% if render_utils.table_max_rows(msg) and render_utils.get_lua_codegen_version() >= 11:
|
|
165
|
+
|
|
166
|
+
function ${ClassName}:Register${msg['name']}TableMaxRowsCallback(cb)
|
|
167
|
+
self.${msg['name']}.table_max_rows_cb = cb
|
|
168
|
+
end
|
|
169
|
+
% endif
|
|
170
|
+
% endif
|
|
171
|
+
% endfor
|
|
172
|
+
|
|
173
|
+
db_selector["temporary"] = ${ClassName}.new
|
|
174
|
+
% endif
|
|
175
|
+
|
|
176
|
+
<% ClassName = root['package'] + 'Database' %>
|
|
177
|
+
local ${ClassName} = {}
|
|
178
|
+
${ClassName}.__index = ${ClassName}
|
|
179
|
+
|
|
180
|
+
function ${ClassName}.new(path, datas, type)
|
|
181
|
+
return db_selector[type] and db_selector[type](path, datas) or nil
|
|
182
|
+
end
|
|
183
|
+
|
|
184
|
+
return ${ClassName}.new
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
${make_header('lua')}
|
|
2
|
+
<%
|
|
3
|
+
messages = [msg for msg in root['data'] if msg['type'] != 'Enum']
|
|
4
|
+
enums = [msg for msg in root['data'] if msg['type'] == 'Enum']
|
|
5
|
+
%>
|
|
6
|
+
local validate = require 'mc.validate'
|
|
7
|
+
local utils = require 'mc.utils'
|
|
8
|
+
% if len(enums) > 0:
|
|
9
|
+
local create_enum_type = require 'mc.enum'
|
|
10
|
+
% endif
|
|
11
|
+
<%namespace name="message" file="../../../templates/apps/utils/message.mako"/>
|
|
12
|
+
<%namespace name="imports" file="../../../templates/apps/utils/imports.mako"/>
|
|
13
|
+
<%namespace name="enum" file="../../../templates/apps/utils/enum.mako"/>
|
|
14
|
+
<%namespace name="mdb_intf" file= "utils/mdb_intf.lua.mako"/>
|
|
15
|
+
${imports.render(root)}
|
|
16
|
+
|
|
17
|
+
local ${root['package']} = {}
|
|
18
|
+
|
|
19
|
+
% for msg in enums:
|
|
20
|
+
${enum.render(msg, 'create_enum_type')}
|
|
21
|
+
${root['package']}.${msg['name']} = E${msg['name']}
|
|
22
|
+
|
|
23
|
+
% endfor
|
|
24
|
+
|
|
25
|
+
% for msg in messages:
|
|
26
|
+
${message.render(msg, root.get('intf', {}).get('name', ''))}
|
|
27
|
+
|
|
28
|
+
${root['package']}.${msg['name']} = T${msg['name']}
|
|
29
|
+
% endfor
|
|
30
|
+
|
|
31
|
+
% if 'intf' in root:
|
|
32
|
+
${root['package']}.interface = ${mdb_intf.render(root['intf'])}
|
|
33
|
+
|
|
34
|
+
% endif
|
|
35
|
+
return ${root['package']}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
${make_header('lua')}
|
|
2
2
|
<%namespace name="imports" file="../../../templates/apps/utils/imports.mako"/>
|
|
3
3
|
<%namespace name="default_intf" file="../../../templates/apps/utils/default_intf.lua.mako"/>
|
|
4
|
-
<%namespace name="mdb_obj" file= "
|
|
4
|
+
<%namespace name="mdb_obj" file= "utils/mdb_obj.lua.mako"/>
|
|
5
5
|
<% has_signal = root['signals']%>
|
|
6
6
|
<% has_mdb = any('path' in cls_data for cls, cls_data in root['class_require'].items())%>
|
|
7
7
|
<% has_default = any((rpc['default'] != '' and not rpc['override']) for rpc in root['methods'])%>
|
|
@@ -10,7 +10,7 @@ ${make_header('lua')}
|
|
|
10
10
|
% if root['has_ipmi_cmd']:
|
|
11
11
|
local ipmi = require 'ipmi'
|
|
12
12
|
% endif
|
|
13
|
-
% if has_default
|
|
13
|
+
% if has_default:
|
|
14
14
|
local mdb = require 'mc.mdb'
|
|
15
15
|
% endif
|
|
16
16
|
local class = require 'mc.class'
|
|
@@ -26,12 +26,10 @@ local object_manage = require 'mc.mdb.object_manage'
|
|
|
26
26
|
local persist_client = require 'persistence.persist_client_lib'
|
|
27
27
|
% endif
|
|
28
28
|
|
|
29
|
-
|
|
30
|
-
local ${intf}Types = require '${project_name}.json_types.${intf}'
|
|
31
|
-
% endfor
|
|
29
|
+
local class_data = {}
|
|
32
30
|
|
|
33
31
|
% for cls, cls_data in root['class_require'].items():
|
|
34
|
-
${mdb_obj.render(cls, cls_data['data'], root['class_require'])}
|
|
32
|
+
class_data.${cls} = {${mdb_obj.render(cls, cls_data['data'], root['class_require'])}}
|
|
35
33
|
% endfor
|
|
36
34
|
|
|
37
35
|
% if root['path_level'] == 2:
|
|
@@ -123,6 +121,7 @@ function ${ClassName}:ctor(${"" if root['path_level'] == 2 else "bus"})
|
|
|
123
121
|
% if utils_py.has_db(root):
|
|
124
122
|
self.db_types = ${utils_py.get_db_types(root)}
|
|
125
123
|
% endif
|
|
124
|
+
self.class_data = class_data
|
|
126
125
|
self.name = '${project_name}'
|
|
127
126
|
end
|
|
128
127
|
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
<%def name="render(intf)">
|
|
2
|
+
{
|
|
3
|
+
'${intf['name']}', {
|
|
4
|
+
% if 'properties' in intf['data'] :
|
|
5
|
+
% for p,p_data in intf['data']['properties'].items():
|
|
6
|
+
${p} = {'${render_utils.do_type_to_dbus_json(intf['data'], p_data)}', ${render_utils.options_json(p_data)}, ${render_utils.readonly_json(p_data)}, ${render_utils.default_json(p_data)}, false},
|
|
7
|
+
% endfor
|
|
8
|
+
% endif
|
|
9
|
+
}, {
|
|
10
|
+
% if 'methods' in intf['data'] :
|
|
11
|
+
% for method, method_data in intf['data']['methods'].items():
|
|
12
|
+
% if version >= 16:
|
|
13
|
+
${method} = {'a{ss}${render_utils.do_types_to_dbus_json(intf['data'], method_data, 'req')}', '${render_utils.do_types_to_dbus_json(intf['data'], method_data,'rsp')}', T${method}Req, T${method}Rsp${render_utils.get_method_description(intf['name'], method_data)}},
|
|
14
|
+
% else:
|
|
15
|
+
${method} = {'a{ss}${render_utils.do_types_to_dbus_json(intf['data'], method_data, 'req')}', '${render_utils.do_types_to_dbus_json(intf['data'], method_data,'rsp')}', T${method}Req, T${method}Rsp},
|
|
16
|
+
%endif
|
|
17
|
+
% endfor
|
|
18
|
+
% endif
|
|
19
|
+
}, {
|
|
20
|
+
% if 'signals' in intf['data'] :
|
|
21
|
+
% for s,s_data in intf['data']['signals'].items():
|
|
22
|
+
${s} = 'a{ss}${render_utils.do_types_to_dbus_json(intf['data'], intf['data']['signals'], s)}',
|
|
23
|
+
% endfor
|
|
24
|
+
% endif
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
</%def>
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
|
|
2
|
+
|
|
3
|
+
<%def name="render(class_name, class_data, class_require)">
|
|
4
|
+
% if 'path' in class_data:
|
|
5
|
+
path = '${render_utils.get_path(class_name, class_require)}',
|
|
6
|
+
% if 'interfaces' in class_data:
|
|
7
|
+
interface_data = {
|
|
8
|
+
% for intf in class_data['interfaces']:
|
|
9
|
+
{name = '${intf}'},
|
|
10
|
+
% endfor
|
|
11
|
+
}
|
|
12
|
+
%endif
|
|
13
|
+
%endif
|
|
14
|
+
</%def>
|