comparison CodeAnalysis/ParseOrthancSDK.py @ 131:c55b0583084b

integration fix-leak->mainline
author Sebastien Jodogne <s.jodogne@gmail.com>
date Wed, 30 Aug 2023 11:52:45 +0200
parents 65ec5597ec70 5643e97d9367
children 3e89d1c4f721
comparison
equal deleted inserted replaced
130:a3f77cf16396 131:c55b0583084b
507 escape = lambda u: u, # No escaping 507 escape = lambda u: u, # No escaping
508 partials = partials, 508 partials = partials,
509 ) 509 )
510 510
511 with open(os.path.join(ROOT, 'Class.mustache'), 'r') as f: 511 with open(os.path.join(ROOT, 'Class.mustache'), 'r') as f:
512 template = f.read() 512 with open(os.path.join(ROOT, 'ClassMethods.mustache'), 'r') as g:
513 513 classDefinition = f.read()
514 for method in CUSTOM_METHODS: 514 classMethods = g.read()
515 classes[method['class_name']]['custom_methods'].append(method) 515
516 516 for method in CUSTOM_METHODS:
517 for (key, value) in classes.items(): 517 classes[method['class_name']]['custom_methods'].append(method)
518 with open(os.path.join(TARGET, 'sdk_%s.impl.h' % value['class_name']), 'w') as h: 518
519 h.write(renderer.render(template, value)) 519 for (key, value) in classes.items():
520 with open(os.path.join(TARGET, 'sdk_%s.impl.h' % value['class_name']), 'w') as h:
521 h.write(renderer.render(classDefinition, value))
522 with open(os.path.join(TARGET, 'sdk_%s.methods.h' % value['class_name']), 'w') as h:
523 h.write(renderer.render(classMethods, value))
520 524
521 525
522 def FlattenDictionary(source): 526 def FlattenDictionary(source):
523 result = [] 527 result = []
524 for (key, value) in source.items(): 528 for (key, value) in source.items():
525 result.append(value) 529 result.append(value)
526 return result 530 return result
527 531
528 532
533 sortedClasses = sorted(FlattenDictionary(classes), key = lambda x: x['class_name'])
534 sortedEnumerations = sorted(FlattenDictionary(enumerations), key = lambda x: x['name'])
535 sortedGlobalFunctions = sorted(globalFunctions, key = lambda x: x['c_function'])
536
529 with open(os.path.join(ROOT, 'GlobalFunctions.mustache'), 'r') as f: 537 with open(os.path.join(ROOT, 'GlobalFunctions.mustache'), 'r') as f:
530 with open(os.path.join(TARGET, 'sdk_GlobalFunctions.impl.h'), 'w') as h: 538 with open(os.path.join(TARGET, 'sdk_GlobalFunctions.impl.h'), 'w') as h:
531 h.write(renderer.render(f.read(), { 539 h.write(renderer.render(f.read(), {
532 'global_functions' : globalFunctions, 540 'global_functions' : globalFunctions,
533 })) 541 }))
534 542
535 with open(os.path.join(ROOT, 'sdk.cpp.mustache'), 'r') as f: 543 with open(os.path.join(ROOT, 'sdk.cpp.mustache'), 'r') as f:
536 with open(os.path.join(TARGET, 'sdk.cpp'), 'w') as h: 544 with open(os.path.join(TARGET, 'sdk.cpp'), 'w') as h:
537 h.write(renderer.render(f.read(), { 545 h.write(renderer.render(f.read(), {
538 'classes' : FlattenDictionary(classes), 546 'classes' : sortedClasses,
539 'enumerations' : FlattenDictionary(enumerations), 547 'enumerations' : sortedEnumerations,
540 'global_functions' : globalFunctions, 548 'global_functions' : globalFunctions,
541 })) 549 }))
542 550
543 with open(os.path.join(ROOT, 'sdk.h.mustache'), 'r') as f: 551 with open(os.path.join(ROOT, 'sdk.h.mustache'), 'r') as f:
544 with open(os.path.join(TARGET, 'sdk.h'), 'w') as h: 552 with open(os.path.join(TARGET, 'sdk.h'), 'w') as h:
545 h.write(renderer.render(f.read(), { 553 h.write(renderer.render(f.read(), {
546 'classes' : FlattenDictionary(classes), 554 'classes' : sortedClasses,
547 })) 555 }))
548 556
549 557
550 print('') 558 print('')
551 print('Total functions in the SDK: %d' % countAllFunctions) 559 print('Total functions in the SDK: %d' % countAllFunctions)