comparison Resources/GenerateErrorCodes.py @ 1578:09715095fc53

cont
author Sebastien Jodogne <s.jodogne@gmail.com>
date Tue, 25 Aug 2015 15:33:36 +0200
parents 7aac0cddd42e
children bf502300c52e
comparison
equal deleted inserted replaced
1577:7aac0cddd42e 1578:09715095fc53
53 HTTP[int(i[1])] = i[0] 53 HTTP[int(i[1])] = i[0]
54 54
55 55
56 56
57 ## 57 ##
58 ## Generate the "ErrorCode" enumeration in "Core/Enumerations.h" 58 ## Generate the "ErrorCode" enumeration in "Enumerations.h"
59 ## 59 ##
60 60
61 with open(os.path.join(BASE, 'Core', 'Enumerations.h'), 'r') as f: 61 path = os.path.join(BASE, 'Core', 'Enumerations.h')
62 with open(path, 'r') as f:
62 a = f.read() 63 a = f.read()
63 64
64 s = ',\n'.join(map(lambda x: ' ErrorCode_%s = %d' % (x['Name'], int(x['Code'])), ERRORS)) 65 s = ',\n'.join(map(lambda x: ' ErrorCode_%s = %d /*!< %s */' % (x['Name'], int(x['Code']), x['Description']), ERRORS))
65 a = re.sub('(enum ErrorCode\s*{)[^}]*?(\s*};)', r'\1\n%s\2' % s, a, re.DOTALL) 66 a = re.sub('(enum ErrorCode\s*{)[^}]*?(\s*};)', r'\1\n%s\2' % s, a, re.DOTALL)
66 67
67 with open(os.path.join(BASE, 'Core', 'Enumerations.h'), 'w') as f: 68 with open(path, 'w') as f:
69 f.write(a)
70
71
72
73 ##
74 ## Generate the "OrthancPluginErrorCode" enumeration in "OrthancCPlugin.h"
75 ##
76
77 path = os.path.join(BASE, 'Plugins', 'Include', 'orthanc', 'OrthancCPlugin.h')
78 with open(path, 'r') as f:
79 a = f.read()
80
81 s = ',\n'.join(map(lambda x: ' OrthancPluginErrorCode_%s = %d /*!< %s */' % (x['Name'], int(x['Code']), x['Description']), ERRORS))
82 a = re.sub('(typedef enum\s*{)[^}]*?(\s*} OrthancPluginErrorCode;)', r'\1\n%s\2' % s, a, re.DOTALL)
83
84 with open(path, 'w') as f:
68 f.write(a) 85 f.write(a)
69 86
70 87
71 88
72 ## 89 ##
73 ## Generate the "EnumerationToString(ErrorCode)" and 90 ## Generate the "EnumerationToString(ErrorCode)" and
74 ## "ConvertErrorCodeToHttpStatus(ErrorCode)" functions in 91 ## "ConvertErrorCodeToHttpStatus(ErrorCode)" functions in
75 ## "Core/Enumerations.cpp" 92 ## "Enumerations.cpp"
76 ## 93 ##
77 94
78 with open(os.path.join(BASE, 'Core', 'Enumerations.cpp'), 'r') as f: 95 path = os.path.join(BASE, 'Core', 'Enumerations.cpp')
96 with open(path, 'r') as f:
79 a = f.read() 97 a = f.read()
80 98
81 s = '\n\n'.join(map(lambda x: ' case ErrorCode_%s:\n return "%s";' % (x['Name'], x['Description']), ERRORS)) 99 s = '\n\n'.join(map(lambda x: ' case ErrorCode_%s:\n return "%s";' % (x['Name'], x['Description']), ERRORS))
82 a = re.sub('(EnumerationToString\(ErrorCode.*?\)\s*{\s*switch \([^)]*?\)\s*{)[^}]*?(\s*default:)', 100 a = re.sub('(EnumerationToString\(ErrorCode.*?\)\s*{\s*switch \([^)]*?\)\s*{)[^}]*?(\s*default:)',
83 r'\1\n%s\2' % s, a, re.DOTALL) 101 r'\1\n%s\2' % s, a, re.DOTALL)
88 106
89 s = '\n\n'.join(map(GetHttpStatus, filter(lambda x: 'HttpStatus' in x, ERRORS))) 107 s = '\n\n'.join(map(GetHttpStatus, filter(lambda x: 'HttpStatus' in x, ERRORS)))
90 a = re.sub('(ConvertErrorCodeToHttpStatus\(ErrorCode.*?\)\s*{\s*switch \([^)]*?\)\s*{)[^}]*?(\s*default:)', 108 a = re.sub('(ConvertErrorCodeToHttpStatus\(ErrorCode.*?\)\s*{\s*switch \([^)]*?\)\s*{)[^}]*?(\s*default:)',
91 r'\1\n%s\2' % s, a, re.DOTALL) 109 r'\1\n%s\2' % s, a, re.DOTALL)
92 110
93 with open(os.path.join(BASE, 'Core', 'Enumerations.cpp'), 'w') as f: 111 with open(path, 'w') as f:
94 f.write(a) 112 f.write(a)