Mercurial > hg > orthanc-python
comparison CodeAnalysis/GenerateOrthancSDK.py @ 192:b0f096d2339e java-code-model
documentation of orthanc.RegisterRestCallback()
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Tue, 02 Jul 2024 18:25:53 +0200 |
parents | 0cb98433a382 |
children | 66cd20e970d8 |
comparison
equal
deleted
inserted
replaced
191:30ed49f2487f | 192:b0f096d2339e |
---|---|
170 arg_type = GetShortName(a['sdk_enumeration']) | 170 arg_type = GetShortName(a['sdk_enumeration']) |
171 elif a['sdk_type'] == 'const_object': | 171 elif a['sdk_type'] == 'const_object': |
172 arg_type = GetShortName(a['sdk_class']) | 172 arg_type = GetShortName(a['sdk_class']) |
173 elif a['sdk_type'] in [ 'int32_t', 'uint32_t', 'uint8_t', 'uint16_t', 'uint64_t' ]: | 173 elif a['sdk_type'] in [ 'int32_t', 'uint32_t', 'uint8_t', 'uint16_t', 'uint64_t' ]: |
174 arg_type = 'int' | 174 arg_type = 'int' |
175 elif a['sdk_type'] == 'Callable': | |
176 arg_type = a['callable_type'] | |
175 else: | 177 else: |
176 raise Exception('Argument type not implemented: %s' % a['sdk_type']) | 178 raise Exception('Argument type not implemented: %s' % a['sdk_type']) |
177 args_declaration.append('%s: %s' % (arg_name, arg_type)) | 179 args_declaration.append('%s: %s' % (arg_name, arg_type)) |
178 args_documentation.append({ | 180 args_documentation.append({ |
179 'name' : arg_name, | 181 'name' : arg_name, |
262 'name' : arg['name'], | 264 'name' : arg['name'], |
263 'python_type' : t['type'], | 265 'python_type' : t['type'], |
264 'initialization' : ' = 0', | 266 'initialization' : ' = 0', |
265 }) | 267 }) |
266 tuple_format += t['format'] | 268 tuple_format += t['format'] |
269 elif arg['sdk_type'] == 'Callable': | |
270 # This is only used to generate the documentation file "orthanc.pyi" | |
271 args.append({ | |
272 'name' : arg['name'], | |
273 }) | |
274 tuple_format += 'O' | |
267 else: | 275 else: |
268 print('Ignoring function with unsupported argument type: %s(), type = %s' % (f['c_function'], arg['sdk_type'])) | 276 print('Ignoring function with unsupported argument type: %s(), type = %s' % (f['c_function'], arg['sdk_type'])) |
269 return None | 277 return None |
270 | 278 |
271 tuple_target.append('&' + arg['name']) | 279 tuple_target.append('&' + arg['name']) |
317 return answer | 325 return answer |
318 | 326 |
319 | 327 |
320 | 328 |
321 globalFunctions = [] | 329 globalFunctions = [] |
330 customFunctions = [] | |
322 | 331 |
323 for f in model['global_functions']: | 332 for f in model['global_functions']: |
324 g = FormatFunction(f) | 333 g = FormatFunction(f) |
325 if g != None: | 334 if g != None: |
326 globalFunctions.append(g) | 335 globalFunctions.append(g) |
327 | 336 |
328 for f in CUSTOM_FUNCTIONS: | 337 for f in CUSTOM_FUNCTIONS: |
329 g = FormatFunction(f) | 338 f['documentation'] = DocumentFunction(f) |
330 if g != None: | 339 customFunctions.append(f) |
331 globalFunctions.append(g) | |
332 | 340 |
333 | 341 |
334 enumerations = [] | 342 enumerations = [] |
335 | 343 |
336 with open(os.path.join(ROOT, 'Enumeration.mustache'), 'r') as f: | 344 with open(os.path.join(ROOT, 'Enumeration.mustache'), 'r') as f: |
408 | 416 |
409 | 417 |
410 sortedClasses = sorted(classes, key = lambda x: x['class_name']) | 418 sortedClasses = sorted(classes, key = lambda x: x['class_name']) |
411 sortedEnumerations = sorted(enumerations, key = lambda x: x['name']) | 419 sortedEnumerations = sorted(enumerations, key = lambda x: x['name']) |
412 sortedGlobalFunctions = sorted(globalFunctions, key = lambda x: x['c_function']) | 420 sortedGlobalFunctions = sorted(globalFunctions, key = lambda x: x['c_function']) |
421 sortedCustomFunctions = sorted(customFunctions, key = lambda x: x['short_name']) | |
413 | 422 |
414 with open(os.path.join(ROOT, 'GlobalFunctions.mustache'), 'r') as f: | 423 with open(os.path.join(ROOT, 'GlobalFunctions.mustache'), 'r') as f: |
415 with open(os.path.join(TARGET, 'sdk_GlobalFunctions.impl.h'), 'w') as h: | 424 with open(os.path.join(TARGET, 'sdk_GlobalFunctions.impl.h'), 'w') as h: |
416 h.write(renderer.render(f.read(), { | 425 h.write(renderer.render(f.read(), { |
417 'global_functions' : sortedGlobalFunctions, | 426 'global_functions' : sortedGlobalFunctions, |
427 'custom_functions' : sortedCustomFunctions, | |
418 })) | 428 })) |
419 | 429 |
420 with open(os.path.join(ROOT, 'sdk.cpp.mustache'), 'r') as f: | 430 with open(os.path.join(ROOT, 'sdk.cpp.mustache'), 'r') as f: |
421 with open(os.path.join(TARGET, 'sdk.cpp'), 'w') as h: | 431 with open(os.path.join(TARGET, 'sdk.cpp'), 'w') as h: |
422 h.write(renderer.render(f.read(), { | 432 h.write(renderer.render(f.read(), { |
423 'classes' : sortedClasses, | 433 'classes' : sortedClasses, |
424 'enumerations' : sortedEnumerations, | 434 'enumerations' : sortedEnumerations, |
425 'global_functions' : sortedGlobalFunctions, | 435 'global_functions' : sortedGlobalFunctions, |
436 'custom_functions' : sortedCustomFunctions, | |
426 })) | 437 })) |
427 | 438 |
428 with open(os.path.join(ROOT, 'sdk.h.mustache'), 'r') as f: | 439 with open(os.path.join(ROOT, 'sdk.h.mustache'), 'r') as f: |
429 with open(os.path.join(TARGET, 'sdk.h'), 'w') as h: | 440 with open(os.path.join(TARGET, 'sdk.h'), 'w') as h: |
430 h.write(renderer.render(f.read(), { | 441 h.write(renderer.render(f.read(), { |
435 with open(os.path.join(TARGET, 'orthanc.pyi'), 'w') as h: | 446 with open(os.path.join(TARGET, 'orthanc.pyi'), 'w') as h: |
436 h.write(renderer.render(f.read(), { | 447 h.write(renderer.render(f.read(), { |
437 'classes' : sortedClasses, | 448 'classes' : sortedClasses, |
438 'enumerations' : sortedEnumerations, | 449 'enumerations' : sortedEnumerations, |
439 'global_functions' : sortedGlobalFunctions, | 450 'global_functions' : sortedGlobalFunctions, |
451 'custom_functions' : sortedCustomFunctions, | |
440 })) | 452 })) |
441 | 453 |
442 | 454 |
443 countMethods = 0 | 455 countMethods = 0 |
444 for c in sortedClasses: | 456 for c in sortedClasses: |
445 countMethods += len(c['methods']) | 457 countMethods += len(c['methods']) |
446 | 458 |
447 print('\nNumber of wrapped global functions: %d' % len(sortedGlobalFunctions)) | 459 print('\nNumber of wrapped global functions: %d' % len(sortedGlobalFunctions + sortedCustomFunctions)) |
448 print('Number of wrapped methods: %d\n' % countMethods) | 460 print('Number of wrapped methods: %d\n' % countMethods) |
449 print('Total number of wrapped global functions or methods: %d\n' % (len(sortedGlobalFunctions) + countMethods)) | 461 print('Total number of wrapped global functions or methods: %d\n' % (len(sortedGlobalFunctions + sortedCustomFunctions) + countMethods)) |