|
17 | 17 | generateCSV = config.get('errorcodes','generateCSV')
|
18 | 18 | errorsTitle = config.get('errorcodes', 'Title')
|
19 | 19 | errorsFormat = config.get('errorcodes', 'Format')
|
| 20 | +generateJSON = config.get('errorcodes','generateJSON') |
20 | 21 |
|
21 | 22 | default_domain = "\n\n.. default-domain:: mongodb\n\n"
|
22 | 23 |
|
@@ -73,6 +74,7 @@ def assignErrorCodes():
|
73 | 74 |
|
74 | 75 |
|
75 | 76 | codes = []
|
| 77 | +messages = {} |
76 | 78 |
|
77 | 79 | def readErrorCodes():
|
78 | 80 | """Open each source file in sourceroot and scan for potential error messages."""
|
@@ -101,6 +103,8 @@ def readErrorCodes():
|
101 | 103 | lineNum = 1
|
102 | 104 |
|
103 | 105 | stripChars = " " + "\n"
|
| 106 | + sourcerootOffset = len(sourceroot) |
| 107 | + |
104 | 108 |
|
105 | 109 | for line in open( x ):
|
106 | 110 |
|
@@ -129,6 +133,21 @@ def repl( m ):
|
129 | 133 | code = m[4]
|
130 | 134 | message = m[5]
|
131 | 135 | codes.append( ( x , lineNum , line , code, message, severity ) )
|
| 136 | + if x.startswith(sourceroot): |
| 137 | + fn = x[sourcerootOffset+1:].rpartition("/2")[2] |
| 138 | +# fn = f.rpartition("/")[2] |
| 139 | + |
| 140 | + msgDICT = { |
| 141 | + 'id': code, |
| 142 | + 'text':message, |
| 143 | + 'sev':severity, |
| 144 | + 'user':'', |
| 145 | + 'sys':'', |
| 146 | + 'ln':lineNum, |
| 147 | + 'f':fn, |
| 148 | + 'src': line.strip(stripChars) |
| 149 | + } |
| 150 | + messages[int(code)] = msgDICT |
132 | 151 |
|
133 | 152 | return start + "(" + spaces + code
|
134 | 153 |
|
@@ -279,4 +298,10 @@ def genErrorOutputCSV():
|
279 | 298 | genErrorOutput()
|
280 | 299 | if (generateCSV == 'yes'):
|
281 | 300 | genErrorOutputCSV()
|
282 |
| - |
| 301 | + if (generateJSON== 'yes'): |
| 302 | + import json |
| 303 | + outputFile = "{}/errorcodes.json".format(resultsRoot) |
| 304 | + out = open(outputFile, 'wb') |
| 305 | + sys.stderr.write("Generating JSON file: {}\n".format(outputFile)) |
| 306 | + out.write(json.dumps(messages)) |
| 307 | + out.close() |
0 commit comments