1
0
mirror of https://github.com/nmap/nmap.git synced 2025-12-09 06:01:28 +00:00

Avoid DeprecationWarning due to accessing BaseException.message

This commit is contained in:
dmiller
2019-12-19 05:25:21 +00:00
parent 260fa12cce
commit d0c61b9cbb

View File

@@ -550,42 +550,48 @@ class ScanInterface(HIGVBox):
try: try:
command_execution.run_scan() command_execution.run_scan()
except Exception, e: except OSError, e:
text = unicode(e.message, errors='replace') text = unicode(e.strerror, errors='replace')
if isinstance(e, OSError): # Handle ENOENT specially.
# Handle ENOENT specially. if e.errno == errno.ENOENT:
if e.errno == errno.ENOENT: # nmap_command_path comes from zenmapCore.NmapCommand.
# nmap_command_path comes from zenmapCore.NmapCommand. path_env = os.getenv("PATH")
path_env = os.getenv("PATH") if path_env is None:
if path_env is None: default_paths = []
default_paths = []
else:
fsencoding = sys.getfilesystemencoding()
if fsencoding:
path_env = path_env.decode(fsencoding, 'replace')
default_paths = path_env.split(os.pathsep)
text += u"\n\n{}\n\n{}".format(
_("This means that the nmap executable was "
"not found in your system PATH, which is"),
path_env or _("<undefined>")
)
extra_paths = get_extra_executable_search_paths()
extra_paths = [p for p in extra_paths if (
p not in default_paths)]
if len(extra_paths) > 0:
if len(extra_paths) == 1:
text += u"\n\n" + _("plus the extra directory")
else:
text += u"\n\n" + _("plus the extra directories")
text += u"\n\n" + os.pathsep.join(extra_paths)
else: else:
text += u" (%d)" % e.errno fsencoding = sys.getfilesystemencoding()
if fsencoding:
path_env = path_env.decode(fsencoding, 'replace')
default_paths = path_env.split(os.pathsep)
text += u"\n\n{}\n\n{}".format(
_("This means that the nmap executable was "
"not found in your system PATH, which is"),
path_env or _("<undefined>")
)
extra_paths = get_extra_executable_search_paths()
extra_paths = [p for p in extra_paths if (
p not in default_paths)]
if len(extra_paths) > 0:
if len(extra_paths) == 1:
text += u"\n\n" + _("plus the extra directory")
else:
text += u"\n\n" + _("plus the extra directories")
text += u"\n\n" + os.pathsep.join(extra_paths)
else:
text += u" (%d)" % e.errno
warn_dialog = HIGAlertDialog( warn_dialog = HIGAlertDialog(
message_format=_("Error executing command"), message_format=_("Error executing command"),
secondary_text=text, type=gtk.MESSAGE_ERROR) secondary_text=text, type=gtk.MESSAGE_ERROR)
warn_dialog.run() warn_dialog.run()
warn_dialog.destroy() warn_dialog.destroy()
return return
except Exception, e:
warn_dialog = HIGAlertDialog(
message_format=_("Error executing command"),
secondary_text=unicode(e, errors='replace'), type=gtk.MESSAGE_ERROR)
warn_dialog.run()
warn_dialog.destroy()
return
log.debug("Running command: %s" % command_execution.command) log.debug("Running command: %s" % command_execution.command)
self.jobs.append(command_execution) self.jobs.append(command_execution)