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

Skip to content

Commit 051db58

Browse files
committed
Minor tweaking to --update
1 parent 44adbc5 commit 051db58

1 file changed

Lines changed: 29 additions & 6 deletions

File tree

lib/core/update.py

Lines changed: 29 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import shutil
2929
import sys
3030
import tempfile
31+
import time
3132
import urlparse
3233
import zipfile
3334

@@ -37,9 +38,9 @@
3738
from subprocess import PIPE
3839
from subprocess import Popen as execute
3940

40-
from lib.core.common import readInput
41-
from lib.core.common import pollProcess
4241
from lib.core.common import dataToStdout
42+
from lib.core.common import pollProcess
43+
from lib.core.common import readInput
4344
from lib.core.data import conf
4445
from lib.core.data import logger
4546
from lib.core.data import paths
@@ -202,37 +203,59 @@ def __updateMSSQLXML():
202203
logger.info(infoMsg)
203204

204205
def __updateSqlmap():
205-
infoMsg = "updating sqlmap directly from the repository"
206+
rootDir = paths.SQLMAP_ROOT_PATH
207+
208+
infoMsg = "updating sqlmap to latest development version from the "
209+
infoMsg += "subversion repository"
206210
logger.info(infoMsg)
207-
rootDir = os.path.dirname(os.path.realpath(sys.argv[0]))
211+
208212
try:
209213
import pysvn
214+
215+
debugMsg = "sqlmap will update itself using installed python-svn "
216+
debugMsg += "third-party library, http://pysvn.tigris.org/"
217+
logger.debug(debugMsg)
218+
210219
def notify(event_dict):
211220
action = str(event_dict['action'])
221+
212222
if action.find('_update') != -1:
213223
return
224+
214225
index = action.find('_')
215226
prefix = action[index + 1].upper() if index != -1 else action.capitalize()
227+
216228
if action.find('_completed') == -1:
217229
print "%s %s" % (prefix, event_dict['path'])
218230
else:
219231
revision = str(event_dict['revision'])
220232
index = revision.find('number ')
233+
221234
if index != -1:
222235
revision = revision[index+7:].strip('>')
236+
223237
logger.info('updated to the latest revision %s' % revision)
238+
224239
client = pysvn.Client()
225240
client.callback_notify = notify
226241
client.update(rootDir)
227-
except ImportError:
228-
process = execute("svn update %s" % (rootDir), shell=True, stdout=None, stderr=PIPE)
242+
except ImportError, _:
243+
debugMsg = "sqlmap will try to update itself using 'svn' command"
244+
logger.debug(debugMsg)
245+
246+
process = execute("svn update %s" % rootDir, shell=True, stdout=PIPE, stderr=PIPE)
229247

248+
dataToStdout("\r[%s] [INFO] update in progress " % time.strftime("%X"))
230249
pollProcess(process)
231250
svnStdout, svnStderr = process.communicate()
232251

233252
if svnStderr:
234253
errMsg = svnStderr.strip()
235254
logger.error(errMsg)
255+
elif svnStdout:
256+
revision = re.search("revision\s+([\d]+)", svnStdout, re.I)
257+
if revision:
258+
logger.info('updated to the latest revision %s' % revision.group(1))
236259

237260
def update():
238261
if not conf.updateAll:

0 commit comments

Comments
 (0)