diff options
author | Eliot Horowitz <eliot@10gen.com> | 2010-07-19 15:37:19 -0400 |
---|---|---|
committer | Eliot Horowitz <eliot@10gen.com> | 2010-07-19 15:37:19 -0400 |
commit | 4b50326dbcafb876dacfcaeac13e4a50df345f4e (patch) | |
tree | b7a97aa3f80fa3ce5b9679d4455f03b076374147 /buildscripts/errorcodes.py | |
parent | 671778afa957f14a78214b6c426237e899c2ed14 (diff) | |
download | mongo-4b50326dbcafb876dacfcaeac13e4a50df345f4e.tar.gz |
cleaning and error code stuff
Diffstat (limited to 'buildscripts/errorcodes.py')
-rwxr-xr-x | buildscripts/errorcodes.py | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/buildscripts/errorcodes.py b/buildscripts/errorcodes.py index a9243128c5a..d87b7adc520 100755 --- a/buildscripts/errorcodes.py +++ b/buildscripts/errorcodes.py @@ -3,6 +3,7 @@ import os import sys import re +import utils def getAllSourceFiles( arr=None , prefix="." ): if arr is None: @@ -43,6 +44,8 @@ def assignErrorCodes(): out.close() +codes = [] + def readErrorCodes( callback ): ps = [ re.compile( "([um]asser(t|ted)) *\( *(\d+)" ) , re.compile( "(User|Msg)Exceptio(n)\( *(\d+)" ) @@ -52,6 +55,7 @@ def readErrorCodes( callback ): for line in open( x ): for p in ps: for m in p.findall( line ): + codes.append( ( x , lineNum , line , m[2] ) ) callback( x , lineNum , line , m[2] ) lineNum = lineNum + 1 @@ -78,8 +82,57 @@ def checkErrorCodes(): readErrorCodes( checkDups ) return len( errors ) == 0 +def getBestMessage( err , start ): + err = err.partition( start )[2] + if not err: + return "" + err = err.partition( "\"" )[2] + if not err: + return "" + err = err.rpartition( "\"" )[0] + if not err: + return "" + return err + +def genErrorOutput(): + + g = utils.getGitVersion() + + if os.path.exists( "docs/errors.md" ): + i = open( "docs/errors.md" , "r" ) + + + out = open( "docs/errors.md" , 'w' ) + out.write( "MongoDB Error Codes\n==========\n\n\n" ) + + prev = "" + seen = {} + + codes.sort( key=lambda x: x[0]+"-"+x[3] ) + for f,l,line,num in codes: + if num in seen: + continue + seen[num] = True + + if f.startswith( "./" ): + f = f[2:] + + if f != prev: + out.write( "\n\n" ) + out.write( f + "\n----\n" ) + prev = f + + url = "http://github.com/mongodb/mongo/blob/" + g + "/" + f + "#L" + str(l) + + out.write( "* " + str(num) + " [code](" + url + ") " + getBestMessage( line , str(num) ) + "\n" ) + + out.write( "\n" ) + out.close() + if __name__ == "__main__": ok = checkErrorCodes() print( "ok:" + str( ok ) ) print( "next: " + str( getNextCode() ) ) + if ok: + genErrorOutput() |