lbkit 0.5.17__tar.gz → 0.5.19__tar.gz

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.
Files changed (55) hide show
  1. {lbkit-0.5.17/lbkit.egg-info → lbkit-0.5.19}/PKG-INFO +1 -1
  2. lbkit-0.5.19/lbkit/__init__.py +2 -0
  3. {lbkit-0.5.17 → lbkit-0.5.19}/lbkit/codegen/ctype_defination.py +37 -32
  4. {lbkit-0.5.17 → lbkit-0.5.19}/lbkit/codegen/idf_interface.py +197 -16
  5. {lbkit-0.5.17 → lbkit-0.5.19}/lbkit/codegen/template/public.c.mako +19 -20
  6. {lbkit-0.5.17 → lbkit-0.5.19}/lbkit/codegen/template/server.c.mako +56 -5
  7. {lbkit-0.5.17 → lbkit-0.5.19}/lbkit/component/build.py +2 -2
  8. lbkit-0.5.19/lbkit/helper.py +96 -0
  9. {lbkit-0.5.17 → lbkit-0.5.19/lbkit.egg-info}/PKG-INFO +1 -1
  10. {lbkit-0.5.17 → lbkit-0.5.19}/lbkit.egg-info/SOURCES.txt +4 -1
  11. {lbkit-0.5.17 → lbkit-0.5.19}/lbkit.egg-info/top_level.txt +1 -0
  12. lbkit-0.5.19/test/__init__.py +0 -0
  13. lbkit-0.5.19/test/test_codegen.py +279 -0
  14. lbkit-0.5.19/test/test_helper.py +247 -0
  15. lbkit-0.5.17/lbkit/__init__.py +0 -2
  16. lbkit-0.5.17/lbkit/helper.py +0 -27
  17. {lbkit-0.5.17 → lbkit-0.5.19}/AUTHORS +0 -0
  18. {lbkit-0.5.17 → lbkit-0.5.19}/LICENSE +0 -0
  19. {lbkit-0.5.17 → lbkit-0.5.19}/MANIFEST.in +0 -0
  20. {lbkit-0.5.17 → lbkit-0.5.19}/README.md +0 -0
  21. {lbkit-0.5.17 → lbkit-0.5.19}/lbkit/ci_robot/__init__.py +0 -0
  22. {lbkit-0.5.17 → lbkit-0.5.19}/lbkit/ci_robot/gitee.py +0 -0
  23. {lbkit-0.5.17 → lbkit-0.5.19}/lbkit/cli.py +0 -0
  24. {lbkit-0.5.17 → lbkit-0.5.19}/lbkit/codegen/__init__.py +0 -0
  25. {lbkit-0.5.17 → lbkit-0.5.19}/lbkit/codegen/codegen.py +0 -0
  26. {lbkit-0.5.17 → lbkit-0.5.19}/lbkit/codegen/renderer.py +0 -0
  27. {lbkit-0.5.17 → lbkit-0.5.19}/lbkit/codegen/template/client.c.mako +0 -0
  28. {lbkit-0.5.17 → lbkit-0.5.19}/lbkit/codegen/template/client.h.mako +0 -0
  29. {lbkit-0.5.17 → lbkit-0.5.19}/lbkit/codegen/template/interface.c.mako +0 -0
  30. {lbkit-0.5.17 → lbkit-0.5.19}/lbkit/codegen/template/interface.introspect.xml.mako +0 -0
  31. {lbkit-0.5.17 → lbkit-0.5.19}/lbkit/codegen/template/public.h.mako +0 -0
  32. {lbkit-0.5.17 → lbkit-0.5.19}/lbkit/codegen/template/server.h.mako +0 -0
  33. {lbkit-0.5.17 → lbkit-0.5.19}/lbkit/component/__init__.py +0 -0
  34. {lbkit-0.5.17 → lbkit-0.5.19}/lbkit/component/arg_parser.py +0 -0
  35. {lbkit-0.5.17 → lbkit-0.5.19}/lbkit/component/template/conanbase.mako +0 -0
  36. {lbkit-0.5.17 → lbkit-0.5.19}/lbkit/component/template/deploy.mako +0 -0
  37. {lbkit-0.5.17 → lbkit-0.5.19}/lbkit/component/test.py +0 -0
  38. {lbkit-0.5.17 → lbkit-0.5.19}/lbkit/errors.py +0 -0
  39. {lbkit-0.5.17 → lbkit-0.5.19}/lbkit/integration/__init__.py +0 -0
  40. {lbkit-0.5.17 → lbkit-0.5.19}/lbkit/integration/build_image.py +0 -0
  41. {lbkit-0.5.17 → lbkit-0.5.19}/lbkit/integration/build_manifest.py +0 -0
  42. {lbkit-0.5.17 → lbkit-0.5.19}/lbkit/integration/build_prepare.py +0 -0
  43. {lbkit-0.5.17 → lbkit-0.5.19}/lbkit/integration/build_rootfs.py +0 -0
  44. {lbkit-0.5.17 → lbkit-0.5.19}/lbkit/integration/config.py +0 -0
  45. {lbkit-0.5.17 → lbkit-0.5.19}/lbkit/integration/task.py +0 -0
  46. {lbkit-0.5.17 → lbkit-0.5.19}/lbkit/integration/template/conanfile.py.mako +0 -0
  47. {lbkit-0.5.17 → lbkit-0.5.19}/lbkit/lbkit.py +0 -0
  48. {lbkit-0.5.17 → lbkit-0.5.19}/lbkit/log.py +0 -0
  49. {lbkit-0.5.17 → lbkit-0.5.19}/lbkit/misc.py +0 -0
  50. {lbkit-0.5.17 → lbkit-0.5.19}/lbkit/tools.py +0 -0
  51. {lbkit-0.5.17 → lbkit-0.5.19}/lbkit.egg-info/dependency_links.txt +0 -0
  52. {lbkit-0.5.17 → lbkit-0.5.19}/lbkit.egg-info/entry_points.txt +0 -0
  53. {lbkit-0.5.17 → lbkit-0.5.19}/lbkit.egg-info/requires.txt +0 -0
  54. {lbkit-0.5.17 → lbkit-0.5.19}/setup.cfg +0 -0
  55. {lbkit-0.5.17 → lbkit-0.5.19}/setup.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: lbkit
3
- Version: 0.5.17
3
+ Version: 0.5.19
4
4
  Summary: Tools provided by litebmc.com
5
5
  Home-page: https://www.litebmc.com
6
6
  Author: xuhj@litebmc.com
@@ -0,0 +1,2 @@
1
+
2
+ __version__ = '0.5.19'
@@ -5,9 +5,11 @@ from lbkit.errors import OdfValidateException
5
5
 
6
6
  class IdfValidator():
7
7
  validator = {}
8
+ name = ""
8
9
 
9
- def set_validator(self, value):
10
+ def set_validator(self, value, name):
10
11
  self.validator = value
12
+ self.name = name
11
13
 
12
14
  def odf_validate(self):
13
15
  idf_validator = idf_validator
@@ -84,8 +86,8 @@ class IntegerValidator(IdfValidator):
84
86
  raise OdfValidateException(f"The max value {self.maximum} less than or equal to {self.minimum}")
85
87
  super().__init__()
86
88
 
87
- def set_validator(self, value):
88
- super().set_validator(value)
89
+ def set_validator(self, value, name):
90
+ super().set_validator(value, name)
89
91
  max = self.validator.get("max", self.maximum)
90
92
  if max > self.maximum:
91
93
  max = self.maximum
@@ -97,20 +99,23 @@ class IntegerValidator(IdfValidator):
97
99
  if not self.signed and self.minimum < 0:
98
100
  self.minimum = 0
99
101
  if self.maximum < self.minimum:
100
- raise OdfValidateException(f"The max value {self.maximum} less than or equal to {self.minimum}")
102
+ raise OdfValidateException(f"The max value {self.maximum} less than or equal to {self.minimum}, property {name} validation failed")
101
103
 
102
104
  def odf_validate(self):
103
105
  func = []
104
106
  if self.signed:
105
- if self.minimum == -9223372036854775808:
106
- func.append(f"validate_odf_as_signed(doc, node, prop, {self.maximum}, G_MININT64, error_list)")
107
- else:
108
- func.append(f"validate_odf_as_signed(doc, node, prop, {self.maximum}, {self.minimum}, error_list)")
107
+ min_str = self.minimum
108
+ max_str = self.maximum
109
+ if self.minimum <= -9223372036854775808:
110
+ min_str = "G_MININT64"
111
+ if self.maximum >= 9223372036854775807:
112
+ max_str = "G_MAXINT64"
113
+ func.append(f"validate_odf_as_signed(doc, node, prop, {max_str}, {min_str}, error_list)")
109
114
  else:
110
- if self.maximum == 18446744073709551615:
111
- func.append(f"validate_odf_as_unsigned(doc, node, prop, G_MAXUINT64, {self.minimum}, error_list)")
112
- else:
113
- func.append(f"validate_odf_as_unsigned(doc, node, prop, {self.maximum}, {self.minimum}, error_list)")
115
+ max_str = f"{self.maximum}UL"
116
+ if self.maximum >= 18446744073709551615:
117
+ max_str = "G_MAXUINT64"
118
+ func.append(f"validate_odf_as_unsigned(doc, node, prop, {max_str}, {self.minimum}UL, error_list)")
114
119
  return func
115
120
 
116
121
  def odf_schema(self, allow_ref):
@@ -142,21 +147,21 @@ class IntegerValidator(IdfValidator):
142
147
  class IntegerArrayValidator(IntegerValidator):
143
148
  def odf_validate(self):
144
149
  func = []
145
- min = self.minimum
146
- max = self.maximum
150
+ min_str = f"{self.minimum}UL"
151
+ max_str = f"{self.maximum}UL"
147
152
  if self.signed:
148
- if self.minimum <= -0x8000_0000_0000_0000:
149
- min = "G_MININT64"
153
+ if self.minimum <= -9223372036854775808:
154
+ min_str = "G_MININT64"
150
155
  if self.maximum >= 0x7fff_ffff_ffff_ffff:
151
- max = "G_MAXINT64"
156
+ max_str = "G_MAXINT64"
152
157
  else:
153
158
  if self.maximum >= 0xffff_ffff_ffff_ffff:
154
- max = "G_MAXUINT64"
159
+ max_str = "G_MAXUINT64"
155
160
 
156
161
  if self.signed:
157
- func.append(f"validate_odf_as_signed_v(doc, node, prop, {max}, {min}, error_list)")
162
+ func.append(f"validate_odf_as_signed_v(doc, node, prop, {max_str}, {min_str}, error_list)")
158
163
  else:
159
- func.append(f"validate_odf_as_unsigned_v(doc, node, prop, {max}, {min}, error_list)")
164
+ func.append(f"validate_odf_as_unsigned_v(doc, node, prop, {max_str}, {min_str}, error_list)")
160
165
  return func
161
166
 
162
167
  def odf_schema(self, allow_ref):
@@ -199,18 +204,18 @@ class FloatValidator(IdfValidator):
199
204
  def odf_validate(self):
200
205
  func = ["validate_odf_as_double(doc, node, prop, error_list)"]
201
206
  if self.exclusive_max is not None:
202
- func.append(f"validate_odf_as_float_exclusive_max(doc, node, prop, {self.exclusive_max}, error_list)")
207
+ func.append(f"validate_odf_as_double_exclusive_max(doc, node, prop, {self.exclusive_max}, error_list)")
203
208
  elif self.maximum != sys.float_info.max:
204
- func.append(f"validate_odf_as_float_max(doc, node, prop, {self.maximum}, error_list)")
209
+ func.append(f"validate_odf_as_double_max(doc, node, prop, {self.maximum}, error_list)")
205
210
 
206
211
  if self.exclusive_min is not None:
207
- func.append(f"validate_odf_as_float_exclusive_min(doc, node, prop, {self.exclusive_min}, error_list)")
212
+ func.append(f"validate_odf_as_double_exclusive_min(doc, node, prop, {self.exclusive_min}, error_list)")
208
213
  elif self.minimum != (-sys.float_info.max):
209
- func.append(f"validate_odf_as_float_min(doc, node, prop, {self.minimum}, error_list)")
214
+ func.append(f"validate_odf_as_double_min(doc, node, prop, {self.minimum}, error_list)")
210
215
  return func
211
216
 
212
- def set_validator(self, value):
213
- super().set_validator(value)
217
+ def set_validator(self, value, name):
218
+ super().set_validator(value, name)
214
219
  self.maximum = self.validator.get("max", self.maximum)
215
220
  self.minimum = self.validator.get("min", self.minimum)
216
221
  self.exclusive_max = self.validator.get("exclusive_max", None)
@@ -256,14 +261,14 @@ class FloatArrayValidator(FloatValidator):
256
261
  def odf_validate(self):
257
262
  func = ["validate_odf_as_double_v(doc, node, prop, error_list)"]
258
263
  if self.exclusive_max is not None:
259
- func.append(f"validate_odf_as_float_exclusive_max_v(doc, node, prop, {self.exclusive_max}, error_list)")
264
+ func.append(f"validate_odf_as_double_exclusive_max_v(doc, node, prop, {self.exclusive_max}, error_list)")
260
265
  elif self.maximum != sys.float_info.max:
261
- func.append(f"validate_odf_as_float_max_v(doc, node, prop, {self.maximum}, error_list)")
266
+ func.append(f"validate_odf_as_double_max_v(doc, node, prop, {self.maximum}, error_list)")
262
267
 
263
268
  if self.exclusive_min is not None:
264
- func.append(f"validate_odf_as_float_exclusive_min_v(doc, node, prop, {self.exclusive_min}, error_list)")
269
+ func.append(f"validate_odf_as_double_exclusive_min_v(doc, node, prop, {self.exclusive_min}, error_list)")
265
270
  elif self.minimum != (-sys.float_info.max):
266
- func.append(f"validate_odf_as_float_min_v(doc, node, prop, {self.minimum}, error_list)")
271
+ func.append(f"validate_odf_as_double_min_v(doc, node, prop, {self.minimum}, error_list)")
267
272
  return func
268
273
 
269
274
  def odf_schema(self, allow_ref):
@@ -294,9 +299,9 @@ class StringValidator(IdfValidator):
294
299
  self.pattern = pattern
295
300
  super().__init__()
296
301
 
297
- def set_validator(self, value):
302
+ def set_validator(self, value, name):
303
+ super().set_validator(value, name)
298
304
  self.pattern = self.validator.get("pattern", self.pattern)
299
- super().set_validator(value)
300
305
 
301
306
  def odf_validate(self):
302
307
  func = []
@@ -1,11 +1,14 @@
1
1
  import yaml
2
2
  import os
3
3
  import re
4
+ import copy
4
5
  import hashlib
5
6
  from lbkit.log import Logger
6
7
  from lbkit.codegen.renderer import Renderer
7
8
  from lbkit.codegen.ctype_defination import CTYPE_OBJS, RefObjArrayValidator, RefObjValidator
8
9
  from lbkit.misc import load_yml_with_json_schema_validate
10
+ from lbkit.errors import OdfValidateException
11
+ from lbkit.helper import SigInvalidException, validate_glib_signature
9
12
 
10
13
  log = Logger("gen_interface")
11
14
 
@@ -130,6 +133,8 @@ class IdfCtypeRender():
130
133
  intf: IdfInterfaceBase = None
131
134
  ctype: str = None
132
135
  name: str = ""
136
+ idf_data = None
137
+ default = None
133
138
  flags: list[str] = []
134
139
 
135
140
  def __init__(self):
@@ -144,19 +149,26 @@ class IdfCtypeRender():
144
149
  if "variant" == self.ctype:
145
150
  return []
146
151
  match = re.match(f"^array\[({CTYPE_BASE_REG})\]$", self.ctype)
152
+ validator_cfg = self.validator_cfg
147
153
  if match:
148
154
  if "refobj" in self.flags:
149
155
  valiator = RefObjArrayValidator()
150
156
  return valiator.odf_validate()
151
- ctype_obj = CTYPE_OBJS.get(self.ctype)
152
- return ctype_obj.validator.odf_validate()
157
+ ctype_obj = copy.deepcopy(CTYPE_OBJS.get(self.ctype))
158
+ validator = ctype_obj.validator
159
+ if validator_cfg:
160
+ validator.set_validator(validator_cfg, self.name)
161
+ return validator.odf_validate()
153
162
  match = re.match(f"^({CTYPE_BASE_REG})$", self.ctype)
154
163
  if match:
155
164
  if "refobj" in self.flags:
156
165
  valiator = RefObjValidator()
157
166
  return valiator.odf_validate()
158
- ctype_obj = CTYPE_OBJS.get(self.ctype)
159
- return ctype_obj.validator.odf_validate()
167
+ ctype_obj = copy.deepcopy(CTYPE_OBJS.get(self.ctype))
168
+ validator = ctype_obj.validator
169
+ if validator_cfg:
170
+ validator.set_validator(validator_cfg, self.name)
171
+ return validator.odf_validate()
160
172
  # 非基础类型
161
173
  is_array = False
162
174
  ctype = self.ctype
@@ -176,20 +188,27 @@ class IdfCtypeRender():
176
188
  log.debug(f"Get odf schema info, name: {self.name}, ctype: {self.ctype}")
177
189
  if "variant" == self.ctype:
178
190
  return None
191
+ validator_cfg = self.validator_cfg
179
192
  match = re.match(f"^array\[({CTYPE_BASE_REG})\]$", self.ctype)
180
193
  if match:
181
194
  if "refobj" in self.flags:
182
195
  valiator = RefObjArrayValidator()
183
196
  return valiator.odf_schema(allow_ref)
184
- ctype_obj = CTYPE_OBJS.get(self.ctype)
185
- return ctype_obj.validator.odf_schema(allow_ref)
197
+ ctype_obj = copy.deepcopy(CTYPE_OBJS.get(self.ctype))
198
+ validator = ctype_obj.validator
199
+ if validator_cfg:
200
+ validator.set_validator(validator_cfg, self.name)
201
+ return validator.odf_schema(allow_ref)
186
202
  match = re.match(f"^({CTYPE_BASE_REG})$", self.ctype)
187
203
  if match:
188
204
  if "refobj" in self.flags:
189
205
  valiator = RefObjValidator()
190
206
  return valiator.odf_schema(allow_ref)
191
207
  ctype_obj = CTYPE_OBJS.get(self.ctype)
192
- return ctype_obj.validator.odf_schema(allow_ref)
208
+ validator = ctype_obj.validator
209
+ if validator_cfg:
210
+ validator.set_validator(validator_cfg, self.name)
211
+ return validator.odf_schema(allow_ref)
193
212
  # 非基础类型
194
213
  is_array = False
195
214
  ctype = self.ctype
@@ -500,9 +519,50 @@ class IdfCtypeRender():
500
519
  else:
501
520
  return f"<arg_name> = _load_odf_as_{stru_name}(doc, <node>)"
502
521
 
522
+ @property
523
+ def validator_cfg(self):
524
+ cfg = {}
525
+ if (self.ctype == "string" or self.ctype == "array[string]" or
526
+ self.ctype == "object_path" or self.ctype == "array[object_path]" or
527
+ self.ctype == "signature" or self.ctype == "array[signature]"):
528
+ value = self.idf_data.get("pattern")
529
+ if value:
530
+ cfg["pattern"] = value
531
+ elif self.ctype in ["byte", "array[byte]", "int16", "array[int16]",
532
+ "uint16", "array[uint16]", "int32", "array[int32]",
533
+ "uint32", "array[uint32]","int64", "array[int64]",
534
+ "uint64", "array[uint64]", "size", "array[size]",
535
+ "ssize", "array[ssize]"]:
536
+ value = self.idf_data.get("max")
537
+ if value:
538
+ cfg["max"] = value
539
+ value = self.idf_data.get("min")
540
+ if value:
541
+ cfg["min"] = value
542
+ if self.ctype == "double" or self.ctype == "array[double]":
543
+ emin = self.idf_data.get("exclusive_min")
544
+ if emin:
545
+ cfg["exclusive_min"] = emin
546
+ emax = self.idf_data.get("exclusive_max")
547
+ if emax:
548
+ cfg["exclusive_max"] = emax
549
+ mmin = self.idf_data.get("min")
550
+ if mmin:
551
+ cfg["min"] = mmin
552
+ mmax = self.idf_data.get("max")
553
+ if mmax:
554
+ cfg["max"] = mmax
555
+ if mmax is not None and emax is not None:
556
+ raise OdfValidateException(f"Cannot set max and exclusive_max at the same time, property {self.name} validation failed")
557
+ if mmin is not None and emin is not None:
558
+ raise OdfValidateException(f"Cannot set min and exclusive_min at the same time, property {self.name} validation failed")
559
+ return cfg
560
+
561
+
503
562
  class IdfProperty(IdfCtypeRender):
504
563
  def __init__(self, intf: IdfInterfaceBase, prop_data):
505
564
  self.intf = intf
565
+ self.idf_data = prop_data
506
566
  self.ctype = prop_data.get("type", "")
507
567
  super().__init__()
508
568
  self.name = prop_data.get("name")
@@ -543,13 +603,136 @@ class IdfProperty(IdfCtypeRender):
543
603
  else:
544
604
  self.desc_flags = " | ".join(c_flags)
545
605
 
606
+ self._load_default()
607
+
608
+ def _load_default(self):
609
+ # 只有基础类型有default值
610
+ match = re.match(f"^array\[({CTYPE_BASE_REG})\]$", self.ctype)
611
+ if not match:
612
+ match = re.match(f"^({CTYPE_BASE_REG})$", self.ctype)
613
+ if not match:
614
+ return
615
+ self.default = self.idf_data.get("default")
616
+ if self.default is None:
617
+ return
618
+
619
+ if self.ctype in ["boolean", "array[boolean]"]:
620
+ return
621
+ pattern = self.idf_data.get("pattern")
622
+ if pattern:
623
+ if self.ctype == "string":
624
+ match = re.match(pattern, self.default)
625
+ if not match:
626
+ raise OdfValidateException(f"Fail to validation default value of property {self.name} with pattern \"{pattern}\", get default: {self.default}")
627
+ return
628
+ if self.ctype == "array[string]":
629
+ for val in self.default:
630
+ match = re.match(pattern, val)
631
+ if not match:
632
+ raise OdfValidateException(f"Fail to validation default value of property {self.name} with pattern \"{pattern}\", get default: {val}")
633
+ return
634
+ if self.ctype == "object_path":
635
+ if pattern:
636
+ match = re.match(pattern, self.default)
637
+ if not match:
638
+ raise OdfValidateException(f"Fail to validation default value of property {self.name} with pattern \"{pattern}\", get default: {self.default}")
639
+ match = re.match(f"^(/[A-Z0-9a-z_]+)+$", self.default)
640
+ if not match:
641
+ raise OdfValidateException(f"Fail to validation default value of property {self.name} with pattern \"^(/[A-Z0-9a-z_]+)+$\", get default: {self.default}")
642
+ return
643
+ if self.ctype == "array[object_path]":
644
+ for val in self.default:
645
+ if pattern:
646
+ match = re.match(pattern, val)
647
+ if not match:
648
+ raise OdfValidateException(f"Fail to validation default value of property {self.name} with pattern \"{pattern}\", get default: {val}")
649
+ match = re.match(f"^(/[A-Z0-9a-z_]+)+$", val)
650
+ if not match:
651
+ raise OdfValidateException(f"Fail to validation default value of property {self.name} with pattern \"^(/[A-Z0-9a-z_]+)+$\", get default: {val}")
652
+ return
653
+
654
+ if self.ctype == "signature":
655
+ try:
656
+ validate_glib_signature(self.default)
657
+ if pattern:
658
+ match = re.match(pattern, self.default)
659
+ if not match:
660
+ raise OdfValidateException(f"Fail to validation default value of property {self.name} with pattern \"{pattern}\", get default: {self.default}")
661
+ except SigInvalidException:
662
+ raise OdfValidateException(f"Fail to validation default value of property {self.name}, get default: {self.default}")
663
+ return
664
+ if self.ctype == "array[oobject_path]":
665
+ try:
666
+ for val in self.default:
667
+ validate_glib_signature(val)
668
+ if pattern:
669
+ match = re.match(pattern, self.default)
670
+ if not match:
671
+ raise OdfValidateException(f"Fail to validation default value of property {self.name} with pattern \"{pattern}\", get default: {self.default}")
672
+ except SigInvalidException:
673
+ raise OdfValidateException(f"Fail to validation default value of property {self.name}, get default: {self.default}")
674
+ return
675
+
676
+ cfg = self.validator_cfg
677
+ if self.ctype in ["byte", "int16", "uint16", "int32", "uint32", "size", "ssize",
678
+ "int64", "uint64"]:
679
+ mmax = cfg.get("max")
680
+ if mmax is not None and mmax < self.default:
681
+ raise OdfValidateException(f"Fail to validation default value of property {self.name}, get default: {self.default}, max: {mmax}")
682
+ mmin = cfg.get("min")
683
+ if mmin is not None and mmin > self.default:
684
+ raise OdfValidateException(f"Fail to validation default value of property {self.name}, get default: {self.default}, min: {mmin}")
685
+ return
686
+ if self.ctype in ["array[byte]", "array[int16]", "array[uint16]", "array[int32]", "array[uint32]", "array[size]",
687
+ "array[ssize]", "array[int64]", "array[uint64]"]:
688
+ for val in self.default:
689
+ mmax = cfg.get("max")
690
+ if mmax is not None and mmax < val:
691
+ raise OdfValidateException(f"Fail to validation default value of property {self.name}, get default: {val}, max: {mmax}")
692
+ mmin = cfg.get("min")
693
+ if mmin is not None and mmin > val:
694
+ raise OdfValidateException(f"Fail to validation default value of property {self.name}, get default: {val}, min: {mmin}")
695
+ return
696
+
697
+ if self.ctype == "double":
698
+ emax = cfg.get("exclusive_max")
699
+ mmax = cfg.get("max")
700
+ if emax is not None and emax <= self.default:
701
+ raise OdfValidateException(f"Fail to validation default value of property {self.name}, get default: {self.default}, eclusive_max: {emax}")
702
+ if mmax is not None and mmax < self.default:
703
+ raise OdfValidateException(f"Fail to validation default value of property {self.name}, get default: {self.default}, max: {mmax}")
704
+ emin = cfg.get("exclusive_min")
705
+ mmin = cfg.get("min")
706
+ if emin is not None and emin >= self.default:
707
+ raise OdfValidateException(f"Fail to validation default value of property {self.name}, get default: {self.default}, exclusive_min: {emin}")
708
+ if mmin is not None and mmin > self.default:
709
+ raise OdfValidateException(f"Fail to validation default value of property {self.name}, get default: {self.default}, min: {emin}")
710
+ return
711
+ if self.ctype == "array[double]":
712
+ for val in self.default:
713
+ emax = cfg.get("exclusive_max")
714
+ mmax = cfg.get("max")
715
+ if emax is not None and emax <= val:
716
+ raise OdfValidateException(f"Fail to validation default value of property {self.name}, get default: {val}, eclusive_max: {emax}")
717
+ if mmax is not None and mmax < val:
718
+ raise OdfValidateException(f"Fail to validation default value of property {self.name}, get default: {val}, max: {mmax}")
719
+ emin = cfg.get("exclusive_min")
720
+ mmin = cfg.get("min")
721
+ if emin is not None and emin >= val:
722
+ raise OdfValidateException(f"Fail to validation default value of property {self.name}, get default: {val}, exclusive_min: {emin}")
723
+ if mmin is not None and mmin > val:
724
+ raise OdfValidateException(f"Fail to validation default value of property {self.name}, get default: {val}, min: {emin}")
725
+ return
726
+ raise OdfValidateException(f"Only basic type(byaqiuxtdsog) support default value, Property {self.name} type is {self.ctype}")
546
727
 
547
728
  @property
548
729
  def signature(self):
549
730
  return ctype_to_variant_signature(self.intf, self.ctype)
550
731
 
732
+
551
733
  class IdfParameter(IdfCtypeRender):
552
734
  def __init__(self, intf: IdfInterfaceBase, para_data):
735
+ self.idf_data = para_data
553
736
  self.intf = intf
554
737
  self.name = para_data.get("name")
555
738
  self.ctype = para_data.get("type", "")
@@ -764,8 +947,8 @@ class IdfDictionary():
764
947
 
765
948
  class IdfInterface(IdfInterfaceBase):
766
949
  def __init__(self, lookup, idf_file):
767
- if not idf_file.endswith(".yaml"):
768
- raise IDFException(f"IDF file {idf_file} not endswith .yaml")
950
+ if not idf_file.endswith(".yaml") and not idf_file.endswith(".yml"):
951
+ raise IDFException(f"IDF file {idf_file} neither endswith .yaml nor endswith .yml")
769
952
  super().__init__()
770
953
  self.lookup = lookup
771
954
  self.file = idf_file
@@ -865,7 +1048,7 @@ class IdfInterface(IdfInterfaceBase):
865
1048
  # 使用schema校验数据,确保IDF文件符合格式要求,减少程序处理过程中的异常处理
866
1049
  # 验证失败时抛异常,此处不用处理,由外层处理
867
1050
  idf = load_yml_with_json_schema_validate(self.file, "/usr/share/litebmc/schema/idf.v1.json")
868
- log.info(f"validate {self.file} successfully")
1051
+ log.debug(f"validate {self.file} successfully")
869
1052
  self.version = idf.get("version")
870
1053
  self.description = idf.get("description", "")
871
1054
  # 别名
@@ -919,19 +1102,17 @@ class IdfInterface(IdfInterfaceBase):
919
1102
  self.structures[self.alias] = intf_stru
920
1103
 
921
1104
  def render_dbus_xml(self, template, out_file):
922
- fd = open(out_file, "w")
923
1105
 
924
1106
  out = self.render(self.lookup, template, intf=self)
925
1107
  hash = hashlib.sha256()
926
1108
  hash.update(out.encode('utf-8'))
927
1109
  self.introspect_xml_sha256 = hash.hexdigest()
928
1110
  log.info("The sha256sum of interface {} is {}".format(out_file, self.introspect_xml_sha256))
929
- fd.write(out)
930
- fd.close()
1111
+ with open(out_file, "w") as fd:
1112
+ fd.write(out)
931
1113
 
932
1114
  def render_c_source(self, template, out_file):
933
- fd = open(out_file, "w")
934
1115
 
935
1116
  out = self.render(self.lookup, template, intf=self)
936
- fd.write(out)
937
- fd.close()
1117
+ with open(out_file, "w") as fd:
1118
+ fd.write(out)
@@ -6,21 +6,21 @@
6
6
  % for name, stru in intf.structures.items():
7
7
  /* ${name} structure object */
8
8
  /* START: 结构体${name}及其数组类型的ODF校验函数 */
9
- static gboolean _validate_odf_as_struct_${name}(yaml_document_t *doc, yaml_node_t *node, GString *prop, GSList **error_list);
10
- static gboolean _validate_odf_as_struct_${name}_v(yaml_document_t *doc, yaml_node_t *node, GString *prop, GSList **error_list);
9
+ static gboolean __attribute__((unused)) _validate_odf_as_struct_${name}(yaml_document_t *doc, yaml_node_t *node, GString *prop, GSList **error_list);
10
+ static gboolean __attribute__((unused)) _validate_odf_as_struct_${name}_v(yaml_document_t *doc, yaml_node_t *node, GString *prop, GSList **error_list);
11
11
 
12
12
  % endfor
13
13
  ## 定义枚举ODF加载函数
14
14
  % for name, enum in intf.enumerations.items():
15
15
  /* START: 枚举${name}及其数组类型的ODF校验函数 */
16
- static gboolean _validate_odf_as_enum_${name}(yaml_document_t *doc, yaml_node_t *node, GString *prop, GSList **error_list);
17
- static gboolean _validate_odf_as_enum_${name}_v(yaml_document_t *doc, yaml_node_t *node, GString *prop, GSList **error_list);
16
+ static gboolean __attribute__((unused)) _validate_odf_as_enum_${name}(yaml_document_t *doc, yaml_node_t *node, GString *prop, GSList **error_list);
17
+ static gboolean __attribute__((unused)) _validate_odf_as_enum_${name}_v(yaml_document_t *doc, yaml_node_t *node, GString *prop, GSList **error_list);
18
18
 
19
19
  % endfor
20
20
  ## 定义字典ODF加载函数
21
21
  % for name, dictionary in intf.dictionaries.items():
22
- static gboolean _validate_odf_as_dict_${name}(yaml_document_t *doc, yaml_node_t *node, GString *prop, GSList **error_list);
23
- static gboolean _validate_odf_as_dict_${name}_v(yaml_document_t *doc, yaml_node_t *node, GString *prop, GSList **error_list);
22
+ static gboolean __attribute__((unused)) _validate_odf_as_dict_${name}(yaml_document_t *doc, yaml_node_t *node, GString *prop, GSList **error_list);
23
+ static gboolean __attribute__((unused)) _validate_odf_as_dict_${name}_v(yaml_document_t *doc, yaml_node_t *node, GString *prop, GSList **error_list);
24
24
 
25
25
  % endfor
26
26
  % for name, stru in intf.structures.items():
@@ -36,7 +36,7 @@ GVariant *${name}_encode(const ${name} *value)
36
36
  value = &default_val;
37
37
  }
38
38
  % endif
39
- GVariant *tmp = NULL;
39
+ __attribute__((unused)) GVariant *tmp = NULL;
40
40
  GVariantBuilder builder;
41
41
  const gchar *sig = "${stru.signature}";
42
42
  g_variant_builder_init(&builder, G_VARIANT_TYPE(sig));
@@ -56,7 +56,7 @@ GVariant *${name}_encode(const ${name} *value)
56
56
  ${name} *${name}_decode(GVariant *in)
57
57
  {
58
58
  GVariantIter iter;
59
- GVariant *tmp = NULL;
59
+ __attribute__((unused)) GVariant *tmp = NULL;
60
60
  ${name} *output = g_new0(${name}, 1);
61
61
  if (!in) {
62
62
  return output;
@@ -161,9 +161,9 @@ gboolean _validate_odf_as_struct_${name}(yaml_document_t *doc, yaml_node_t *node
161
161
  "the node type of property %s is not a mapping, get %s", prop->str, gcl_yaml_node_type_str(node->type)));
162
162
  return FALSE;
163
163
  }
164
- gsize len = prop->len;
164
+ __attribute__((unused)) gsize len = prop->len;
165
165
  gboolean valid = TRUE;
166
- yaml_node_t *val;
166
+ __attribute__((unused)) yaml_node_t *val;
167
167
  GHashTable *prop_table = load_yaml_mapping_to_hash_table(doc, node);
168
168
  % for prop in stru.values.parameters:
169
169
  val = g_hash_table_lookup(prop_table, "${prop.name}");
@@ -282,7 +282,7 @@ ${name} *${name}_decode_v(GVariant *in, gsize *n)
282
282
  }
283
283
  ${name} *output = g_new0(${name}, *n);
284
284
  while (g_variant_iter_loop(&iter, "s", &str_val)) {
285
- for (int i = 0; i <= ${len(enum.values.parameters)}; i++) {
285
+ for (int i = 0; i < ${len(enum.values.parameters)}; i++) {
286
286
  if (g_strcmp0(str_val, _${name}StrMap[i]) == 0) {
287
287
  output[id++] = (${name})i;
288
288
  }
@@ -501,7 +501,7 @@ static void ${name}_foreach_encode(${key_declare}, ${name}${dictionary.key} *val
501
501
  g_assert(value && dict_builder);
502
502
  % endif
503
503
 
504
- GVariant *tmp = NULL;
504
+ __attribute__((unused)) GVariant *tmp = NULL;
505
505
  GVariantBuilder builder;
506
506
  % if len(dictionary.values.parameters) == 1:
507
507
  ## 当只有一个成员时直接添加值
@@ -563,7 +563,6 @@ ${name} *${name}_decode(GVariant *in)
563
563
  % if len(dictionary.values.parameters) > 1:
564
564
  GVariantIter item_iter;
565
565
  % endif
566
- GVariant *next_item = NULL;
567
566
  GVariant *next_mem = NULL;
568
567
 
569
568
  ${name} *dict = ${name}_new();
@@ -824,7 +823,7 @@ GVariant *${class_name}_${method.name}_Req_encode(${class_name}_${method.name}_R
824
823
  if (!value) {
825
824
  value = &default_val;
826
825
  }
827
- GVariant *tmp = NULL;
826
+ __attribute__((unused)) GVariant *tmp = NULL;
828
827
  GVariantBuilder builder;
829
828
  const gchar *sig = "${method.in_signature}";
830
829
  g_variant_builder_init(&builder, G_VARIANT_TYPE(sig));
@@ -842,7 +841,7 @@ GVariant *${class_name}_${method.name}_Req_encode(${class_name}_${method.name}_R
842
841
  ${class_name}_${method.name}_Req *${class_name}_${method.name}_Req_decode(GVariant *in)
843
842
  {
844
843
  GVariantIter iter;
845
- GVariant *tmp = NULL;
844
+ __attribute__((unused)) GVariant *tmp = NULL;
846
845
  ${class_name}_${method.name}_Req *output = g_new0(${class_name}_${method.name}_Req, 1);
847
846
  if (!in) {
848
847
  return output;
@@ -885,7 +884,7 @@ GVariant *${class_name}_${method.name}_Rsp_encode(${class_name}_${method.name}_R
885
884
  if (!value) {
886
885
  value = &default_val;
887
886
  }
888
- GVariant *tmp = NULL;
887
+ __attribute__((unused)) GVariant *tmp = NULL;
889
888
  GVariantBuilder builder;
890
889
  const gchar *sig = "${method.out_signature}";
891
890
  g_variant_builder_init(&builder, G_VARIANT_TYPE(sig));
@@ -903,7 +902,7 @@ GVariant *${class_name}_${method.name}_Rsp_encode(${class_name}_${method.name}_R
903
902
  ${class_name}_${method.name}_Rsp *${class_name}_${method.name}_Rsp_decode(GVariant *in)
904
903
  {
905
904
  GVariantIter iter;
906
- GVariant *tmp = NULL;
905
+ __attribute__((unused)) GVariant *tmp = NULL;
907
906
  ${class_name}_${method.name}_Rsp *output = g_new0(${class_name}_${method.name}_Rsp, 1);
908
907
  if (!in) {
909
908
  return output;
@@ -1077,7 +1076,7 @@ GVariant *${class_name}_${signal.name}_Msg_encode(${class_name}_${signal.name}_M
1077
1076
  if (!value) {
1078
1077
  value = &default_val;
1079
1078
  }
1080
- GVariant *tmp = NULL;
1079
+ __attribute__((unused)) GVariant *tmp = NULL;
1081
1080
  GVariantBuilder builder;
1082
1081
  const gchar *sig = "${signal.signature}";
1083
1082
  g_variant_builder_init(&builder, G_VARIANT_TYPE(sig));
@@ -1095,7 +1094,7 @@ GVariant *${class_name}_${signal.name}_Msg_encode(${class_name}_${signal.name}_M
1095
1094
  ${class_name}_${signal.name}_Msg *${class_name}_${signal.name}_Msg_decode(GVariant *in)
1096
1095
  {
1097
1096
  GVariantIter iter;
1098
- GVariant *tmp = NULL;
1097
+ __attribute__((unused)) GVariant *tmp = NULL;
1099
1098
  ${class_name}_${signal.name}_Msg *output = g_new0(${class_name}_${signal.name}_Msg, 1);
1100
1099
  if (!in) {
1101
1100
  return output;
@@ -1162,7 +1161,7 @@ static gboolean _validate_odf_prop_${prop.name}(yaml_document_t *doc, GHashTable
1162
1161
  if (!node) {
1163
1162
  ## 检查属性是否存在
1164
1163
  % if "required" in prop.flags:
1165
- *error_list = g_slist_append(*error_list, g_error_new(ODF_ERROR, ODF_ERROR_PROP_MISSING, "Property %s is missing", prop->str));
1164
+ *error_list = g_slist_append(*error_list, g_error_new(ODF_ERROR, ODF_ERROR_PROP_MISSING, "Property ${prop.name} is missing"));
1166
1165
  valid = FALSE;
1167
1166
  % endif
1168
1167
  break;