Mercurial > hg > orthanc
annotate Resources/GenerateErrorCodes.py @ 2248:69b0f4e8a49b
Escape multipart type parameter value in Content-Type header
## Summary
Multipart responses do not quote/escape the value of their type
parameter (the subtype) even though it always contains at least one
special character (the slash "/"), which confuses standard-compliant
HTTP clients.
## Details
The Content-Type header in HTTP is in RFC 7231, Section 3.1.1.5:
https://tools.ietf.org/html/rfc7231#section-3.1.1.5
The section defers to the media type section (3.1.1.1) for the syntax of
the media type:
https://tools.ietf.org/html/rfc7231#section-3.1.1.1
This states that a parameter value can be quoted:
parameter = token "=" ( token / quoted-string )
A parameter value that matches the token production can be transmitted
either as a token or within a quoted-string. The quoted and unquoted
values are equivalent.
Tokens are defined in RFC 7230, Section 3.2.6 (via RFC 7231, appendix
C):
https://tools.ietf.org/html/rfc7231#appendix-C
https://tools.ietf.org/html/rfc7230#section-3.2.6
Here we observe that tokens cannot contain a slash "/" character:
token = 1*tchar
tchar = "!" / "#" / "$" / "%" / "&" / "'" / "*"
/ "+" / "-" / "." / "^" / "_" / "`" / "|" / "~"
/ DIGIT / ALPHA
; any VCHAR, except delimiters
Delimiters are chosen from the set of US-ASCII visual characters not
allowed in a token (DQUOTE and "(),/:;<=>?@[\]{}").
However, the current implementation does not quote/escape the value of
the type parameter:
multipart/related; type=application/dicom
Instead, it should be:
multipart/related; type="application/dicom"
All of this also seems to apply to the MIME Content-Type header
definition, even though it is a little different:
https://www.iana.org/assignments/message-headers
https://tools.ietf.org/html/rfc2045#section-5.1
https://tools.ietf.org/html/rfc2387
author | Thibault Nélis <tn@osimis.io> |
---|---|
date | Mon, 16 Jan 2017 13:07:11 +0100 |
parents | a3a65de1840f |
children | 878b59270859 |
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 |
2244
a3a65de1840f
shared copyright with osimis
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1900
diff
changeset
|
6 # Copyright (C) 2017 Osimis, Belgium |
1576
de54c19fc44d
refactoring OrthancException
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
7 # |
de54c19fc44d
refactoring OrthancException
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
8 # This program is free software: you can redistribute it and/or |
de54c19fc44d
refactoring OrthancException
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
9 # modify it under the terms of the GNU General Public License as |
de54c19fc44d
refactoring OrthancException
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
10 # published by the Free Software Foundation, either version 3 of the |
de54c19fc44d
refactoring OrthancException
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
11 # License, or (at your option) any later version. |
de54c19fc44d
refactoring OrthancException
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
12 # |
de54c19fc44d
refactoring OrthancException
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
13 # In addition, as a special exception, the copyright holders of this |
de54c19fc44d
refactoring OrthancException
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
14 # program give permission to link the code of its release with the |
de54c19fc44d
refactoring OrthancException
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
15 # OpenSSL project's "OpenSSL" library (or with modified versions of it |
de54c19fc44d
refactoring OrthancException
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
16 # that use the same license as the "OpenSSL" library), and distribute |
de54c19fc44d
refactoring OrthancException
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
17 # the linked executables. You must obey the GNU General Public License |
de54c19fc44d
refactoring OrthancException
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
18 # in all respects for all of the code used other than "OpenSSL". If you |
de54c19fc44d
refactoring OrthancException
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
19 # modify file(s) with this exception, you may extend this exception to |
de54c19fc44d
refactoring OrthancException
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
20 # your version of the file(s), but you are not obligated to do so. If |
de54c19fc44d
refactoring OrthancException
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
21 # you do not wish to do so, delete this exception statement from your |
de54c19fc44d
refactoring OrthancException
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
22 # version. If you delete this exception statement from all source files |
de54c19fc44d
refactoring OrthancException
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
23 # in the program, then also delete it here. |
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 # 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
|
26 # WITHOUT ANY WARRANTY; without even the implied warranty of |
de54c19fc44d
refactoring OrthancException
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
27 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
de54c19fc44d
refactoring OrthancException
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
28 # General Public License for more details. |
de54c19fc44d
refactoring OrthancException
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
29 # |
de54c19fc44d
refactoring OrthancException
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
30 # You should have received a copy of the GNU General Public License |
de54c19fc44d
refactoring OrthancException
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
31 # along with this program. If not, see <http://www.gnu.org/licenses/>. |
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 |
de54c19fc44d
refactoring OrthancException
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
34 import json |
de54c19fc44d
refactoring OrthancException
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
35 import os |
de54c19fc44d
refactoring OrthancException
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
36 import re |
1644
939b921b2c81
plugin error dictionary
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1626
diff
changeset
|
37 import sys |
1576
de54c19fc44d
refactoring OrthancException
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
38 |
1644
939b921b2c81
plugin error dictionary
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1626
diff
changeset
|
39 START_PLUGINS = 1000000 |
1576
de54c19fc44d
refactoring OrthancException
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
40 BASE = os.path.abspath(os.path.join(os.path.dirname(__file__), '..')) |
de54c19fc44d
refactoring OrthancException
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
41 |
de54c19fc44d
refactoring OrthancException
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
42 |
1577
7aac0cddd42e
generation of the error codes from a Python script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1576
diff
changeset
|
43 |
1576
de54c19fc44d
refactoring OrthancException
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
44 ## |
1577
7aac0cddd42e
generation of the error codes from a Python script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1576
diff
changeset
|
45 ## Read all the available error codes and HTTP status |
1576
de54c19fc44d
refactoring OrthancException
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
46 ## |
de54c19fc44d
refactoring OrthancException
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
47 |
de54c19fc44d
refactoring OrthancException
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
48 with open(os.path.join(BASE, 'Resources', 'ErrorCodes.json'), 'r') as f: |
1582
bd1889029cbb
encoding of exceptions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1580
diff
changeset
|
49 ERRORS = json.loads(re.sub('/\*.*?\*/', '', f.read())) |
1576
de54c19fc44d
refactoring OrthancException
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
50 |
1644
939b921b2c81
plugin error dictionary
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1626
diff
changeset
|
51 for error in ERRORS: |
939b921b2c81
plugin error dictionary
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1626
diff
changeset
|
52 if error['Code'] >= START_PLUGINS: |
939b921b2c81
plugin error dictionary
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1626
diff
changeset
|
53 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
|
54 sys.exit(-1) |
939b921b2c81
plugin error dictionary
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1626
diff
changeset
|
55 |
1577
7aac0cddd42e
generation of the error codes from a Python script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1576
diff
changeset
|
56 with open(os.path.join(BASE, 'Core', 'Enumerations.h'), 'r') as f: |
7aac0cddd42e
generation of the error codes from a Python script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1576
diff
changeset
|
57 a = f.read() |
7aac0cddd42e
generation of the error codes from a Python script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1576
diff
changeset
|
58 |
7aac0cddd42e
generation of the error codes from a Python script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1576
diff
changeset
|
59 HTTP = {} |
7aac0cddd42e
generation of the error codes from a Python script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1576
diff
changeset
|
60 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
|
61 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
|
62 |
7aac0cddd42e
generation of the error codes from a Python script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1576
diff
changeset
|
63 |
1576
de54c19fc44d
refactoring OrthancException
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
64 |
de54c19fc44d
refactoring OrthancException
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
65 ## |
1578 | 66 ## Generate the "ErrorCode" enumeration in "Enumerations.h" |
1576
de54c19fc44d
refactoring OrthancException
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
67 ## |
de54c19fc44d
refactoring OrthancException
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
68 |
1578 | 69 path = os.path.join(BASE, 'Core', 'Enumerations.h') |
70 with open(path, 'r') as f: | |
1576
de54c19fc44d
refactoring OrthancException
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
71 a = f.read() |
de54c19fc44d
refactoring OrthancException
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
72 |
1578 | 73 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
|
74 |
939b921b2c81
plugin error dictionary
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1626
diff
changeset
|
75 s += ',\n ErrorCode_START_PLUGINS = %d' % START_PLUGINS |
1576
de54c19fc44d
refactoring OrthancException
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
76 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
|
77 |
1578 | 78 with open(path, 'w') as f: |
79 f.write(a) | |
80 | |
81 | |
82 | |
83 ## | |
84 ## Generate the "OrthancPluginErrorCode" enumeration in "OrthancCPlugin.h" | |
85 ## | |
86 | |
87 path = os.path.join(BASE, 'Plugins', 'Include', 'orthanc', 'OrthancCPlugin.h') | |
88 with open(path, 'r') as f: | |
89 a = f.read() | |
90 | |
91 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
|
92 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
|
93 a = re.sub('(typedef enum\s*{)[^}]*?(} OrthancPluginErrorCode;)', r'\1\n%s\2' % s, a, re.DOTALL) |
1578 | 94 |
95 with open(path, 'w') as f: | |
1576
de54c19fc44d
refactoring OrthancException
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
96 f.write(a) |
de54c19fc44d
refactoring OrthancException
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
97 |
1577
7aac0cddd42e
generation of the error codes from a Python script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1576
diff
changeset
|
98 |
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 ## |
7aac0cddd42e
generation of the error codes from a Python script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1576
diff
changeset
|
101 ## 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
|
102 ## "ConvertErrorCodeToHttpStatus(ErrorCode)" functions in |
1578 | 103 ## "Enumerations.cpp" |
1577
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 |
1578 | 106 path = os.path.join(BASE, 'Core', 'Enumerations.cpp') |
107 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
|
108 a = f.read() |
7aac0cddd42e
generation of the error codes from a Python script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1576
diff
changeset
|
109 |
7aac0cddd42e
generation of the error codes from a Python script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1576
diff
changeset
|
110 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
|
111 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
|
112 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
|
113 |
7aac0cddd42e
generation of the error codes from a Python script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1576
diff
changeset
|
114 def GetHttpStatus(x): |
7aac0cddd42e
generation of the error codes from a Python script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1576
diff
changeset
|
115 s = HTTP[x['HttpStatus']] |
7aac0cddd42e
generation of the error codes from a Python script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1576
diff
changeset
|
116 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
|
117 |
7aac0cddd42e
generation of the error codes from a Python script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1576
diff
changeset
|
118 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
|
119 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
|
120 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
|
121 |
1578 | 122 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
|
123 f.write(a) |
1585
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 |
9a3e03d6a4d5
fix sqlite standalone build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1582
diff
changeset
|
126 |
9a3e03d6a4d5
fix sqlite standalone build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1582
diff
changeset
|
127 ## |
9a3e03d6a4d5
fix sqlite standalone build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1582
diff
changeset
|
128 ## Generate the "ErrorCode" enumeration in "OrthancSQLiteException.h" |
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 |
9a3e03d6a4d5
fix sqlite standalone build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1582
diff
changeset
|
131 path = os.path.join(BASE, 'Core', 'SQLite', 'OrthancSQLiteException.h') |
9a3e03d6a4d5
fix sqlite standalone build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1582
diff
changeset
|
132 with open(path, 'r') as f: |
9a3e03d6a4d5
fix sqlite standalone build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1582
diff
changeset
|
133 a = f.read() |
9a3e03d6a4d5
fix sqlite standalone build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1582
diff
changeset
|
134 |
9a3e03d6a4d5
fix sqlite standalone build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1582
diff
changeset
|
135 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
|
136 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
|
137 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
|
138 |
9a3e03d6a4d5
fix sqlite standalone build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1582
diff
changeset
|
139 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
|
140 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
|
141 r'\1\n%s\2' % s, a, re.DOTALL) |
9a3e03d6a4d5
fix sqlite standalone build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1582
diff
changeset
|
142 |
9a3e03d6a4d5
fix sqlite standalone build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1582
diff
changeset
|
143 with open(path, 'w') as f: |
9a3e03d6a4d5
fix sqlite standalone build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1582
diff
changeset
|
144 f.write(a) |
1733 | 145 |
146 | |
147 | |
148 ## | |
149 ## Generate the "PrintErrors" function in "main.cpp" | |
150 ## | |
151 | |
152 path = os.path.join(BASE, 'OrthancServer', 'main.cpp') | |
153 with open(path, 'r') as f: | |
154 a = f.read() | |
155 | |
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
|
156 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
|
157 a = re.sub('(static void PrintErrors[^{}]*?{[^{}]*?{)([^}]*?)}', r'\1\n%s\n }' % s, a, re.DOTALL) |
1733 | 158 |
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
|
159 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
|
160 f.write(a) |