Mercurial > hg > orthanc
comparison OrthancFramework/Resources/CodeGeneration/GenerateErrorCodes.py @ 4047:0327421506ad framework
fix paths in GenerateErrorCodes.py
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Thu, 11 Jun 2020 07:53:13 +0200 |
parents | d25f4c0fa160 |
children | bf7b9edf6b81 |
comparison
equal
deleted
inserted
replaced
4046:7ff1e6c80627 | 4047:0327421506ad |
---|---|
35 import os | 35 import os |
36 import re | 36 import re |
37 import sys | 37 import sys |
38 | 38 |
39 START_PLUGINS = 1000000 | 39 START_PLUGINS = 1000000 |
40 BASE = os.path.abspath(os.path.join(os.path.dirname(__file__), '..')) | 40 BASE = os.path.abspath(os.path.join(os.path.dirname(__file__), '..', '..', '..')) |
41 | 41 |
42 | 42 |
43 | 43 |
44 ## | 44 ## |
45 ## Read all the available error codes and HTTP status | 45 ## Read all the available error codes and HTTP status |
46 ## | 46 ## |
47 | 47 |
48 with open(os.path.join(BASE, 'Resources', 'ErrorCodes.json'), 'r') as f: | 48 with open(os.path.join(BASE, 'OrthancFramework', 'Resources', 'CodeGeneration', 'ErrorCodes.json'), 'r') as f: |
49 ERRORS = json.loads(re.sub('/\*.*?\*/', '', f.read())) | 49 ERRORS = json.loads(re.sub('/\*.*?\*/', '', f.read())) |
50 | 50 |
51 for error in ERRORS: | 51 for error in ERRORS: |
52 if error['Code'] >= START_PLUGINS: | 52 if error['Code'] >= START_PLUGINS: |
53 print('ERROR: Error code must be below %d, but "%s" is set to %d' % (START_PLUGINS, error['Name'], error['Code'])) | 53 print('ERROR: Error code must be below %d, but "%s" is set to %d' % (START_PLUGINS, error['Name'], error['Code'])) |
54 sys.exit(-1) | 54 sys.exit(-1) |
55 | 55 |
56 with open(os.path.join(BASE, 'Core', 'Enumerations.h'), 'r') as f: | 56 with open(os.path.join(BASE, 'OrthancFramework', 'Sources', 'Enumerations.h'), 'r') as f: |
57 a = f.read() | 57 a = f.read() |
58 | 58 |
59 HTTP = {} | 59 HTTP = {} |
60 for i in re.findall('(HttpStatus_([0-9]+)_\w+)', a): | 60 for i in re.findall('(HttpStatus_([0-9]+)_\w+)', a): |
61 HTTP[int(i[1])] = i[0] | 61 HTTP[int(i[1])] = i[0] |
64 | 64 |
65 ## | 65 ## |
66 ## Generate the "ErrorCode" enumeration in "Enumerations.h" | 66 ## Generate the "ErrorCode" enumeration in "Enumerations.h" |
67 ## | 67 ## |
68 | 68 |
69 path = os.path.join(BASE, 'Core', 'Enumerations.h') | 69 path = os.path.join(BASE, 'OrthancFramework', 'Sources', 'Enumerations.h') |
70 with open(path, 'r') as f: | 70 with open(path, 'r') as f: |
71 a = f.read() | 71 a = f.read() |
72 | 72 |
73 s = ',\n'.join(map(lambda x: ' ErrorCode_%s = %d /*!< %s */' % (x['Name'], int(x['Code']), x['Description']), ERRORS)) | 73 s = ',\n'.join(map(lambda x: ' ErrorCode_%s = %d /*!< %s */' % (x['Name'], int(x['Code']), x['Description']), ERRORS)) |
74 | 74 |
82 | 82 |
83 ## | 83 ## |
84 ## Generate the "OrthancPluginErrorCode" enumeration in "OrthancCPlugin.h" | 84 ## Generate the "OrthancPluginErrorCode" enumeration in "OrthancCPlugin.h" |
85 ## | 85 ## |
86 | 86 |
87 path = os.path.join(BASE, 'Plugins', 'Include', 'orthanc', 'OrthancCPlugin.h') | 87 path = os.path.join(BASE, 'OrthancServer', 'Plugins', 'Include', 'orthanc', 'OrthancCPlugin.h') |
88 with open(path, 'r') as f: | 88 with open(path, 'r') as f: |
89 a = f.read() | 89 a = f.read() |
90 | 90 |
91 s = ',\n'.join(map(lambda x: ' OrthancPluginErrorCode_%s = %d /*!< %s */' % (x['Name'], int(x['Code']), x['Description']), ERRORS)) | 91 s = ',\n'.join(map(lambda x: ' OrthancPluginErrorCode_%s = %d /*!< %s */' % (x['Name'], int(x['Code']), x['Description']), ERRORS)) |
92 s += ',\n\n _OrthancPluginErrorCode_INTERNAL = 0x7fffffff\n ' | 92 s += ',\n\n _OrthancPluginErrorCode_INTERNAL = 0x7fffffff\n ' |
101 ## Generate the "EnumerationToString(ErrorCode)" and | 101 ## Generate the "EnumerationToString(ErrorCode)" and |
102 ## "ConvertErrorCodeToHttpStatus(ErrorCode)" functions in | 102 ## "ConvertErrorCodeToHttpStatus(ErrorCode)" functions in |
103 ## "Enumerations.cpp" | 103 ## "Enumerations.cpp" |
104 ## | 104 ## |
105 | 105 |
106 path = os.path.join(BASE, 'Core', 'Enumerations.cpp') | 106 path = os.path.join(BASE, 'OrthancFramework', 'Sources', 'Enumerations.cpp') |
107 with open(path, 'r') as f: | 107 with open(path, 'r') as f: |
108 a = f.read() | 108 a = f.read() |
109 | 109 |
110 s = '\n\n'.join(map(lambda x: ' case ErrorCode_%s:\n return "%s";' % (x['Name'], x['Description']), ERRORS)) | 110 s = '\n\n'.join(map(lambda x: ' case ErrorCode_%s:\n return "%s";' % (x['Name'], x['Description']), ERRORS)) |
111 a = re.sub('(EnumerationToString\(ErrorCode.*?\)\s*{\s*switch \([^)]*?\)\s*{)[^}]*?(\s*default:)', | 111 a = re.sub('(EnumerationToString\(ErrorCode.*?\)\s*{\s*switch \([^)]*?\)\s*{)[^}]*?(\s*default:)', |
126 | 126 |
127 ## | 127 ## |
128 ## Generate the "ErrorCode" enumeration in "OrthancSQLiteException.h" | 128 ## Generate the "ErrorCode" enumeration in "OrthancSQLiteException.h" |
129 ## | 129 ## |
130 | 130 |
131 path = os.path.join(BASE, 'Core', 'SQLite', 'OrthancSQLiteException.h') | 131 path = os.path.join(BASE, 'OrthancFramework', 'Sources', 'SQLite', 'OrthancSQLiteException.h') |
132 with open(path, 'r') as f: | 132 with open(path, 'r') as f: |
133 a = f.read() | 133 a = f.read() |
134 | 134 |
135 e = filter(lambda x: 'SQLite' in x and x['SQLite'], ERRORS) | 135 e = filter(lambda x: 'SQLite' in x and x['SQLite'], ERRORS) |
136 s = ',\n'.join(map(lambda x: ' ErrorCode_%s' % x['Name'], e)) | 136 s = ',\n'.join(map(lambda x: ' ErrorCode_%s' % x['Name'], e)) |
147 | 147 |
148 ## | 148 ## |
149 ## Generate the "PrintErrors" function in "main.cpp" | 149 ## Generate the "PrintErrors" function in "main.cpp" |
150 ## | 150 ## |
151 | 151 |
152 path = os.path.join(BASE, 'OrthancServer', 'main.cpp') | 152 path = os.path.join(BASE, 'OrthancServer', 'Sources', 'main.cpp') |
153 with open(path, 'r') as f: | 153 with open(path, 'r') as f: |
154 a = f.read() | 154 a = f.read() |
155 | 155 |
156 s = '\n'.join(map(lambda x: ' PrintErrorCode(ErrorCode_%s, "%s");' % (x['Name'], x['Description']), ERRORS)) | 156 s = '\n'.join(map(lambda x: ' PrintErrorCode(ErrorCode_%s, "%s");' % (x['Name'], x['Description']), ERRORS)) |
157 a = re.sub('(static void PrintErrors[^{}]*?{[^{}]*?{)([^}]*?)}', r'\1\n%s\n }' % s, a, re.DOTALL) | 157 a = re.sub('(static void PrintErrors[^{}]*?{[^{}]*?{)([^}]*?)}', r'\1\n%s\n }' % s, a, re.DOTALL) |