comparison Resources/GenerateTransferSyntaxes.py @ 3731:e7ff4f9b34bd storage-commitment

integration mainline->storage-commitment
author Sebastien Jodogne <s.jodogne@gmail.com>
date Mon, 09 Mar 2020 17:19:45 +0100
parents ae31ba2b09a6
children
comparison
equal deleted inserted replaced
3718:922c56b76edc 3731:e7ff4f9b34bd
1 #!/usr/bin/python
2
3 # Orthanc - A Lightweight, RESTful DICOM Store
4 # Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
5 # Department, University Hospital of Liege, Belgium
6 # Copyright (C) 2017-2020 Osimis S.A., Belgium
7 #
8 # This program is free software: you can redistribute it and/or
9 # modify it under the terms of the GNU General Public License as
10 # published by the Free Software Foundation, either version 3 of the
11 # License, or (at your option) any later version.
12 #
13 # In addition, as a special exception, the copyright holders of this
14 # program give permission to link the code of its release with the
15 # OpenSSL project's "OpenSSL" library (or with modified versions of it
16 # that use the same license as the "OpenSSL" library), and distribute
17 # the linked executables. You must obey the GNU General Public License
18 # in all respects for all of the code used other than "OpenSSL". If you
19 # modify file(s) with this exception, you may extend this exception to
20 # your version of the file(s), but you are not obligated to do so. If
21 # you do not wish to do so, delete this exception statement from your
22 # version. If you delete this exception statement from all source files
23 # in the program, then also delete it here.
24 #
25 # This program is distributed in the hope that it will be useful, but
26 # WITHOUT ANY WARRANTY; without even the implied warranty of
27 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
28 # General Public License for more details.
29 #
30 # You should have received a copy of the GNU General Public License
31 # along with this program. If not, see <http://www.gnu.org/licenses/>.
32
33
34 import json
35 import os
36 import re
37 import sys
38 import pystache
39
40 BASE = os.path.abspath(os.path.join(os.path.dirname(__file__), '..'))
41
42
43
44 ## https://www.dicomlibrary.com/dicom/transfer-syntax/
45 ## https://cedocs.intersystems.com/latest/csp/docbook/DocBook.UI.Page.cls?KEY=EDICOM_transfer_syntax
46
47
48 with open(os.path.join(BASE, 'Resources', 'DicomTransferSyntaxes.json'), 'r') as f:
49 SYNTAXES = json.loads(f.read())
50
51
52
53 ##
54 ## Generate the "DicomTransferSyntax" enumeration in "Enumerations.h"
55 ##
56
57 path = os.path.join(BASE, 'Core', 'Enumerations.h')
58 with open(path, 'r') as f:
59 a = f.read()
60
61 s = ',\n'.join(map(lambda x: ' DicomTransferSyntax_%s /*!< %s */' % (x['Value'], x['Name']), SYNTAXES))
62
63 a = re.sub('(enum DicomTransferSyntax\s*{)[^}]*?(\s*};)', r'\1\n%s\2' % s, a, re.DOTALL)
64
65 with open(path, 'w') as f:
66 f.write(a)
67
68
69
70 ##
71 ## Generate the implementations
72 ##
73
74 with open(os.path.join(BASE, 'Core', 'Enumerations_TransferSyntaxes.impl.h'), 'w') as b:
75 with open(os.path.join(BASE, 'Resources', 'GenerateTransferSyntaxesEnumerations.mustache'), 'r') as a:
76 b.write(pystache.render(a.read(), {
77 'Syntaxes' : SYNTAXES
78 }))
79
80 with open(os.path.join(BASE, 'Core', 'DicomParsing', 'FromDcmtkBridge_TransferSyntaxes.impl.h'), 'w') as b:
81 with open(os.path.join(BASE, 'Resources', 'GenerateTransferSyntaxesDcmtk.mustache'), 'r') as a:
82 b.write(pystache.render(a.read(), {
83 'Syntaxes' : SYNTAXES
84 }))