added support for displaying revision number at unhandled exception message

This commit is contained in:
Miroslav Stampar 2010-10-19 08:55:14 +00:00
parent 9a7fd29d4f
commit 264e0a6fda
4 changed files with 45 additions and 2 deletions

View File

@ -10,6 +10,7 @@ See the file 'doc/COPYING' for copying permission
from lib.core.settings import PLATFORM from lib.core.settings import PLATFORM
from lib.core.settings import PYVERSION from lib.core.settings import PYVERSION
from lib.core.settings import VERSION from lib.core.settings import VERSION
from lib.core.settings import REVISION
from lib.core.settings import VERSION_STRING from lib.core.settings import VERSION_STRING
@ -75,7 +76,7 @@ def unhandledException():
errMsg += "following text and any information needed to reproduce the " errMsg += "following text and any information needed to reproduce the "
errMsg += "bug. The developers will try to reproduce the bug, fix it " errMsg += "bug. The developers will try to reproduce the bug, fix it "
errMsg += "accordingly and get back to you.\n" errMsg += "accordingly and get back to you.\n"
errMsg += "sqlmap version: %s\n" % VERSION errMsg += "sqlmap version: %s%s\n" % (VERSION, " (r%d)" % REVISION if REVISION else "")
errMsg += "Python version: %s\n" % PYVERSION errMsg += "Python version: %s\n" % PYVERSION
errMsg += "Operating system: %s" % PLATFORM errMsg += "Operating system: %s" % PLATFORM
return errMsg return errMsg

39
lib/core/revision.py Normal file
View File

@ -0,0 +1,39 @@
import os
import re
from subprocess import PIPE
from subprocess import Popen as execute
def getRevisionNumber():
curDir = os.path.dirname(os.path.realpath(__file__))
retVal = None
try:
import pysvn
client = pysvn.Client()
if client.info(curDir):
retVal = client.info(curDir).revision.number
except ImportError, _:
process = execute("svn info %s" % curDir, shell=True, stdout=PIPE, stderr=PIPE)
svnStdout, svnStderr = process.communicate()
if svnStdout:
revision = re.search("Revision:\s+([\d]+)", svnStdout)
if revision:
retVal = revision.group(1)
if retVal:
try:
retVal = int(retVal)
except ValueError:
retVal = None
#if not retVal:
#debugMsg = "sqlmap was not able to retrieve the revision number"
#logger.debug(debugMsg)
return retVal

View File

@ -12,8 +12,11 @@ import os
import subprocess import subprocess
import sys import sys
from lib.core.revision import getRevisionNumber
# sqlmap version and site # sqlmap version and site
VERSION = "0.9-dev" VERSION = "0.9-dev"
REVISION = getRevisionNumber()
VERSION_STRING = "sqlmap/%s" % VERSION VERSION_STRING = "sqlmap/%s" % VERSION
DESCRIPTION = "automatic SQL injection and database takeover tool" DESCRIPTION = "automatic SQL injection and database takeover tool"
SITE = "http://sqlmap.sourceforge.net" SITE = "http://sqlmap.sourceforge.net"