annotate OrthancFramework/Resources/CodeGeneration/GenerateTransferSyntaxes.py @ 4984:c8cdf5163cd2

cppcheck
author Alain Mazy <am@osimis.io>
date Mon, 25 Apr 2022 18:54:45 +0200
parents 43e613a7756b
children 0ea402b4d901
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
3727
090022f1b5e1 auto-generation of primitives to handle transfer syntaxes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1 #!/usr/bin/python
090022f1b5e1 auto-generation of primitives to handle transfer syntaxes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2
090022f1b5e1 auto-generation of primitives to handle transfer syntaxes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3 # Orthanc - A Lightweight, RESTful DICOM Store
090022f1b5e1 auto-generation of primitives to handle transfer syntaxes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
4 # Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
090022f1b5e1 auto-generation of primitives to handle transfer syntaxes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
5 # Department, University Hospital of Liege, Belgium
4870
43e613a7756b upgrade to year 2022
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4831
diff changeset
6 # Copyright (C) 2017-2022 Osimis S.A., Belgium
43e613a7756b upgrade to year 2022
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4831
diff changeset
7 # Copyright (C) 2021-2022 Sebastien Jodogne, ICTEAM UCLouvain, Belgium
3727
090022f1b5e1 auto-generation of primitives to handle transfer syntaxes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
8 #
090022f1b5e1 auto-generation of primitives to handle transfer syntaxes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
9 # This program is free software: you can redistribute it and/or
4119
bf7b9edf6b81 re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4044
diff changeset
10 # modify it under the terms of the GNU Lesser General Public License
bf7b9edf6b81 re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4044
diff changeset
11 # as published by the Free Software Foundation, either version 3 of
bf7b9edf6b81 re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4044
diff changeset
12 # the License, or (at your option) any later version.
3727
090022f1b5e1 auto-generation of primitives to handle transfer syntaxes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
13 #
090022f1b5e1 auto-generation of primitives to handle transfer syntaxes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
14 # This program is distributed in the hope that it will be useful, but
090022f1b5e1 auto-generation of primitives to handle transfer syntaxes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
15 # WITHOUT ANY WARRANTY; without even the implied warranty of
090022f1b5e1 auto-generation of primitives to handle transfer syntaxes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
16 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
4119
bf7b9edf6b81 re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4044
diff changeset
17 # Lesser General Public License for more details.
3727
090022f1b5e1 auto-generation of primitives to handle transfer syntaxes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
18 #
4119
bf7b9edf6b81 re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4044
diff changeset
19 # You should have received a copy of the GNU Lesser General Public
bf7b9edf6b81 re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4044
diff changeset
20 # License along with this program. If not, see
bf7b9edf6b81 re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4044
diff changeset
21 # <http://www.gnu.org/licenses/>.
3727
090022f1b5e1 auto-generation of primitives to handle transfer syntaxes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
22
090022f1b5e1 auto-generation of primitives to handle transfer syntaxes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
23
090022f1b5e1 auto-generation of primitives to handle transfer syntaxes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
24 import json
090022f1b5e1 auto-generation of primitives to handle transfer syntaxes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
25 import os
090022f1b5e1 auto-generation of primitives to handle transfer syntaxes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
26 import re
090022f1b5e1 auto-generation of primitives to handle transfer syntaxes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
27 import sys
3730
ae31ba2b09a6 toolbox: LookupTransferSyntax()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3727
diff changeset
28 import pystache
3727
090022f1b5e1 auto-generation of primitives to handle transfer syntaxes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
29
4468
9c070a34de18 IApplicationEntityFilter::GetAcceptedTransferSyntaxes()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
30 BASE = os.path.abspath(os.path.join(os.path.dirname(__file__), '..', '..'))
3727
090022f1b5e1 auto-generation of primitives to handle transfer syntaxes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
31
090022f1b5e1 auto-generation of primitives to handle transfer syntaxes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
32
090022f1b5e1 auto-generation of primitives to handle transfer syntaxes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
33
090022f1b5e1 auto-generation of primitives to handle transfer syntaxes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
34 ## https://www.dicomlibrary.com/dicom/transfer-syntax/
090022f1b5e1 auto-generation of primitives to handle transfer syntaxes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
35 ## https://cedocs.intersystems.com/latest/csp/docbook/DocBook.UI.Page.cls?KEY=EDICOM_transfer_syntax
090022f1b5e1 auto-generation of primitives to handle transfer syntaxes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
36
090022f1b5e1 auto-generation of primitives to handle transfer syntaxes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
37
4468
9c070a34de18 IApplicationEntityFilter::GetAcceptedTransferSyntaxes()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
38 with open(os.path.join(BASE, 'Resources', 'CodeGeneration', 'DicomTransferSyntaxes.json'), 'r') as f:
3727
090022f1b5e1 auto-generation of primitives to handle transfer syntaxes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
39 SYNTAXES = json.loads(f.read())
090022f1b5e1 auto-generation of primitives to handle transfer syntaxes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
40
090022f1b5e1 auto-generation of primitives to handle transfer syntaxes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
41
090022f1b5e1 auto-generation of primitives to handle transfer syntaxes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
42
090022f1b5e1 auto-generation of primitives to handle transfer syntaxes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
43 ##
090022f1b5e1 auto-generation of primitives to handle transfer syntaxes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
44 ## Generate the "DicomTransferSyntax" enumeration in "Enumerations.h"
090022f1b5e1 auto-generation of primitives to handle transfer syntaxes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
45 ##
090022f1b5e1 auto-generation of primitives to handle transfer syntaxes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
46
4468
9c070a34de18 IApplicationEntityFilter::GetAcceptedTransferSyntaxes()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
47 path = os.path.join(BASE, 'Sources', 'Enumerations.h')
3727
090022f1b5e1 auto-generation of primitives to handle transfer syntaxes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
48 with open(path, 'r') as f:
090022f1b5e1 auto-generation of primitives to handle transfer syntaxes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
49 a = f.read()
090022f1b5e1 auto-generation of primitives to handle transfer syntaxes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
50
090022f1b5e1 auto-generation of primitives to handle transfer syntaxes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
51 s = ',\n'.join(map(lambda x: ' DicomTransferSyntax_%s /*!< %s */' % (x['Value'], x['Name']), SYNTAXES))
090022f1b5e1 auto-generation of primitives to handle transfer syntaxes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
52
090022f1b5e1 auto-generation of primitives to handle transfer syntaxes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
53 a = re.sub('(enum DicomTransferSyntax\s*{)[^}]*?(\s*};)', r'\1\n%s\2' % s, a, re.DOTALL)
090022f1b5e1 auto-generation of primitives to handle transfer syntaxes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
54
090022f1b5e1 auto-generation of primitives to handle transfer syntaxes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
55 with open(path, 'w') as f:
090022f1b5e1 auto-generation of primitives to handle transfer syntaxes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
56 f.write(a)
090022f1b5e1 auto-generation of primitives to handle transfer syntaxes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
57
090022f1b5e1 auto-generation of primitives to handle transfer syntaxes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
58
3730
ae31ba2b09a6 toolbox: LookupTransferSyntax()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3727
diff changeset
59
3727
090022f1b5e1 auto-generation of primitives to handle transfer syntaxes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
60 ##
3730
ae31ba2b09a6 toolbox: LookupTransferSyntax()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3727
diff changeset
61 ## Generate the implementations
3727
090022f1b5e1 auto-generation of primitives to handle transfer syntaxes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
62 ##
090022f1b5e1 auto-generation of primitives to handle transfer syntaxes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
63
4468
9c070a34de18 IApplicationEntityFilter::GetAcceptedTransferSyntaxes()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
64 with open(os.path.join(BASE, 'Sources', 'Enumerations_TransferSyntaxes.impl.h'), 'w') as b:
9c070a34de18 IApplicationEntityFilter::GetAcceptedTransferSyntaxes()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
65 with open(os.path.join(BASE, 'Resources', 'CodeGeneration', 'GenerateTransferSyntaxesEnumerations.mustache'), 'r') as a:
3730
ae31ba2b09a6 toolbox: LookupTransferSyntax()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3727
diff changeset
66 b.write(pystache.render(a.read(), {
ae31ba2b09a6 toolbox: LookupTransferSyntax()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3727
diff changeset
67 'Syntaxes' : SYNTAXES
ae31ba2b09a6 toolbox: LookupTransferSyntax()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3727
diff changeset
68 }))
3727
090022f1b5e1 auto-generation of primitives to handle transfer syntaxes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
69
4468
9c070a34de18 IApplicationEntityFilter::GetAcceptedTransferSyntaxes()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
70 with open(os.path.join(BASE, 'Sources', 'DicomParsing', 'FromDcmtkBridge_TransferSyntaxes.impl.h'), 'w') as b:
9c070a34de18 IApplicationEntityFilter::GetAcceptedTransferSyntaxes()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
71 with open(os.path.join(BASE, 'Resources', 'CodeGeneration', 'GenerateTransferSyntaxesDcmtk.mustache'), 'r') as a:
3730
ae31ba2b09a6 toolbox: LookupTransferSyntax()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3727
diff changeset
72 b.write(pystache.render(a.read(), {
ae31ba2b09a6 toolbox: LookupTransferSyntax()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3727
diff changeset
73 'Syntaxes' : SYNTAXES
ae31ba2b09a6 toolbox: LookupTransferSyntax()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3727
diff changeset
74 }))