Minor tweaking to --update

This commit is contained in:
Bernardo Damele 2010-01-18 14:59:24 +00:00
parent 44adbc5776
commit 051db588a5

View File

@ -28,6 +28,7 @@ import re
import shutil import shutil
import sys import sys
import tempfile import tempfile
import time
import urlparse import urlparse
import zipfile import zipfile
@ -37,9 +38,9 @@ from xml.dom.minidom import Document
from subprocess import PIPE from subprocess import PIPE
from subprocess import Popen as execute from subprocess import Popen as execute
from lib.core.common import readInput
from lib.core.common import pollProcess
from lib.core.common import dataToStdout from lib.core.common import dataToStdout
from lib.core.common import pollProcess
from lib.core.common import readInput
from lib.core.data import conf from lib.core.data import conf
from lib.core.data import logger from lib.core.data import logger
from lib.core.data import paths from lib.core.data import paths
@ -202,37 +203,59 @@ def __updateMSSQLXML():
logger.info(infoMsg) logger.info(infoMsg)
def __updateSqlmap(): def __updateSqlmap():
infoMsg = "updating sqlmap directly from the repository" rootDir = paths.SQLMAP_ROOT_PATH
infoMsg = "updating sqlmap to latest development version from the "
infoMsg += "subversion repository"
logger.info(infoMsg) logger.info(infoMsg)
rootDir = os.path.dirname(os.path.realpath(sys.argv[0]))
try: try:
import pysvn import pysvn
debugMsg = "sqlmap will update itself using installed python-svn "
debugMsg += "third-party library, http://pysvn.tigris.org/"
logger.debug(debugMsg)
def notify(event_dict): def notify(event_dict):
action = str(event_dict['action']) action = str(event_dict['action'])
if action.find('_update') != -1: if action.find('_update') != -1:
return return
index = action.find('_') index = action.find('_')
prefix = action[index + 1].upper() if index != -1 else action.capitalize() prefix = action[index + 1].upper() if index != -1 else action.capitalize()
if action.find('_completed') == -1: if action.find('_completed') == -1:
print "%s %s" % (prefix, event_dict['path']) print "%s %s" % (prefix, event_dict['path'])
else: else:
revision = str(event_dict['revision']) revision = str(event_dict['revision'])
index = revision.find('number ') index = revision.find('number ')
if index != -1: if index != -1:
revision = revision[index+7:].strip('>') revision = revision[index+7:].strip('>')
logger.info('updated to the latest revision %s' % revision) logger.info('updated to the latest revision %s' % revision)
client = pysvn.Client() client = pysvn.Client()
client.callback_notify = notify client.callback_notify = notify
client.update(rootDir) client.update(rootDir)
except ImportError: except ImportError, _:
process = execute("svn update %s" % (rootDir), shell=True, stdout=None, stderr=PIPE) debugMsg = "sqlmap will try to update itself using 'svn' command"
logger.debug(debugMsg)
process = execute("svn update %s" % rootDir, shell=True, stdout=PIPE, stderr=PIPE)
dataToStdout("\r[%s] [INFO] update in progress " % time.strftime("%X"))
pollProcess(process) pollProcess(process)
svnStdout, svnStderr = process.communicate() svnStdout, svnStderr = process.communicate()
if svnStderr: if svnStderr:
errMsg = svnStderr.strip() errMsg = svnStderr.strip()
logger.error(errMsg) logger.error(errMsg)
elif svnStdout:
revision = re.search("revision\s+([\d]+)", svnStdout, re.I)
if revision:
logger.info('updated to the latest revision %s' % revision.group(1))
def update(): def update():
if not conf.updateAll: if not conf.updateAll: