MCPcopy Index your code
hub / github.com/sqlmapproject/sqlmap / update

Function update

lib/core/update.py:35–171  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

33from thirdparty.six.moves import urllib as _urllib
34
35def update():
36 if not conf.updateAll:
37 return
38
39 success = False
40
41 if TYPE == "pip":
42 infoMsg = "updating sqlmap to the latest stable version from the "
43 infoMsg += "PyPI repository"
44 logger.info(infoMsg)
45
46 debugMsg = "sqlmap will try to update itself using 'pip' command"
47 logger.debug(debugMsg)
48
49 dataToStdout("\r[%s] [INFO] update in progress" % time.strftime("%X"))
50
51 output = ""
52 try:
53 process = subprocess.Popen("pip install -U sqlmap", shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, cwd=paths.SQLMAP_ROOT_PATH)
54 pollProcess(process, True)
55 output, _ = process.communicate()
56 success = not process.returncode
57 except Exception as ex:
58 success = False
59 output = getSafeExString(ex)
60 finally:
61 output = getText(output)
62
63 if success:
64 logger.info("%s the latest revision '%s'" % ("already at" if "already up-to-date" in output else "updated to", extractRegexResult(r"\binstalled sqlmap-(?P<result>\d+\.\d+\.\d+)", output) or extractRegexResult(r"\((?P<result>\d+\.\d+\.\d+)\)", output)))
65 else:
66 logger.error("update could not be completed ('%s')" % re.sub(r"[^a-z0-9:/\\]+", " ", output).strip())
67
68 elif not os.path.exists(os.path.join(paths.SQLMAP_ROOT_PATH, ".git")):
69 warnMsg = "not a git repository. It is recommended to clone the 'sqlmapproject/sqlmap' repository "
70 warnMsg += "from GitHub (e.g. 'git clone --depth 1 %s sqlmap')" % GIT_REPOSITORY
71 logger.warning(warnMsg)
72
73 if VERSION == getLatestRevision():
74 logger.info("already at the latest revision '%s'" % (getRevisionNumber() or VERSION))
75 return
76
77 message = "do you want to try to fetch the latest 'zipball' from repository and extract it (experimental) ? [y/N]"
78 if readInput(message, default='N', boolean=True):
79 directory = os.path.abspath(paths.SQLMAP_ROOT_PATH)
80
81 try:
82 open(os.path.join(directory, "sqlmap.py"), "w+b")
83 except Exception as ex:
84 errMsg = "unable to update content of directory '%s' ('%s')" % (directory, getSafeExString(ex))
85 logger.error(errMsg)
86 else:
87 attrs = os.stat(os.path.join(directory, "sqlmap.py")).st_mode
88 for wildcard in ('*', ".*"):
89 for _ in glob.glob(os.path.join(directory, wildcard)):
90 try:
91 if os.path.isdir(_):
92 shutil.rmtree(_)

Callers 1

initFunction · 0.90

Calls 15

dataToStdoutFunction · 0.90
pollProcessFunction · 0.90
getSafeExStringFunction · 0.90
getTextFunction · 0.90
extractRegexResultFunction · 0.90
getLatestRevisionFunction · 0.90
getRevisionNumberFunction · 0.90
readInputFunction · 0.90
openFileFunction · 0.90
infoMethod · 0.80
debugMethod · 0.80
removeMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…