annotate OrthancFramework/Resources/CodeGeneration/GenerateErrorCodes.py @ 4864:09d06d99745c openssl-3.x

integration mainline->openssl-3.x
author Sebastien Jodogne <s.jodogne@gmail.com>
date Fri, 24 Dec 2021 17:18:06 +0100
parents 7053502fbf97
children 43e613a7756b
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1576
de54c19fc44d refactoring OrthancException
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1 #!/usr/bin/python
de54c19fc44d refactoring OrthancException
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2
de54c19fc44d refactoring OrthancException
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3 # Orthanc - A Lightweight, RESTful DICOM Store
1900
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1734
diff changeset
4 # Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
1576
de54c19fc44d refactoring OrthancException
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
4831
7053502fbf97 added copyright UCLouvain
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
7 # Copyright (C) 2021-2021 Sebastien Jodogne, ICTEAM UCLouvain, Belgium
1576
de54c19fc44d refactoring OrthancException
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
8 #
de54c19fc44d refactoring OrthancException
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: 4047
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: 4047
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: 4047
diff changeset
12 # the License, or (at your option) any later version.
1576
de54c19fc44d refactoring OrthancException
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
13 #
de54c19fc44d refactoring OrthancException
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
14 # This program is distributed in the hope that it will be useful, but
de54c19fc44d refactoring OrthancException
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
15 # WITHOUT ANY WARRANTY; without even the implied warranty of
de54c19fc44d refactoring OrthancException
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: 4047
diff changeset
17 # Lesser General Public License for more details.
1576
de54c19fc44d refactoring OrthancException
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: 4047
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: 4047
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: 4047
diff changeset
21 # <http://www.gnu.org/licenses/>.
1576
de54c19fc44d refactoring OrthancException
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
22
de54c19fc44d refactoring OrthancException
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
23
de54c19fc44d refactoring OrthancException
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
24 import json
de54c19fc44d refactoring OrthancException
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
25 import os
de54c19fc44d refactoring OrthancException
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
26 import re
1644
939b921b2c81 plugin error dictionary
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1626
diff changeset
27 import sys
1576
de54c19fc44d refactoring OrthancException
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
28
1644
939b921b2c81 plugin error dictionary
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1626
diff changeset
29 START_PLUGINS = 1000000
4047
0327421506ad fix paths in GenerateErrorCodes.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4044
diff changeset
30 BASE = os.path.abspath(os.path.join(os.path.dirname(__file__), '..', '..', '..'))
1576
de54c19fc44d refactoring OrthancException
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
31
de54c19fc44d refactoring OrthancException
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
32
1577
7aac0cddd42e generation of the error codes from a Python script
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1576
diff changeset
33
1576
de54c19fc44d refactoring OrthancException
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
34 ##
1577
7aac0cddd42e generation of the error codes from a Python script
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1576
diff changeset
35 ## Read all the available error codes and HTTP status
1576
de54c19fc44d refactoring OrthancException
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
36 ##
de54c19fc44d refactoring OrthancException
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
37
4047
0327421506ad fix paths in GenerateErrorCodes.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4044
diff changeset
38 with open(os.path.join(BASE, 'OrthancFramework', 'Resources', 'CodeGeneration', 'ErrorCodes.json'), 'r') as f:
1582
bd1889029cbb encoding of exceptions
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1580
diff changeset
39 ERRORS = json.loads(re.sub('/\*.*?\*/', '', f.read()))
1576
de54c19fc44d refactoring OrthancException
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
40
1644
939b921b2c81 plugin error dictionary
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1626
diff changeset
41 for error in ERRORS:
939b921b2c81 plugin error dictionary
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1626
diff changeset
42 if error['Code'] >= START_PLUGINS:
939b921b2c81 plugin error dictionary
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1626
diff changeset
43 print('ERROR: Error code must be below %d, but "%s" is set to %d' % (START_PLUGINS, error['Name'], error['Code']))
939b921b2c81 plugin error dictionary
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1626
diff changeset
44 sys.exit(-1)
939b921b2c81 plugin error dictionary
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1626
diff changeset
45
4047
0327421506ad fix paths in GenerateErrorCodes.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4044
diff changeset
46 with open(os.path.join(BASE, 'OrthancFramework', 'Sources', 'Enumerations.h'), 'r') as f:
1577
7aac0cddd42e generation of the error codes from a Python script
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1576
diff changeset
47 a = f.read()
7aac0cddd42e generation of the error codes from a Python script
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1576
diff changeset
48
7aac0cddd42e generation of the error codes from a Python script
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1576
diff changeset
49 HTTP = {}
7aac0cddd42e generation of the error codes from a Python script
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1576
diff changeset
50 for i in re.findall('(HttpStatus_([0-9]+)_\w+)', a):
7aac0cddd42e generation of the error codes from a Python script
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1576
diff changeset
51 HTTP[int(i[1])] = i[0]
7aac0cddd42e generation of the error codes from a Python script
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1576
diff changeset
52
7aac0cddd42e generation of the error codes from a Python script
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1576
diff changeset
53
1576
de54c19fc44d refactoring OrthancException
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
54
de54c19fc44d refactoring OrthancException
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
55 ##
1578
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1577
diff changeset
56 ## Generate the "ErrorCode" enumeration in "Enumerations.h"
1576
de54c19fc44d refactoring OrthancException
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
57 ##
de54c19fc44d refactoring OrthancException
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
58
4047
0327421506ad fix paths in GenerateErrorCodes.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4044
diff changeset
59 path = os.path.join(BASE, 'OrthancFramework', 'Sources', 'Enumerations.h')
1578
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1577
diff changeset
60 with open(path, 'r') as f:
1576
de54c19fc44d refactoring OrthancException
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
61 a = f.read()
de54c19fc44d refactoring OrthancException
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
62
1578
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1577
diff changeset
63 s = ',\n'.join(map(lambda x: ' ErrorCode_%s = %d /*!< %s */' % (x['Name'], int(x['Code']), x['Description']), ERRORS))
1644
939b921b2c81 plugin error dictionary
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1626
diff changeset
64
939b921b2c81 plugin error dictionary
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1626
diff changeset
65 s += ',\n ErrorCode_START_PLUGINS = %d' % START_PLUGINS
1576
de54c19fc44d refactoring OrthancException
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
66 a = re.sub('(enum ErrorCode\s*{)[^}]*?(\s*};)', r'\1\n%s\2' % s, a, re.DOTALL)
de54c19fc44d refactoring OrthancException
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
67
1578
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1577
diff changeset
68 with open(path, 'w') as f:
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1577
diff changeset
69 f.write(a)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1577
diff changeset
70
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1577
diff changeset
71
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1577
diff changeset
72
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1577
diff changeset
73 ##
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1577
diff changeset
74 ## Generate the "OrthancPluginErrorCode" enumeration in "OrthancCPlugin.h"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1577
diff changeset
75 ##
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1577
diff changeset
76
4047
0327421506ad fix paths in GenerateErrorCodes.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4044
diff changeset
77 path = os.path.join(BASE, 'OrthancServer', 'Plugins', 'Include', 'orthanc', 'OrthancCPlugin.h')
1578
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1577
diff changeset
78 with open(path, 'r') as f:
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1577
diff changeset
79 a = f.read()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1577
diff changeset
80
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1577
diff changeset
81 s = ',\n'.join(map(lambda x: ' OrthancPluginErrorCode_%s = %d /*!< %s */' % (x['Name'], int(x['Code']), x['Description']), ERRORS))
1580
bf502300c52e force the size of the enumerations in the plugin SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1578
diff changeset
82 s += ',\n\n _OrthancPluginErrorCode_INTERNAL = 0x7fffffff\n '
bf502300c52e force the size of the enumerations in the plugin SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1578
diff changeset
83 a = re.sub('(typedef enum\s*{)[^}]*?(} OrthancPluginErrorCode;)', r'\1\n%s\2' % s, a, re.DOTALL)
1578
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1577
diff changeset
84
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1577
diff changeset
85 with open(path, 'w') as f:
1576
de54c19fc44d refactoring OrthancException
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
86 f.write(a)
de54c19fc44d refactoring OrthancException
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
87
1577
7aac0cddd42e generation of the error codes from a Python script
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1576
diff changeset
88
7aac0cddd42e generation of the error codes from a Python script
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1576
diff changeset
89
7aac0cddd42e generation of the error codes from a Python script
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1576
diff changeset
90 ##
7aac0cddd42e generation of the error codes from a Python script
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1576
diff changeset
91 ## Generate the "EnumerationToString(ErrorCode)" and
7aac0cddd42e generation of the error codes from a Python script
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1576
diff changeset
92 ## "ConvertErrorCodeToHttpStatus(ErrorCode)" functions in
1578
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1577
diff changeset
93 ## "Enumerations.cpp"
1577
7aac0cddd42e generation of the error codes from a Python script
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1576
diff changeset
94 ##
7aac0cddd42e generation of the error codes from a Python script
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1576
diff changeset
95
4047
0327421506ad fix paths in GenerateErrorCodes.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4044
diff changeset
96 path = os.path.join(BASE, 'OrthancFramework', 'Sources', 'Enumerations.cpp')
1578
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1577
diff changeset
97 with open(path, 'r') as f:
1577
7aac0cddd42e generation of the error codes from a Python script
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1576
diff changeset
98 a = f.read()
7aac0cddd42e generation of the error codes from a Python script
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1576
diff changeset
99
7aac0cddd42e generation of the error codes from a Python script
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1576
diff changeset
100 s = '\n\n'.join(map(lambda x: ' case ErrorCode_%s:\n return "%s";' % (x['Name'], x['Description']), ERRORS))
7aac0cddd42e generation of the error codes from a Python script
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1576
diff changeset
101 a = re.sub('(EnumerationToString\(ErrorCode.*?\)\s*{\s*switch \([^)]*?\)\s*{)[^}]*?(\s*default:)',
7aac0cddd42e generation of the error codes from a Python script
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1576
diff changeset
102 r'\1\n%s\2' % s, a, re.DOTALL)
7aac0cddd42e generation of the error codes from a Python script
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1576
diff changeset
103
7aac0cddd42e generation of the error codes from a Python script
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1576
diff changeset
104 def GetHttpStatus(x):
7aac0cddd42e generation of the error codes from a Python script
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1576
diff changeset
105 s = HTTP[x['HttpStatus']]
7aac0cddd42e generation of the error codes from a Python script
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1576
diff changeset
106 return ' case ErrorCode_%s:\n return %s;' % (x['Name'], s)
7aac0cddd42e generation of the error codes from a Python script
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1576
diff changeset
107
7aac0cddd42e generation of the error codes from a Python script
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1576
diff changeset
108 s = '\n\n'.join(map(GetHttpStatus, filter(lambda x: 'HttpStatus' in x, ERRORS)))
7aac0cddd42e generation of the error codes from a Python script
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1576
diff changeset
109 a = re.sub('(ConvertErrorCodeToHttpStatus\(ErrorCode.*?\)\s*{\s*switch \([^)]*?\)\s*{)[^}]*?(\s*default:)',
7aac0cddd42e generation of the error codes from a Python script
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1576
diff changeset
110 r'\1\n%s\2' % s, a, re.DOTALL)
7aac0cddd42e generation of the error codes from a Python script
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1576
diff changeset
111
1578
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1577
diff changeset
112 with open(path, 'w') as f:
1577
7aac0cddd42e generation of the error codes from a Python script
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1576
diff changeset
113 f.write(a)
1585
9a3e03d6a4d5 fix sqlite standalone build
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1582
diff changeset
114
9a3e03d6a4d5 fix sqlite standalone build
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1582
diff changeset
115
9a3e03d6a4d5 fix sqlite standalone build
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1582
diff changeset
116
9a3e03d6a4d5 fix sqlite standalone build
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1582
diff changeset
117 ##
9a3e03d6a4d5 fix sqlite standalone build
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1582
diff changeset
118 ## Generate the "ErrorCode" enumeration in "OrthancSQLiteException.h"
9a3e03d6a4d5 fix sqlite standalone build
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1582
diff changeset
119 ##
9a3e03d6a4d5 fix sqlite standalone build
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1582
diff changeset
120
4047
0327421506ad fix paths in GenerateErrorCodes.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4044
diff changeset
121 path = os.path.join(BASE, 'OrthancFramework', 'Sources', 'SQLite', 'OrthancSQLiteException.h')
1585
9a3e03d6a4d5 fix sqlite standalone build
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1582
diff changeset
122 with open(path, 'r') as f:
9a3e03d6a4d5 fix sqlite standalone build
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1582
diff changeset
123 a = f.read()
9a3e03d6a4d5 fix sqlite standalone build
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1582
diff changeset
124
9a3e03d6a4d5 fix sqlite standalone build
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1582
diff changeset
125 e = filter(lambda x: 'SQLite' in x and x['SQLite'], ERRORS)
9a3e03d6a4d5 fix sqlite standalone build
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1582
diff changeset
126 s = ',\n'.join(map(lambda x: ' ErrorCode_%s' % x['Name'], e))
9a3e03d6a4d5 fix sqlite standalone build
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1582
diff changeset
127 a = re.sub('(enum ErrorCode\s*{)[^}]*?(\s*};)', r'\1\n%s\2' % s, a, re.DOTALL)
9a3e03d6a4d5 fix sqlite standalone build
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1582
diff changeset
128
9a3e03d6a4d5 fix sqlite standalone build
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1582
diff changeset
129 s = '\n\n'.join(map(lambda x: ' case ErrorCode_%s:\n return "%s";' % (x['Name'], x['Description']), e))
9a3e03d6a4d5 fix sqlite standalone build
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1582
diff changeset
130 a = re.sub('(EnumerationToString\(ErrorCode.*?\)\s*{\s*switch \([^)]*?\)\s*{)[^}]*?(\s*default:)',
9a3e03d6a4d5 fix sqlite standalone build
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1582
diff changeset
131 r'\1\n%s\2' % s, a, re.DOTALL)
9a3e03d6a4d5 fix sqlite standalone build
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1582
diff changeset
132
9a3e03d6a4d5 fix sqlite standalone build
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1582
diff changeset
133 with open(path, 'w') as f:
9a3e03d6a4d5 fix sqlite standalone build
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1582
diff changeset
134 f.write(a)
1733
e1f5ab395297 PrintErrors
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1646
diff changeset
135
e1f5ab395297 PrintErrors
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1646
diff changeset
136
e1f5ab395297 PrintErrors
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1646
diff changeset
137
e1f5ab395297 PrintErrors
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1646
diff changeset
138 ##
e1f5ab395297 PrintErrors
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1646
diff changeset
139 ## Generate the "PrintErrors" function in "main.cpp"
e1f5ab395297 PrintErrors
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1646
diff changeset
140 ##
e1f5ab395297 PrintErrors
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1646
diff changeset
141
4047
0327421506ad fix paths in GenerateErrorCodes.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4044
diff changeset
142 path = os.path.join(BASE, 'OrthancServer', 'Sources', 'main.cpp')
1733
e1f5ab395297 PrintErrors
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1646
diff changeset
143 with open(path, 'r') as f:
e1f5ab395297 PrintErrors
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1646
diff changeset
144 a = f.read()
e1f5ab395297 PrintErrors
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1646
diff changeset
145
1734
e2675b37eb01 Under Windows, the exit status of Orthanc corresponds to the encountered error code
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1733
diff changeset
146 s = '\n'.join(map(lambda x: ' PrintErrorCode(ErrorCode_%s, "%s");' % (x['Name'], x['Description']), ERRORS))
e2675b37eb01 Under Windows, the exit status of Orthanc corresponds to the encountered error code
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1733
diff changeset
147 a = re.sub('(static void PrintErrors[^{}]*?{[^{}]*?{)([^}]*?)}', r'\1\n%s\n }' % s, a, re.DOTALL)
1733
e1f5ab395297 PrintErrors
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1646
diff changeset
148
1734
e2675b37eb01 Under Windows, the exit status of Orthanc corresponds to the encountered error code
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1733
diff changeset
149 with open(path, 'w') as f:
e2675b37eb01 Under Windows, the exit status of Orthanc corresponds to the encountered error code
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1733
diff changeset
150 f.write(a)