mirror of
				https://github.com/sqlmapproject/sqlmap.git
				synced 2025-10-31 07:57:47 +03:00 
			
		
		
		
	Getting back revision number - displayed like in GitHub commits (Issue #52)
This commit is contained in:
		
							parent
							
								
									add8352804
								
							
						
					
					
						commit
						8eefe4b71f
					
				|  | @ -2489,7 +2489,7 @@ def unhandledExceptionMessage(): | ||||||
|     errMsg += "and any information required to reproduce the bug. The " |     errMsg += "and any information required to reproduce the bug. The " | ||||||
|     errMsg += "developers will try to reproduce the bug, fix it accordingly " |     errMsg += "developers will try to reproduce the bug, fix it accordingly " | ||||||
|     errMsg += "and get back to you.\n" |     errMsg += "and get back to you.\n" | ||||||
|     errMsg += "sqlmap version: %s%s\n" % (VERSION, " (r%d)" % REVISION if REVISION else "") |     errMsg += "sqlmap version: %s%s\n" % (VERSION, " (%s)" % REVISION if REVISION else "") | ||||||
|     errMsg += "Python version: %s\n" % PYVERSION |     errMsg += "Python version: %s\n" % PYVERSION | ||||||
|     errMsg += "Operating system: %s\n" % PLATFORM |     errMsg += "Operating system: %s\n" % PLATFORM | ||||||
|     errMsg += "Command line: %s\n" % " ".join(sys.argv) |     errMsg += "Command line: %s\n" % " ".join(sys.argv) | ||||||
|  |  | ||||||
|  | @ -12,50 +12,29 @@ from subprocess import PIPE | ||||||
| from subprocess import Popen as execute | from subprocess import Popen as execute | ||||||
| 
 | 
 | ||||||
| def getRevisionNumber(): | def getRevisionNumber(): | ||||||
|     curDir = os.path.dirname(os.path.realpath(__file__)) |  | ||||||
|     retVal = None |     retVal = None | ||||||
|  |     filePath = None | ||||||
| 
 | 
 | ||||||
|     try: |     _ = os.path.dirname(__file__) | ||||||
|         import pysvn |     while True: | ||||||
| 
 |         filePath = os.path.join(_, ".git/refs/heads/master").replace('/', os.path.sep) | ||||||
|         client = pysvn.Client() |         if os.path.exists(filePath): | ||||||
|         if client.info(curDir): |             break | ||||||
|             retVal = client.info(curDir).revision.number |         else: | ||||||
|     except ImportError: |             filePath = None | ||||||
|         process = execute("svn info %s" % curDir, shell=True, stdout=PIPE, stderr=PIPE) |             if _ == os.path.dirname(_): | ||||||
|         svnStdout, svnStderr = process.communicate() |                 break | ||||||
| 
 |             else: | ||||||
|         if svnStdout: |                 _ = os.path.dirname(_) | ||||||
|             revision = re.search("Revision:\s+([\d]+)", svnStdout) |     if filePath: | ||||||
| 
 |         with open(filePath, "r") as f: | ||||||
|             if revision: |             match = re.match(r"(?i)[0-9a-f]{32}", f.read()) | ||||||
|                 retVal = revision.group(1) |             retVal = match.group(0) if match else None | ||||||
|     except: |  | ||||||
|         pass |  | ||||||
| 
 | 
 | ||||||
|     if not retVal: |     if not retVal: | ||||||
|         # Reference: http://stackoverflow.com/questions/242295/how-does-one-add-a-svn-repository-build-number-to-python-code |         process = execute("git rev-parse --verify HEAD", shell=True, stdout=PIPE, stderr=PIPE) | ||||||
|         entriesPath = '%s/.svn/entries' % curDir |         stdout, _ = process.communicate() | ||||||
|  |         match = re.search(r"(?i)[0-9a-f]{32}", stdout or "") | ||||||
|  |         retVal = match.group(0) if match else None | ||||||
| 
 | 
 | ||||||
|         if os.path.exists(entriesPath): |     return retVal[:10] if retVal else None | ||||||
|             entries = open(entriesPath, 'r').read() |  | ||||||
|             # Versions >= 7 of the entries file are flat text.  The first line is |  | ||||||
|             # the version number. The next set of digits after 'dir' is the revision. |  | ||||||
|             if re.match('(\d+)', entries): |  | ||||||
|                 match = re.search('\d+\s+dir\s+(\d+)', entries) |  | ||||||
|                 if match: |  | ||||||
|                     retVal = match.groups()[0] |  | ||||||
|             # Older XML versions of the file specify revision as an attribute of |  | ||||||
|             # the first entries node. |  | ||||||
|             else: |  | ||||||
|                 from xml.dom import minidom |  | ||||||
|                 dom = minidom.parse(entriesPath) |  | ||||||
|                 retVal = dom.getElementsByTagName('entry')[0].getAttribute('revision') |  | ||||||
| 
 |  | ||||||
|     if retVal: |  | ||||||
|         try: |  | ||||||
|             retVal = int(retVal) |  | ||||||
|         except ValueError: |  | ||||||
|             retVal = None |  | ||||||
| 
 |  | ||||||
|     return retVal |  | ||||||
|  |  | ||||||
|  | @ -20,7 +20,7 @@ from lib.core.revision import getRevisionNumber | ||||||
| # sqlmap version and site | # sqlmap version and site | ||||||
| VERSION = "1.0-dev" | VERSION = "1.0-dev" | ||||||
| REVISION = getRevisionNumber() | REVISION = getRevisionNumber() | ||||||
| VERSION_STRING = "sqlmap/%s%s" % (VERSION, " (r%s)" % REVISION if REVISION else "") | VERSION_STRING = "sqlmap/%s%s" % (VERSION, " (%s)" % REVISION if REVISION else "") | ||||||
| DESCRIPTION = "automatic SQL injection and database takeover tool" | DESCRIPTION = "automatic SQL injection and database takeover tool" | ||||||
| SITE = "http://www.sqlmap.org" | SITE = "http://www.sqlmap.org" | ||||||
| ML = "sqlmap-users@lists.sourceforge.net" | ML = "sqlmap-users@lists.sourceforge.net" | ||||||
|  |  | ||||||
|  | @ -73,17 +73,6 @@ def checkDependencies(): | ||||||
|         logger.warn(warnMsg) |         logger.warn(warnMsg) | ||||||
|         missing_libraries.add('python-ntlm') |         missing_libraries.add('python-ntlm') | ||||||
| 
 | 
 | ||||||
|     try: |  | ||||||
|         import pysvn |  | ||||||
|         debugMsg = "'python-svn' third-party library is found" |  | ||||||
|         logger.debug(debugMsg) |  | ||||||
|     except ImportError, _: |  | ||||||
|         warnMsg = "sqlmap requires 'python-svn' third-party library for " |  | ||||||
|         warnMsg += "if you want to use the sqlmap update functionality. " |  | ||||||
|         warnMsg += "Download from http://pysvn.tigris.org/" |  | ||||||
|         logger.warn(warnMsg) |  | ||||||
|         missing_libraries.add('python-svn') |  | ||||||
| 
 |  | ||||||
|     if IS_WIN: |     if IS_WIN: | ||||||
|         try: |         try: | ||||||
|             import pyreadline |             import pyreadline | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue
	
	Block a user