Mercurial > hg > orthanc
annotate OrthancFramework/Resources/CodeGeneration/GenerateErrorCodes.py @ 5831:22623aa8e6fc find-refactoring tip
DB SDK: ordering + metadata constraints
author | Alain Mazy <am@orthanc.team> |
---|---|
date | Tue, 08 Oct 2024 17:53:06 +0200 |
parents | f7adfb22e20e |
children |
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 | 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 |
5640
f7adfb22e20e
updated copyright, as Orthanc Team now replaces Osimis
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5485
diff
changeset
|
6 # Copyright (C) 2017-2023 Osimis S.A., Belgium |
f7adfb22e20e
updated copyright, as Orthanc Team now replaces Osimis
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5485
diff
changeset
|
7 # Copyright (C) 2024-2024 Orthanc Team SRL, Belgium |
5485
48b8dae6dc77
upgrade to year 2024
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5384
diff
changeset
|
8 # Copyright (C) 2021-2024 Sebastien Jodogne, ICTEAM UCLouvain, Belgium |
1576
de54c19fc44d
refactoring OrthancException
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
9 # |
de54c19fc44d
refactoring OrthancException
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
10 # 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
|
11 # 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
|
12 # 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
|
13 # the License, or (at your option) any later version. |
1576
de54c19fc44d
refactoring OrthancException
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
14 # |
de54c19fc44d
refactoring OrthancException
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
15 # 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
|
16 # WITHOUT ANY WARRANTY; without even the implied warranty of |
de54c19fc44d
refactoring OrthancException
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
17 # 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
|
18 # Lesser General Public License for more details. |
1576
de54c19fc44d
refactoring OrthancException
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
19 # |
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
|
20 # 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
|
21 # 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
|
22 # <http://www.gnu.org/licenses/>. |
1576
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 |
de54c19fc44d
refactoring OrthancException
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
25 import json |
de54c19fc44d
refactoring OrthancException
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
26 import os |
de54c19fc44d
refactoring OrthancException
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
27 import re |
1644
939b921b2c81
plugin error dictionary
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1626
diff
changeset
|
28 import sys |
1576
de54c19fc44d
refactoring OrthancException
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
29 |
1644
939b921b2c81
plugin error dictionary
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1626
diff
changeset
|
30 START_PLUGINS = 1000000 |
4047
0327421506ad
fix paths in GenerateErrorCodes.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4044
diff
changeset
|
31 BASE = os.path.abspath(os.path.join(os.path.dirname(__file__), '..', '..', '..')) |
1576
de54c19fc44d
refactoring OrthancException
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
32 |
de54c19fc44d
refactoring OrthancException
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
33 |
1577
7aac0cddd42e
generation of the error codes from a Python script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1576
diff
changeset
|
34 |
1576
de54c19fc44d
refactoring OrthancException
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
35 ## |
1577
7aac0cddd42e
generation of the error codes from a Python script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1576
diff
changeset
|
36 ## Read all the available error codes and HTTP status |
1576
de54c19fc44d
refactoring OrthancException
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
37 ## |
de54c19fc44d
refactoring OrthancException
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
38 |
4047
0327421506ad
fix paths in GenerateErrorCodes.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4044
diff
changeset
|
39 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
|
40 ERRORS = json.loads(re.sub('/\*.*?\*/', '', f.read())) |
1576
de54c19fc44d
refactoring OrthancException
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
41 |
1644
939b921b2c81
plugin error dictionary
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1626
diff
changeset
|
42 for error in ERRORS: |
939b921b2c81
plugin error dictionary
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1626
diff
changeset
|
43 if error['Code'] >= START_PLUGINS: |
939b921b2c81
plugin error dictionary
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1626
diff
changeset
|
44 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
|
45 sys.exit(-1) |
939b921b2c81
plugin error dictionary
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1626
diff
changeset
|
46 |
4047
0327421506ad
fix paths in GenerateErrorCodes.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4044
diff
changeset
|
47 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
|
48 a = f.read() |
7aac0cddd42e
generation of the error codes from a Python script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1576
diff
changeset
|
49 |
7aac0cddd42e
generation of the error codes from a Python script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1576
diff
changeset
|
50 HTTP = {} |
7aac0cddd42e
generation of the error codes from a Python script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1576
diff
changeset
|
51 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
|
52 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
|
53 |
7aac0cddd42e
generation of the error codes from a Python script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1576
diff
changeset
|
54 |
1576
de54c19fc44d
refactoring OrthancException
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
55 |
de54c19fc44d
refactoring OrthancException
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
56 ## |
1578 | 57 ## Generate the "ErrorCode" enumeration in "Enumerations.h" |
1576
de54c19fc44d
refactoring OrthancException
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
58 ## |
de54c19fc44d
refactoring OrthancException
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
59 |
4047
0327421506ad
fix paths in GenerateErrorCodes.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4044
diff
changeset
|
60 path = os.path.join(BASE, 'OrthancFramework', 'Sources', 'Enumerations.h') |
1578 | 61 with open(path, 'r') as f: |
1576
de54c19fc44d
refactoring OrthancException
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
62 a = f.read() |
de54c19fc44d
refactoring OrthancException
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
63 |
1578 | 64 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
|
65 |
939b921b2c81
plugin error dictionary
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1626
diff
changeset
|
66 s += ',\n ErrorCode_START_PLUGINS = %d' % START_PLUGINS |
1576
de54c19fc44d
refactoring OrthancException
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
67 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
|
68 |
1578 | 69 with open(path, 'w') as f: |
70 f.write(a) | |
71 | |
72 | |
73 | |
74 ## | |
75 ## Generate the "OrthancPluginErrorCode" enumeration in "OrthancCPlugin.h" | |
76 ## | |
77 | |
4047
0327421506ad
fix paths in GenerateErrorCodes.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4044
diff
changeset
|
78 path = os.path.join(BASE, 'OrthancServer', 'Plugins', 'Include', 'orthanc', 'OrthancCPlugin.h') |
1578 | 79 with open(path, 'r') as f: |
80 a = f.read() | |
81 | |
82 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
|
83 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
|
84 a = re.sub('(typedef enum\s*{)[^}]*?(} OrthancPluginErrorCode;)', r'\1\n%s\2' % s, a, re.DOTALL) |
1578 | 85 |
86 with open(path, 'w') as f: | |
1576
de54c19fc44d
refactoring OrthancException
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
87 f.write(a) |
de54c19fc44d
refactoring OrthancException
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
88 |
1577
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 ## |
7aac0cddd42e
generation of the error codes from a Python script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1576
diff
changeset
|
92 ## 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
|
93 ## "ConvertErrorCodeToHttpStatus(ErrorCode)" functions in |
1578 | 94 ## "Enumerations.cpp" |
1577
7aac0cddd42e
generation of the error codes from a Python script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1576
diff
changeset
|
95 ## |
7aac0cddd42e
generation of the error codes from a Python script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1576
diff
changeset
|
96 |
4047
0327421506ad
fix paths in GenerateErrorCodes.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4044
diff
changeset
|
97 path = os.path.join(BASE, 'OrthancFramework', 'Sources', 'Enumerations.cpp') |
1578 | 98 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
|
99 a = f.read() |
7aac0cddd42e
generation of the error codes from a Python script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1576
diff
changeset
|
100 |
7aac0cddd42e
generation of the error codes from a Python script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1576
diff
changeset
|
101 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
|
102 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
|
103 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
|
104 |
7aac0cddd42e
generation of the error codes from a Python script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1576
diff
changeset
|
105 def GetHttpStatus(x): |
7aac0cddd42e
generation of the error codes from a Python script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1576
diff
changeset
|
106 s = HTTP[x['HttpStatus']] |
7aac0cddd42e
generation of the error codes from a Python script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1576
diff
changeset
|
107 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
|
108 |
7aac0cddd42e
generation of the error codes from a Python script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1576
diff
changeset
|
109 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
|
110 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
|
111 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
|
112 |
1578 | 113 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
|
114 f.write(a) |
1585
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 ## |
9a3e03d6a4d5
fix sqlite standalone build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1582
diff
changeset
|
119 ## Generate the "ErrorCode" enumeration in "OrthancSQLiteException.h" |
9a3e03d6a4d5
fix sqlite standalone build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1582
diff
changeset
|
120 ## |
9a3e03d6a4d5
fix sqlite standalone build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1582
diff
changeset
|
121 |
4047
0327421506ad
fix paths in GenerateErrorCodes.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4044
diff
changeset
|
122 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
|
123 with open(path, 'r') as f: |
9a3e03d6a4d5
fix sqlite standalone build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1582
diff
changeset
|
124 a = f.read() |
9a3e03d6a4d5
fix sqlite standalone build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1582
diff
changeset
|
125 |
5384
31bfa492311e
GenerateErrorCodes.py now works with python3
Alain Mazy <am@osimis.io>
parents:
5185
diff
changeset
|
126 e = list(filter(lambda x: 'SQLite' in x and x['SQLite'], ERRORS)) |
1585
9a3e03d6a4d5
fix sqlite standalone build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1582
diff
changeset
|
127 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
|
128 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
|
129 |
9a3e03d6a4d5
fix sqlite standalone build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1582
diff
changeset
|
130 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
|
131 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
|
132 r'\1\n%s\2' % s, a, re.DOTALL) |
9a3e03d6a4d5
fix sqlite standalone build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1582
diff
changeset
|
133 |
9a3e03d6a4d5
fix sqlite standalone build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1582
diff
changeset
|
134 with open(path, 'w') as f: |
9a3e03d6a4d5
fix sqlite standalone build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1582
diff
changeset
|
135 f.write(a) |
1733 | 136 |
137 | |
138 | |
139 ## | |
140 ## Generate the "PrintErrors" function in "main.cpp" | |
141 ## | |
142 | |
4047
0327421506ad
fix paths in GenerateErrorCodes.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4044
diff
changeset
|
143 path = os.path.join(BASE, 'OrthancServer', 'Sources', 'main.cpp') |
1733 | 144 with open(path, 'r') as f: |
145 a = f.read() | |
146 | |
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
|
147 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
|
148 a = re.sub('(static void PrintErrors[^{}]*?{[^{}]*?{)([^}]*?)}', r'\1\n%s\n }' % s, a, re.DOTALL) |
1733 | 149 |
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
|
150 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
|
151 f.write(a) |