Mercurial > hg > orthanc
comparison Resources/GenerateTransferSyntaxes.py @ 3730:ae31ba2b09a6
toolbox: LookupTransferSyntax()
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Mon, 09 Mar 2020 15:06:22 +0100 |
parents | 090022f1b5e1 |
children |
comparison
equal
deleted
inserted
replaced
3729:982c24a70dfd | 3730:ae31ba2b09a6 |
---|---|
33 | 33 |
34 import json | 34 import json |
35 import os | 35 import os |
36 import re | 36 import re |
37 import sys | 37 import sys |
38 import pystache | |
38 | 39 |
39 BASE = os.path.abspath(os.path.join(os.path.dirname(__file__), '..')) | 40 BASE = os.path.abspath(os.path.join(os.path.dirname(__file__), '..')) |
40 | 41 |
41 | 42 |
42 | 43 |
63 | 64 |
64 with open(path, 'w') as f: | 65 with open(path, 'w') as f: |
65 f.write(a) | 66 f.write(a) |
66 | 67 |
67 | 68 |
68 | 69 |
69 ## | 70 ## |
70 ## Generate the "GetTransferSyntaxUid()" function in | 71 ## Generate the implementations |
71 ## "Enumerations.cpp" | |
72 ## | 72 ## |
73 | 73 |
74 path = os.path.join(BASE, 'Core', 'Enumerations.cpp') | 74 with open(os.path.join(BASE, 'Core', 'Enumerations_TransferSyntaxes.impl.h'), 'w') as b: |
75 with open(path, 'r') as f: | 75 with open(os.path.join(BASE, 'Resources', 'GenerateTransferSyntaxesEnumerations.mustache'), 'r') as a: |
76 a = f.read() | 76 b.write(pystache.render(a.read(), { |
77 'Syntaxes' : SYNTAXES | |
78 })) | |
77 | 79 |
78 s = '\n\n'.join(map(lambda x: ' case DicomTransferSyntax_%s:\n return "%s";' % (x['Value'], x['UID']), SYNTAXES)) | 80 with open(os.path.join(BASE, 'Core', 'DicomParsing', 'FromDcmtkBridge_TransferSyntaxes.impl.h'), 'w') as b: |
79 a = re.sub('(GetTransferSyntaxUid\(DicomTransferSyntax.*?\)\s*{\s*switch \([^)]*?\)\s*{)[^}]*?(\s*default:)', | 81 with open(os.path.join(BASE, 'Resources', 'GenerateTransferSyntaxesDcmtk.mustache'), 'r') as a: |
80 r'\1\n%s\2' % s, a, re.DOTALL) | 82 b.write(pystache.render(a.read(), { |
81 | 83 'Syntaxes' : SYNTAXES |
82 with open(path, 'w') as f: | 84 })) |
83 f.write(a) | |
84 | |
85 | |
86 ## | |
87 ## Generate the "GetDcmtkTransferSyntax()" function in | |
88 ## "FromDcmtkBridge.cpp" | |
89 ## | |
90 | |
91 path = os.path.join(BASE, 'Core', 'DicomParsing', 'FromDcmtkBridge.cpp') | |
92 with open(path, 'r') as f: | |
93 a = f.read() | |
94 | |
95 def Format(x): | |
96 t = ' case DicomTransferSyntax_%s:\n target = %s;\n return true;' % (x['Value'], x['DCMTK']) | |
97 if 'SinceDCMTK' in x: | |
98 return '#if DCMTK_VERSION_NUMBER >= %s\n%s\n#endif' % (x['SinceDCMTK'], t) | |
99 else: | |
100 return t | |
101 | |
102 s = '\n\n'.join(map(Format, filter(lambda x: 'DCMTK' in x, SYNTAXES))) | |
103 a = re.sub('(GetDcmtkTransferSyntax\(E_TransferSyntax.*?\s*DicomTransferSyntax.*?\)\s*{\s*switch \([^)]*?\)\s*{)[^}]*?(\s*default:)', | |
104 r'\1\n%s\2' % s, a, re.DOTALL) | |
105 | |
106 with open(path, 'w') as f: | |
107 f.write(a) |