From 3d9b44cb508fc625986ff2d47e9995edd13138d6 Mon Sep 17 00:00:00 2001 From: Steven Hollingsworth Date: Thu, 17 Jun 2021 16:39:35 -0700 Subject: [PATCH 1/2] fixes #439 - module namespace conflict --- ui/opensnitch/config.py | 2 +- ui/opensnitch/dialogs/preferences.py | 10 +++++----- ui/opensnitch/dialogs/processdetails.py | 8 ++++---- ui/opensnitch/dialogs/prompt.py | 9 ++++----- ui/opensnitch/dialogs/ruleseditor.py | 12 ++++++------ ui/opensnitch/dialogs/stats.py | 18 +++++++++--------- ui/opensnitch/nodes.py | 4 ++-- ui/opensnitch/service.py | 24 ++++++++++++------------ ui/opensnitch/utils.py | 2 +- 9 files changed, 44 insertions(+), 45 deletions(-) diff --git a/ui/opensnitch/config.py b/ui/opensnitch/config.py index 83f903cf61..daea008476 100644 --- a/ui/opensnitch/config.py +++ b/ui/opensnitch/config.py @@ -1,6 +1,6 @@ import os from PyQt5 import QtCore -from database import Database +from opensnitch.database import Database class Config: __instance = None diff --git a/ui/opensnitch/dialogs/preferences.py b/ui/opensnitch/dialogs/preferences.py index 72db03390b..c1255f2750 100644 --- a/ui/opensnitch/dialogs/preferences.py +++ b/ui/opensnitch/dialogs/preferences.py @@ -6,12 +6,12 @@ from PyQt5 import QtCore, QtGui, uic, QtWidgets from PyQt5.QtCore import QCoreApplication as QC -from config import Config -from nodes import Nodes -from database import Database -from utils import Message +from opensnitch.config import Config +from opensnitch.nodes import Nodes +from opensnitch.database import Database +from opensnitch.utils import Message -import ui_pb2 +from opensnitch import ui_pb2 DIALOG_UI_PATH = "%s/../res/preferences.ui" % os.path.dirname(sys.modules[__name__].__file__) class PreferencesDialog(QtWidgets.QDialog, uic.loadUiType(DIALOG_UI_PATH)[0]): diff --git a/ui/opensnitch/dialogs/processdetails.py b/ui/opensnitch/dialogs/processdetails.py index 2f276debe7..0368dd5336 100644 --- a/ui/opensnitch/dialogs/processdetails.py +++ b/ui/opensnitch/dialogs/processdetails.py @@ -4,10 +4,10 @@ from PyQt5 import QtCore, QtGui, uic, QtWidgets -import ui_pb2 -from nodes import Nodes -from desktop_parser import LinuxDesktopParser -from utils import Message +from opensnitch import ui_pb2 +from opensnitch.nodes import Nodes +from opensnitch.desktop_parser import LinuxDesktopParser +from opensnitch.utils import Message DIALOG_UI_PATH = "%s/../res/process_details.ui" % os.path.dirname(sys.modules[__name__].__file__) class ProcessDetailsDialog(QtWidgets.QDialog, uic.loadUiType(DIALOG_UI_PATH)[0]): diff --git a/ui/opensnitch/dialogs/prompt.py b/ui/opensnitch/dialogs/prompt.py index 5e216ca7fe..855e6b94cf 100644 --- a/ui/opensnitch/dialogs/prompt.py +++ b/ui/opensnitch/dialogs/prompt.py @@ -12,11 +12,10 @@ from slugify import slugify -from desktop_parser import LinuxDesktopParser -from config import Config -from version import version - -import ui_pb2 +from opensnitch.desktop_parser import LinuxDesktopParser +from opensnitch.config import Config +from opensnitch.version import version +from opensnitch import ui_pb2 DIALOG_UI_PATH = "%s/../res/prompt.ui" % os.path.dirname(sys.modules[__name__].__file__) class PromptDialog(QtWidgets.QDialog, uic.loadUiType(DIALOG_UI_PATH)[0]): diff --git a/ui/opensnitch/dialogs/ruleseditor.py b/ui/opensnitch/dialogs/ruleseditor.py index 28994a23e9..770b8c4d9e 100644 --- a/ui/opensnitch/dialogs/ruleseditor.py +++ b/ui/opensnitch/dialogs/ruleseditor.py @@ -7,15 +7,15 @@ import json import sys import os -import ui_pb2 +from opensnitch import ui_pb2 import time import ipaddress -from config import Config -from nodes import Nodes -from database import Database -from version import version -from utils import Message, FileDialog +from opensnitch.config import Config +from opensnitch.nodes import Nodes +from opensnitch.database import Database +from opensnitch.version import version +from opensnitch.utils import Message, FileDialog DIALOG_UI_PATH = "%s/../res/ruleseditor.ui" % os.path.dirname(sys.modules[__name__].__file__) class RulesEditorDialog(QtWidgets.QDialog, uic.loadUiType(DIALOG_UI_PATH)[0]): diff --git a/ui/opensnitch/dialogs/stats.py b/ui/opensnitch/dialogs/stats.py index 8c4a7e5feb..78ee62fb96 100644 --- a/ui/opensnitch/dialogs/stats.py +++ b/ui/opensnitch/dialogs/stats.py @@ -7,15 +7,15 @@ from PyQt5 import QtCore, QtGui, uic, QtWidgets from PyQt5.QtCore import QCoreApplication as QC -import ui_pb2 -from config import Config -from version import version -from nodes import Nodes -from dialogs.preferences import PreferencesDialog -from dialogs.ruleseditor import RulesEditorDialog -from dialogs.processdetails import ProcessDetailsDialog -from customwidgets import ColorizedDelegate, ConnectionsTableModel -from utils import Message +from opensnitch import ui_pb2 +from opensnitch.config import Config +from opensnitch.version import version +from opensnitch.nodes import Nodes +from opensnitch.dialogs.preferences import PreferencesDialog +from opensnitch.dialogs.ruleseditor import RulesEditorDialog +from opensnitch.dialogs.processdetails import ProcessDetailsDialog +from opensnitch.customwidgets import ColorizedDelegate, ConnectionsTableModel +from opensnitch.utils import Message DIALOG_UI_PATH = "%s/../res/stats.ui" % os.path.dirname(sys.modules[__name__].__file__) class StatsDialog(QtWidgets.QDialog, uic.loadUiType(DIALOG_UI_PATH)[0]): diff --git a/ui/opensnitch/nodes.py b/ui/opensnitch/nodes.py index a0f3eb4370..7250fcd5db 100644 --- a/ui/opensnitch/nodes.py +++ b/ui/opensnitch/nodes.py @@ -3,8 +3,8 @@ import time import json -import ui_pb2 -from database import Database +from opensnitch import ui_pb2 +from opensnitch.database import Database class Nodes(): __instance = None diff --git a/ui/opensnitch/service.py b/ui/opensnitch/service.py index 228966f1d6..89188b5262 100644 --- a/ui/opensnitch/service.py +++ b/ui/opensnitch/service.py @@ -9,18 +9,18 @@ path = os.path.abspath(os.path.dirname(__file__)) sys.path.append(path) -import ui_pb2 -import ui_pb2_grpc - -from dialogs.prompt import PromptDialog -from dialogs.stats import StatsDialog - -from nodes import Nodes -from config import Config -from version import version -from database import Database -from utils import Utils -from version import version +from opensnitch import ui_pb2 +from opensnitch import ui_pb2_grpc + +from opensnitch.dialogs.prompt import PromptDialog +from opensnitch.dialogs.stats import StatsDialog + +from opensnitch.nodes import Nodes +from opensnitch.config import Config +from opensnitch.version import version +from opensnitch.database import Database +from opensnitch.utils import Utils +from opensnitch.version import version class UIService(ui_pb2_grpc.UIServicer, QtWidgets.QGraphicsObject): _new_remote_trigger = QtCore.pyqtSignal(str, ui_pb2.PingRequest) diff --git a/ui/opensnitch/utils.py b/ui/opensnitch/utils.py index 1b941126e8..45817eb89d 100644 --- a/ui/opensnitch/utils.py +++ b/ui/opensnitch/utils.py @@ -1,6 +1,6 @@ from PyQt5 import QtCore, QtWidgets -from version import version +from opensnitch.version import version import pwd import socket import fcntl From de559dccf80afc63325f7980de89ee96a080d0e6 Mon Sep 17 00:00:00 2001 From: Steven Hollingsworth Date: Fri, 18 Jun 2021 12:54:17 -0700 Subject: [PATCH 2/2] Changed import ui_pb2 from global to relative --- ui/Makefile | 1 + 1 file changed, 1 insertion(+) diff --git a/ui/Makefile b/ui/Makefile index 039c3703a4..0976022bab 100644 --- a/ui/Makefile +++ b/ui/Makefile @@ -5,6 +5,7 @@ install: opensnitch/resources_rc.py: translations deps @pyrcc5 -o opensnitch/resources_rc.py opensnitch/res/resources.qrc + sed -i 's/^import ui_pb2/from . import ui_pb2/' opensnitch/ui_pb2* translations: @cd i18n ; make