Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 8eefe4b

Browse files
committed
Getting back revision number - displayed like in GitHub commits (Issue #52)
1 parent add8352 commit 8eefe4b

4 files changed

Lines changed: 24 additions & 56 deletions

File tree

lib/core/common.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2489,7 +2489,7 @@ def unhandledExceptionMessage():
24892489
errMsg += "and any information required to reproduce the bug. The "
24902490
errMsg += "developers will try to reproduce the bug, fix it accordingly "
24912491
errMsg += "and get back to you.\n"
2492-
errMsg += "sqlmap version: %s%s\n" % (VERSION, " (r%d)" % REVISION if REVISION else "")
2492+
errMsg += "sqlmap version: %s%s\n" % (VERSION, " (%s)" % REVISION if REVISION else "")
24932493
errMsg += "Python version: %s\n" % PYVERSION
24942494
errMsg += "Operating system: %s\n" % PLATFORM
24952495
errMsg += "Command line: %s\n" % " ".join(sys.argv)

lib/core/revision.py

Lines changed: 22 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -12,50 +12,29 @@
1212
from subprocess import Popen as execute
1313

1414
def getRevisionNumber():
15-
curDir = os.path.dirname(os.path.realpath(__file__))
1615
retVal = None
17-
18-
try:
19-
import pysvn
20-
21-
client = pysvn.Client()
22-
if client.info(curDir):
23-
retVal = client.info(curDir).revision.number
24-
except ImportError:
25-
process = execute("svn info %s" % curDir, shell=True, stdout=PIPE, stderr=PIPE)
26-
svnStdout, svnStderr = process.communicate()
27-
28-
if svnStdout:
29-
revision = re.search("Revision:\s+([\d]+)", svnStdout)
30-
31-
if revision:
32-
retVal = revision.group(1)
33-
except:
34-
pass
35-
36-
if not retVal:
37-
# Reference: http://stackoverflow.com/questions/242295/how-does-one-add-a-svn-repository-build-number-to-python-code
38-
entriesPath = '%s/.svn/entries' % curDir
39-
40-
if os.path.exists(entriesPath):
41-
entries = open(entriesPath, 'r').read()
42-
# Versions >= 7 of the entries file are flat text. The first line is
43-
# the version number. The next set of digits after 'dir' is the revision.
44-
if re.match('(\d+)', entries):
45-
match = re.search('\d+\s+dir\s+(\d+)', entries)
46-
if match:
47-
retVal = match.groups()[0]
48-
# Older XML versions of the file specify revision as an attribute of
49-
# the first entries node.
16+
filePath = None
17+
18+
_ = os.path.dirname(__file__)
19+
while True:
20+
filePath = os.path.join(_, ".git/refs/heads/master").replace('/', os.path.sep)
21+
if os.path.exists(filePath):
22+
break
23+
else:
24+
filePath = None
25+
if _ == os.path.dirname(_):
26+
break
5027
else:
51-
from xml.dom import minidom
52-
dom = minidom.parse(entriesPath)
53-
retVal = dom.getElementsByTagName('entry')[0].getAttribute('revision')
28+
_ = os.path.dirname(_)
29+
if filePath:
30+
with open(filePath, "r") as f:
31+
match = re.match(r"(?i)[0-9a-f]{32}", f.read())
32+
retVal = match.group(0) if match else None
5433

55-
if retVal:
56-
try:
57-
retVal = int(retVal)
58-
except ValueError:
59-
retVal = None
34+
if not retVal:
35+
process = execute("git rev-parse --verify HEAD", shell=True, stdout=PIPE, stderr=PIPE)
36+
stdout, _ = process.communicate()
37+
match = re.search(r"(?i)[0-9a-f]{32}", stdout or "")
38+
retVal = match.group(0) if match else None
6039

61-
return retVal
40+
return retVal[:10] if retVal else None

lib/core/settings.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
# sqlmap version and site
2121
VERSION = "1.0-dev"
2222
REVISION = getRevisionNumber()
23-
VERSION_STRING = "sqlmap/%s%s" % (VERSION, " (r%s)" % REVISION if REVISION else "")
23+
VERSION_STRING = "sqlmap/%s%s" % (VERSION, " (%s)" % REVISION if REVISION else "")
2424
DESCRIPTION = "automatic SQL injection and database takeover tool"
2525
SITE = "http://www.sqlmap.org"
2626

lib/utils/deps.py

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -73,17 +73,6 @@ def checkDependencies():
7373
logger.warn(warnMsg)
7474
missing_libraries.add('python-ntlm')
7575

76-
try:
77-
import pysvn
78-
debugMsg = "'python-svn' third-party library is found"
79-
logger.debug(debugMsg)
80-
except ImportError, _:
81-
warnMsg = "sqlmap requires 'python-svn' third-party library for "
82-
warnMsg += "if you want to use the sqlmap update functionality. "
83-
warnMsg += "Download from http://pysvn.tigris.org/"
84-
logger.warn(warnMsg)
85-
missing_libraries.add('python-svn')
86-
8776
if IS_WIN:
8877
try:
8978
import pyreadline

0 commit comments

Comments
 (0)