Mercurial > hg > orthanc
annotate OrthancFramework/Resources/CodeGeneration/GenerateTransferSyntaxes.py @ 4802:6a23cd1fc66b
fix news
author | Alain Mazy <am@osimis.io> |
---|---|
date | Tue, 19 Oct 2021 17:00:23 +0200 |
parents | 9c070a34de18 |
children | 7053502fbf97 |
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 |
4437
d9473bd5ed43
upgrade to year 2021
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4119
diff
changeset
|
6 # Copyright (C) 2017-2021 Osimis S.A., Belgium |
3727
090022f1b5e1
auto-generation of primitives to handle transfer syntaxes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
7 # |
090022f1b5e1
auto-generation of primitives to handle transfer syntaxes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
8 # 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
|
9 # 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
|
10 # 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
|
11 # 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
|
12 # |
090022f1b5e1
auto-generation of primitives to handle transfer syntaxes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
13 # 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
|
14 # 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
|
15 # 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
|
16 # 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
|
17 # |
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
|
18 # 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
|
19 # 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
|
20 # <http://www.gnu.org/licenses/>. |
3727
090022f1b5e1
auto-generation of primitives to handle transfer syntaxes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
21 |
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 import json |
090022f1b5e1
auto-generation of primitives to handle transfer syntaxes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
24 import os |
090022f1b5e1
auto-generation of primitives to handle transfer syntaxes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
25 import re |
090022f1b5e1
auto-generation of primitives to handle transfer syntaxes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
26 import sys |
3730
ae31ba2b09a6
toolbox: LookupTransferSyntax()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3727
diff
changeset
|
27 import pystache |
3727
090022f1b5e1
auto-generation of primitives to handle transfer syntaxes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
28 |
4468
9c070a34de18
IApplicationEntityFilter::GetAcceptedTransferSyntaxes()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
29 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
|
30 |
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 ## 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
|
34 ## 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
|
35 |
090022f1b5e1
auto-generation of primitives to handle transfer syntaxes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
36 |
4468
9c070a34de18
IApplicationEntityFilter::GetAcceptedTransferSyntaxes()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
37 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
|
38 SYNTAXES = json.loads(f.read()) |
090022f1b5e1
auto-generation of primitives to handle transfer syntaxes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
39 |
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 ## 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
|
44 ## |
090022f1b5e1
auto-generation of primitives to handle transfer syntaxes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
45 |
4468
9c070a34de18
IApplicationEntityFilter::GetAcceptedTransferSyntaxes()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
46 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
|
47 with open(path, 'r') as f: |
090022f1b5e1
auto-generation of primitives to handle transfer syntaxes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
48 a = f.read() |
090022f1b5e1
auto-generation of primitives to handle transfer syntaxes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
49 |
090022f1b5e1
auto-generation of primitives to handle transfer syntaxes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
50 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
|
51 |
090022f1b5e1
auto-generation of primitives to handle transfer syntaxes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
52 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
|
53 |
090022f1b5e1
auto-generation of primitives to handle transfer syntaxes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
54 with open(path, 'w') as f: |
090022f1b5e1
auto-generation of primitives to handle transfer syntaxes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
55 f.write(a) |
090022f1b5e1
auto-generation of primitives to handle transfer syntaxes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
56 |
090022f1b5e1
auto-generation of primitives to handle transfer syntaxes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
57 |
3730
ae31ba2b09a6
toolbox: LookupTransferSyntax()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3727
diff
changeset
|
58 |
3727
090022f1b5e1
auto-generation of primitives to handle transfer syntaxes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
59 ## |
3730
ae31ba2b09a6
toolbox: LookupTransferSyntax()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3727
diff
changeset
|
60 ## Generate the implementations |
3727
090022f1b5e1
auto-generation of primitives to handle transfer syntaxes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
61 ## |
090022f1b5e1
auto-generation of primitives to handle transfer syntaxes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
62 |
4468
9c070a34de18
IApplicationEntityFilter::GetAcceptedTransferSyntaxes()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
63 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
|
64 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
|
65 b.write(pystache.render(a.read(), { |
ae31ba2b09a6
toolbox: LookupTransferSyntax()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3727
diff
changeset
|
66 'Syntaxes' : SYNTAXES |
ae31ba2b09a6
toolbox: LookupTransferSyntax()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3727
diff
changeset
|
67 })) |
3727
090022f1b5e1
auto-generation of primitives to handle transfer syntaxes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
68 |
4468
9c070a34de18
IApplicationEntityFilter::GetAcceptedTransferSyntaxes()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
69 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
|
70 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
|
71 b.write(pystache.render(a.read(), { |
ae31ba2b09a6
toolbox: LookupTransferSyntax()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3727
diff
changeset
|
72 'Syntaxes' : SYNTAXES |
ae31ba2b09a6
toolbox: LookupTransferSyntax()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3727
diff
changeset
|
73 })) |