1
0
mirror of https://github.com/nmap/nmap.git synced 2026-01-21 21:59:08 +00:00

Merge #2088: Update Zenmap to Python 3 and PyGObject

Note: Ndiff build will be broken until subsequent changes are made.
Deprecation warnings will need to be addressed in future changes.
Closes #2088
This commit is contained in:
dmiller
2022-12-07 20:34:03 +00:00
parent e2e55660c3
commit 24b26317c7
104 changed files with 5381 additions and 4383 deletions

View File

@@ -1,5 +1,4 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#!/usr/bin/env python3
# ***********************IMPORTANT NMAP LICENSE TERMS************************
# * *
@@ -62,7 +61,7 @@ import imp
import os
import signal
import sys
import ConfigParser
import configparser
import shutil
# Cause an exception if PyGTK can't open a display. Normally this just
@@ -74,7 +73,9 @@ import shutil
import warnings
warnings.filterwarnings("error", module="gtk", append="True")
try:
import gtk
import gi
gi.require_version("Gtk", "3.0")
from gi.repository import Gtk, Gdk
except Exception:
# On Mac OS X 10.5, X11 is supposed to be automatically launched on demand.
# It works by setting the DISPLAY environment variable to something like
@@ -86,7 +87,9 @@ except Exception:
# startup scripts, and for some reason the first connection (the one that
# caused the launch) is rejected. But somehow subsequent connections work
# fine! So if the import fails, try one more time.
import gtk
import gi
gi.require_version("Gtk", "3.0")
from gi.repository import Gtk, Gdk
warnings.resetwarnings()
from zenmapGUI.higwidgets.higdialogs import HIGAlertDialog
@@ -103,17 +106,17 @@ from zenmapCore.Name import APP_DISPLAY_NAME
from zenmapGUI.higwidgets.higdialogs import HIGAlertDialog
# A global list of open scan windows. When the last one is destroyed, we call
# gtk.main_quit.
# Gtk.main_quit.
open_windows = []
def _destroy_callback(window):
open_windows.remove(window)
if len(open_windows) == 0:
gtk.main_quit()
Gtk.main_quit()
try:
from zenmapCore.UmitDB import UmitDB
except ImportError, e:
except ImportError as e:
log.debug(">>> Not cleaning up database: %s." % str(e))
else:
# Cleaning up data base
@@ -160,29 +163,31 @@ def install_excepthook():
# produces a warning, but the lack of a display eventually causes a
# segmentation fault. See http://live.gnome.org/PyGTK/WhatsNew210.
warnings.filterwarnings("error", module="gtk")
import gtk
import gi
gi.require_version("Gtk", "3.0")
from gi.repository import Gtk, Gdk
warnings.resetwarnings()
gtk.gdk.threads_enter()
Gdk.threads_enter()
from zenmapGUI.higwidgets.higdialogs import HIGAlertDialog
from zenmapGUI.CrashReport import CrashReport
if type == ImportError:
d = HIGAlertDialog(type=gtk.MESSAGE_ERROR,
d = HIGAlertDialog(type=Gtk.MessageType.ERROR,
message_format=_("Import error"),
secondary_text=_("""A required module was not found.
""" + unicode(value)))
""" + str(value)))
d.run()
d.destroy()
else:
c = CrashReport(type, value, tb)
c.show_all()
gtk.main()
Gtk.main()
gtk.gdk.threads_leave()
Gdk.threads_leave()
gtk.main_quit()
Gtk.main_quit()
sys.excepthook = excepthook
@@ -215,7 +220,7 @@ def run():
# template directory.
create_user_config_dir(
Path.user_config_dir, Path.config_dir)
except (IOError, OSError), e:
except (IOError, OSError) as e:
error_dialog = HIGAlertDialog(
message_format=_(
"Error creating the per-user configuration directory"),
@@ -239,7 +244,7 @@ scan profiles. Check for access to the directory and try again.""") % (
try:
# Read the ~/.zenmap/zenmap.conf configuration file.
zenmapCore.UmitConf.config_parser.read(Path.user_config_file)
except ConfigParser.ParsingError, e:
except configparser.ParsingError as e:
# ParsingError can leave some values as lists instead of strings. Just
# blow it all away if we have this problem.
zenmapCore.UmitConf.config_parser = zenmapCore.UmitConf.config_parser.__class__()
@@ -258,7 +263,7 @@ until it is repaired.""") % (Path.user_config_file, str(e), APP_DISPLAY_NAME)
error_dialog.destroy()
global_config_path = os.path.join(Path.config_dir, APP_NAME + '.conf')
repair_dialog = HIGAlertDialog(
type=gtk.MESSAGE_QUESTION,
type=Gtk.MessageType.QUESTION,
message_format=_("Restore default configuration?"),
secondary_text=_("""\
To avoid further errors parsing the configuration file %s, \
@@ -267,9 +272,9 @@ you can copy the default configuration from %s.
Do this now? \
""") % (Path.user_config_file, global_config_path),
)
repair_dialog.add_button(gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL)
repair_dialog.set_default_response(gtk.RESPONSE_CANCEL)
if repair_dialog.run() == gtk.RESPONSE_OK:
repair_dialog.add_button(Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL)
repair_dialog.set_default_response(Gtk.ResponseType.CANCEL)
if repair_dialog.run() == Gtk.ResponseType.OK:
shutil.copyfile(global_config_path, Path.user_config_file)
log.debug(">>> Copy %s to %s." % (global_config_path, Path.user_config_file))
repair_dialog.destroy()
@@ -316,13 +321,13 @@ Do this now? \
if main_is_frozen():
# This is needed by py2exe
gtk.gdk.threads_init()
gtk.gdk.threads_enter()
Gdk.threads_init()
Gdk.threads_enter()
gtk.main()
Gtk.main()
if main_is_frozen():
gtk.gdk.threads_leave()
Gdk.threads_leave()
class NonRootWarning (HIGAlertDialog):