diff Resources/GenerateErrorCodes.py @ 1626:8dc468f44661

mapping of error codes from plugins to Orthanc
author Sebastien Jodogne <s.jodogne@gmail.com>
date Fri, 18 Sep 2015 14:28:47 +0200
parents 9a3e03d6a4d5
children 939b921b2c81
line wrap: on
line diff
--- a/Resources/GenerateErrorCodes.py	Fri Sep 18 12:58:51 2015 +0200
+++ b/Resources/GenerateErrorCodes.py	Fri Sep 18 14:28:47 2015 +0200
@@ -132,3 +132,21 @@
 
 with open(path, 'w') as f:
     f.write(a)
+
+
+
+##
+## Generate the "Plugins::Convert(OrthancPluginErrorCode)" in
+## "PluginsEnumerations.cpp"
+##
+
+path = os.path.join(BASE, 'Plugins', 'Engine', 'PluginsEnumerations.cpp')
+with open(path, 'r') as f:
+    a = f.read()
+
+s = '\n\n'.join(map(lambda x: '        case OrthancPluginErrorCode_%s:\n          return ErrorCode_%s;' % (x['Name'], x['Name']), ERRORS))
+a = re.sub('(Convert\(OrthancPluginErrorCode.*?\)\s*{\s*switch \([^)]*?\)\s*{)[^}]*?(\s*default:)',
+           r'\1\n%s\2' % s, a, re.DOTALL)
+
+with open(path, 'w') as f:
+    f.write(a)