comparison Resources/GenerateErrorCodes.py @ 1646:da799f767e5d

simplification in error casting with plugins
author Sebastien Jodogne <s.jodogne@gmail.com>
date Thu, 24 Sep 2015 16:01:09 +0200
parents 939b921b2c81
children e1f5ab395297
comparison
equal deleted inserted replaced
1645:1558b3226b18 1646:da799f767e5d
139 a = re.sub('(EnumerationToString\(ErrorCode.*?\)\s*{\s*switch \([^)]*?\)\s*{)[^}]*?(\s*default:)', 139 a = re.sub('(EnumerationToString\(ErrorCode.*?\)\s*{\s*switch \([^)]*?\)\s*{)[^}]*?(\s*default:)',
140 r'\1\n%s\2' % s, a, re.DOTALL) 140 r'\1\n%s\2' % s, a, re.DOTALL)
141 141
142 with open(path, 'w') as f: 142 with open(path, 'w') as f:
143 f.write(a) 143 f.write(a)
144
145
146
147 ##
148 ## Generate the "Plugins::Convert(OrthancPluginErrorCode)" in
149 ## "PluginsEnumerations.cpp"
150 ##
151
152 path = os.path.join(BASE, 'Plugins', 'Engine', 'PluginsEnumerations.cpp')
153 with open(path, 'r') as f:
154 a = f.read()
155
156 s = '\n\n'.join(map(lambda x: ' case OrthancPluginErrorCode_%s:\n return ErrorCode_%s;' % (x['Name'], x['Name']), ERRORS))
157 a = re.sub('(Convert\(OrthancPluginErrorCode.*?\)\s*{\s*switch \([^)]*?\)\s*{)[^}]*?(\s*default:)',
158 r'\1\n%s\2' % s, a, re.DOTALL)
159
160 with open(path, 'w') as f:
161 f.write(a)