Mercurial > hg > orthanc
comparison Resources/GenerateErrorCodes.py @ 1644:939b921b2c81
plugin error dictionary
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Wed, 23 Sep 2015 22:05:27 +0200 |
parents | 8dc468f44661 |
children | da799f767e5d |
comparison
equal
deleted
inserted
replaced
1643:87c77b9b3679 | 1644:939b921b2c81 |
---|---|
31 | 31 |
32 | 32 |
33 import json | 33 import json |
34 import os | 34 import os |
35 import re | 35 import re |
36 import sys | |
36 | 37 |
38 START_PLUGINS = 1000000 | |
37 BASE = os.path.abspath(os.path.join(os.path.dirname(__file__), '..')) | 39 BASE = os.path.abspath(os.path.join(os.path.dirname(__file__), '..')) |
38 | 40 |
39 | 41 |
40 | 42 |
41 ## | 43 ## |
42 ## Read all the available error codes and HTTP status | 44 ## Read all the available error codes and HTTP status |
43 ## | 45 ## |
44 | 46 |
45 with open(os.path.join(BASE, 'Resources', 'ErrorCodes.json'), 'r') as f: | 47 with open(os.path.join(BASE, 'Resources', 'ErrorCodes.json'), 'r') as f: |
46 ERRORS = json.loads(re.sub('/\*.*?\*/', '', f.read())) | 48 ERRORS = json.loads(re.sub('/\*.*?\*/', '', f.read())) |
49 | |
50 for error in ERRORS: | |
51 if error['Code'] >= START_PLUGINS: | |
52 print('ERROR: Error code must be below %d, but "%s" is set to %d' % (START_PLUGINS, error['Name'], error['Code'])) | |
53 sys.exit(-1) | |
47 | 54 |
48 with open(os.path.join(BASE, 'Core', 'Enumerations.h'), 'r') as f: | 55 with open(os.path.join(BASE, 'Core', 'Enumerations.h'), 'r') as f: |
49 a = f.read() | 56 a = f.read() |
50 | 57 |
51 HTTP = {} | 58 HTTP = {} |
61 path = os.path.join(BASE, 'Core', 'Enumerations.h') | 68 path = os.path.join(BASE, 'Core', 'Enumerations.h') |
62 with open(path, 'r') as f: | 69 with open(path, 'r') as f: |
63 a = f.read() | 70 a = f.read() |
64 | 71 |
65 s = ',\n'.join(map(lambda x: ' ErrorCode_%s = %d /*!< %s */' % (x['Name'], int(x['Code']), x['Description']), ERRORS)) | 72 s = ',\n'.join(map(lambda x: ' ErrorCode_%s = %d /*!< %s */' % (x['Name'], int(x['Code']), x['Description']), ERRORS)) |
73 | |
74 s += ',\n ErrorCode_START_PLUGINS = %d' % START_PLUGINS | |
66 a = re.sub('(enum ErrorCode\s*{)[^}]*?(\s*};)', r'\1\n%s\2' % s, a, re.DOTALL) | 75 a = re.sub('(enum ErrorCode\s*{)[^}]*?(\s*};)', r'\1\n%s\2' % s, a, re.DOTALL) |
67 | 76 |
68 with open(path, 'w') as f: | 77 with open(path, 'w') as f: |
69 f.write(a) | 78 f.write(a) |
70 | 79 |