From 55df230864434562eb4c889f33bef7ad0e10dc54 Mon Sep 17 00:00:00 2001 From: Mark Paronyan Date: Wed, 30 Sep 2026 20:51:22 +0300 Subject: [PATCH] style: sort imports in controller --- gns3server/controller/__init__.py | 37 ++++++------ gns3server/controller/appliance_manager.py | 39 ++++++------- .../controller/appliance_to_template.py | 1 + gns3server/controller/compute.py | 27 +++++---- gns3server/controller/drawing.py | 11 ++-- gns3server/controller/export_project.py | 15 +++-- gns3server/controller/gns3vm/__init__.py | 17 +++--- gns3server/controller/gns3vm/base_gns3_vm.py | 4 +- .../controller/gns3vm/hyperv_gns3_vm.py | 7 ++- .../controller/gns3vm/remote_gns3_vm.py | 5 +- .../controller/gns3vm/virtualbox_gns3_vm.py | 17 +++--- .../controller/gns3vm/vmware_gns3_vm.py | 5 +- gns3server/controller/import_project.py | 22 +++---- gns3server/controller/link.py | 10 ++-- gns3server/controller/marker_replay.py | 2 +- gns3server/controller/node.py | 24 ++++---- gns3server/controller/notification.py | 1 + gns3server/controller/ports/port_factory.py | 14 ++--- gns3server/controller/project.py | 58 +++++++++---------- gns3server/controller/snapshot.py | 13 ++--- gns3server/controller/symbols.py | 9 ++- gns3server/controller/topology.py | 33 +++++------ gns3server/controller/udp_link.py | 5 +- 23 files changed, 182 insertions(+), 194 deletions(-) diff --git a/gns3server/controller/__init__.py b/gns3server/controller/__init__.py index 026cd2b6e..f2629065c 100644 --- a/gns3server/controller/__init__.py +++ b/gns3server/controller/__init__.py @@ -15,43 +15,42 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . -import os -import sys -import uuid -import shutil import asyncio -import random import json +import os +import random +import shutil +import sys import threading +import uuid try: import importlib_resources except ImportError: from importlib import resources as importlib_resources -from watchdog.events import FileSystemEventHandler, DirDeletedEvent, FileDeletedEvent +import logging + +from watchdog.events import DirDeletedEvent, FileDeletedEvent, FileSystemEventHandler from watchdog.observers import Observer from ..config import Config -from ..utils import parse_version, md5sum -from ..utils.images import default_images_directory +from ..db.tasks import update_disk_checksums +from ..utils import md5sum, parse_version from ..utils.asyncio import wait_run_in_executor - -from .project import Project -from .node import Node +from ..utils.images import default_images_directory +from ..version import __version__ from .appliance import Appliance from .appliance_manager import ApplianceManager from .compute import Compute, ComputeError -from .notification import Notification -from .symbols import Symbols -from .topology import load_topology +from .controller_error import ControllerError, ControllerNotFoundError from .gns3vm import GNS3VM from .gns3vm.gns3_vm_error import GNS3VMError -from .controller_error import ControllerError, ControllerNotFoundError -from ..db.tasks import update_disk_checksums -from ..version import __version__ - -import logging +from .node import Node +from .notification import Notification +from .project import Project +from .symbols import Symbols +from .topology import load_topology log = logging.getLogger(__name__) diff --git a/gns3server/controller/appliance_manager.py b/gns3server/controller/appliance_manager.py index e99320202..fc6836116 100644 --- a/gns3server/controller/appliance_manager.py +++ b/gns3server/controller/appliance_manager.py @@ -15,37 +15,34 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . -import os -import json import asyncio -import platformdirs - - +import json +import logging +import os from typing import List, Optional, Tuple -from aiohttp.client_exceptions import ClientError - from uuid import UUID + +import platformdirs +from aiohttp.client_exceptions import ClientError from pydantic import ValidationError from sqlalchemy.exc import SQLAlchemyError -from .appliance import Appliance +from gns3server import schemas +from gns3server.db.repositories.images import ImagesRepository +from gns3server.db.repositories.rbac import RbacRepository +from gns3server.db.repositories.templates import TemplatesRepository +from gns3server.schemas.controller.appliances import ApplianceModel +from gns3server.services.templates import TemplatesService +from gns3server.utils.images import default_images_directory + from ..config import Config from ..utils.asyncio import locking from ..utils.http_client import HTTPClient -from .controller_error import ControllerBadRequestError, ControllerNotFoundError, ControllerError -from .appliance_to_template import ApplianceToTemplate -from ..utils.images import InvalidImageError, write_image, read_image_info from ..utils.image_inventory import image_lock - -from gns3server import schemas -from gns3server.schemas.controller.appliances import ApplianceModel -from gns3server.utils.images import default_images_directory -from gns3server.db.repositories.images import ImagesRepository -from gns3server.db.repositories.templates import TemplatesRepository -from gns3server.services.templates import TemplatesService -from gns3server.db.repositories.rbac import RbacRepository - -import logging +from ..utils.images import InvalidImageError, read_image_info, write_image +from .appliance import Appliance +from .appliance_to_template import ApplianceToTemplate +from .controller_error import ControllerBadRequestError, ControllerError, ControllerNotFoundError log = logging.getLogger(__name__) diff --git a/gns3server/controller/appliance_to_template.py b/gns3server/controller/appliance_to_template.py index e78eaf56f..8f2f5e175 100644 --- a/gns3server/controller/appliance_to_template.py +++ b/gns3server/controller/appliance_to_template.py @@ -17,6 +17,7 @@ import logging + from .controller_error import ControllerError log = logging.getLogger(__name__) diff --git a/gns3server/controller/compute.py b/gns3server/controller/compute.py index f42f2e3a0..1b3b65e38 100644 --- a/gns3server/controller/compute.py +++ b/gns3server/controller/compute.py @@ -15,14 +15,14 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . -import ipaddress -import aiohttp import asyncio -import socket -import json -import sys import io +import ipaddress +import json +import socket +import sys +import aiohttp from fastapi import HTTPException if sys.version_info >= (3, 11): @@ -30,23 +30,22 @@ if sys.version_info >= (3, 11): else: from async_timeout import timeout as asynctimeout -from ..utils import parse_version -from ..utils.asyncio import locking, async_iterable_to_stream +import logging + from ..controller.controller_error import ( - ControllerError, + ComputeConflictError, + ComputeError, ControllerBadRequestError, - ControllerNotFoundError, + ControllerError, ControllerForbiddenError, + ControllerNotFoundError, ControllerTimeoutError, ControllerUnauthorizedError, - ComputeError, - ComputeConflictError, ) +from ..utils import parse_version +from ..utils.asyncio import async_iterable_to_stream, locking from ..version import __version__, __version_info__ - -import logging - log = logging.getLogger(__name__) diff --git a/gns3server/controller/drawing.py b/gns3server/controller/drawing.py index daf072983..a67a9988a 100644 --- a/gns3server/controller/drawing.py +++ b/gns3server/controller/drawing.py @@ -15,19 +15,16 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . -import hashlib import base64 -import uuid -import re +import hashlib +import logging import os +import re +import uuid import xml.etree.ElementTree as ET - from gns3server.utils.picture import get_size - -import logging - log = logging.getLogger(__name__) diff --git a/gns3server/controller/export_project.py b/gns3server/controller/export_project.py index 080d3675c..c1c7aac7b 100644 --- a/gns3server/controller/export_project.py +++ b/gns3server/controller/export_project.py @@ -15,19 +15,18 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . +import asyncio +import json +import logging import os import sys -import json -import asyncio -import aiofiles -import zipfile import tempfile - -from .controller_error import ControllerError, ControllerNotFoundError, ControllerTimeoutError - +import zipfile from datetime import datetime -import logging +import aiofiles + +from .controller_error import ControllerError, ControllerNotFoundError, ControllerTimeoutError log = logging.getLogger(__name__) diff --git a/gns3server/controller/gns3vm/__init__.py b/gns3server/controller/gns3vm/__init__.py index a20a1e81d..3f69ee001 100644 --- a/gns3server/controller/gns3vm/__init__.py +++ b/gns3server/controller/gns3vm/__init__.py @@ -15,22 +15,21 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . -import sys -import copy import asyncio +import copy import ipaddress +import logging +import sys from ...utils.asyncio import locking -from .vmware_gns3_vm import VMwareGNS3VM -from .virtualbox_gns3_vm import VirtualBoxGNS3VM -from .hyperv_gns3_vm import HyperVGNS3VM -from .remote_gns3_vm import RemoteGNS3VM -from .gns3_vm_error import GNS3VMError from ...version import __version__ from ..compute import ComputeError from ..controller_error import ControllerError - -import logging +from .gns3_vm_error import GNS3VMError +from .hyperv_gns3_vm import HyperVGNS3VM +from .remote_gns3_vm import RemoteGNS3VM +from .virtualbox_gns3_vm import VirtualBoxGNS3VM +from .vmware_gns3_vm import VMwareGNS3VM log = logging.getLogger(__name__) diff --git a/gns3server/controller/gns3vm/base_gns3_vm.py b/gns3server/controller/gns3vm/base_gns3_vm.py index 4c5c85788..3abe8679c 100644 --- a/gns3server/controller/gns3vm/base_gns3_vm.py +++ b/gns3server/controller/gns3vm/base_gns3_vm.py @@ -15,10 +15,10 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . -import psutil - import logging +import psutil + log = logging.getLogger(__name__) diff --git a/gns3server/controller/gns3vm/hyperv_gns3_vm.py b/gns3server/controller/gns3vm/hyperv_gns3_vm.py index 7ec969223..6505e0349 100644 --- a/gns3server/controller/gns3vm/hyperv_gns3_vm.py +++ b/gns3server/controller/gns3vm/hyperv_gns3_vm.py @@ -15,11 +15,12 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . -import sys -import logging import asyncio -import psutil import ipaddress +import logging +import sys + +import psutil from .base_gns3_vm import BaseGNS3VM from .gns3_vm_error import GNS3VMError diff --git a/gns3server/controller/gns3vm/remote_gns3_vm.py b/gns3server/controller/gns3vm/remote_gns3_vm.py index f71aa9e82..aa3ad4147 100644 --- a/gns3server/controller/gns3vm/remote_gns3_vm.py +++ b/gns3server/controller/gns3vm/remote_gns3_vm.py @@ -15,12 +15,11 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . +import logging + from .base_gns3_vm import BaseGNS3VM from .gns3_vm_error import GNS3VMError - -import logging - log = logging.getLogger(__name__) diff --git a/gns3server/controller/gns3vm/virtualbox_gns3_vm.py b/gns3server/controller/gns3vm/virtualbox_gns3_vm.py index 5fe733cd5..f4e328424 100644 --- a/gns3server/controller/gns3vm/virtualbox_gns3_vm.py +++ b/gns3server/controller/gns3vm/virtualbox_gns3_vm.py @@ -15,21 +15,22 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . -import re -import sys -import aiohttp -import logging import asyncio -import socket import ipaddress +import logging +import re +import socket +import sys + +import aiohttp -from .base_gns3_vm import BaseGNS3VM -from .gns3_vm_error import GNS3VMError from gns3server.utils import parse_version -from gns3server.utils.http_client import HTTPClient from gns3server.utils.asyncio import wait_run_in_executor +from gns3server.utils.http_client import HTTPClient from ...compute.virtualbox import VirtualBox, VirtualBoxError +from .base_gns3_vm import BaseGNS3VM +from .gns3_vm_error import GNS3VMError log = logging.getLogger(__name__) diff --git a/gns3server/controller/gns3vm/vmware_gns3_vm.py b/gns3server/controller/gns3vm/vmware_gns3_vm.py index b19c85ad9..ff0451463 100644 --- a/gns3server/controller/gns3vm/vmware_gns3_vm.py +++ b/gns3server/controller/gns3vm/vmware_gns3_vm.py @@ -15,9 +15,10 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . -import os -import logging import asyncio +import logging +import os + import psutil from gns3server.compute.vmware import VMware, VMwareError diff --git a/gns3server/controller/import_project.py b/gns3server/controller/import_project.py index f26c747e2..e844d99e7 100644 --- a/gns3server/controller/import_project.py +++ b/gns3server/controller/import_project.py @@ -15,23 +15,23 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . -import os -import sys -import json -import uuid -import shutil -import aiofiles import itertools -import tempfile +import json +import logging +import os +import shutil import stat +import sys +import tempfile +import uuid + +import aiofiles + import gns3server.utils.zipfile_zstd as zipfile_zstd +from ..utils.asyncio import aiozipstream, wait_run_in_executor from .controller_error import ControllerError from .topology import load_topology -from ..utils.asyncio import wait_run_in_executor -from ..utils.asyncio import aiozipstream - -import logging log = logging.getLogger(__name__) diff --git a/gns3server/controller/link.py b/gns3server/controller/link.py index c2ef20f7a..5cbe94506 100644 --- a/gns3server/controller/link.py +++ b/gns3server/controller/link.py @@ -15,21 +15,21 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . +import html +import logging import os import re import uuid -import html -from .controller_error import ControllerError, ControllerNotFoundError from gns3server.agent.web_wireshark.manager import WebWiresharkManager from gns3server.config import Config from gns3server.utils.packet_filter_validation import ( - validate_all_filters, - filter_inactive_filters, FilterValidationError, + filter_inactive_filters, + validate_all_filters, ) -import logging +from .controller_error import ControllerError, ControllerNotFoundError log = logging.getLogger(__name__) diff --git a/gns3server/controller/marker_replay.py b/gns3server/controller/marker_replay.py index f5996c159..716c5cf82 100644 --- a/gns3server/controller/marker_replay.py +++ b/gns3server/controller/marker_replay.py @@ -63,7 +63,7 @@ import tempfile import time from contextlib import asynccontextmanager -from .controller_error import ControllerError, ControllerNotFoundError, ControllerBadRequestError +from .controller_error import ControllerBadRequestError, ControllerError, ControllerNotFoundError log = logging.getLogger(__name__) diff --git a/gns3server/controller/node.py b/gns3server/controller/node.py index 6fb64045f..e96d4b704 100644 --- a/gns3server/controller/node.py +++ b/gns3server/controller/node.py @@ -16,21 +16,19 @@ # along with this program. If not, see . import asyncio -import html import copy -import uuid -import os - -from .controller_error import ControllerError, ControllerTimeoutError, ComputeError, ComputeConflictError -from .node_types import BUILTIN_NODE_TYPES -from .ports.port_factory import PortFactory, StandardPortFactory, DynamipsPortFactory -from ..utils.images import images_directories -from ..utils.application_id import is_iol_runner_environment -from ..utils import macaddress_to_int, int_to_macaddress -from ..config import Config - - +import html import logging +import os +import uuid + +from ..config import Config +from ..utils import int_to_macaddress, macaddress_to_int +from ..utils.application_id import is_iol_runner_environment +from ..utils.images import images_directories +from .controller_error import ComputeConflictError, ComputeError, ControllerError, ControllerTimeoutError +from .node_types import BUILTIN_NODE_TYPES +from .ports.port_factory import DynamipsPortFactory, PortFactory, StandardPortFactory log = logging.getLogger(__name__) diff --git a/gns3server/controller/notification.py b/gns3server/controller/notification.py index d3540a746..711fabcc2 100644 --- a/gns3server/controller/notification.py +++ b/gns3server/controller/notification.py @@ -19,6 +19,7 @@ import asyncio from contextlib import contextmanager from gns3server.utils.notification_queue import NotificationQueue + from .controller_error import ControllerError diff --git a/gns3server/controller/ports/port_factory.py b/gns3server/controller/ports/port_factory.py index 0568ef788..dd74ba086 100644 --- a/gns3server/controller/ports/port_factory.py +++ b/gns3server/controller/ports/port_factory.py @@ -15,18 +15,18 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . +import logging + from gns3server.controller.controller_error import ControllerError -from gns3server.utils import macaddress_to_int, int_to_macaddress +from gns3server.utils import int_to_macaddress, macaddress_to_int + from .atm_port import ATMPort +from .ethernet_port import EthernetPort +from .fastethernet_port import FastEthernetPort from .frame_relay_port import FrameRelayPort from .gigabitethernet_port import GigabitEthernetPort -from .fastethernet_port import FastEthernetPort -from .ethernet_port import EthernetPort -from .serial_port import SerialPort from .pos_port import POSPort - - -import logging +from .serial_port import SerialPort log = logging.getLogger(__name__) diff --git a/gns3server/controller/project.py b/gns3server/controller/project.py index 83b95b41f..04016ed27 100644 --- a/gns3server/controller/project.py +++ b/gns3server/controller/project.py @@ -15,43 +15,41 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . -import re -import os -import json -import uuid -import copy -import shutil -import time import asyncio -import aiofiles -import tempfile -import zipfile +import copy +import json +import logging +import os import pathlib - +import re +import shutil +import tempfile +import time +import uuid +import zipfile from uuid import UUID, uuid4 + +import aiofiles from fastapi import HTTPException, status -from .node import Node -from .compute import ComputeError -from .snapshot import Snapshot -from .drawing import Drawing -from .topology import project_to_topology, load_topology -from .udp_link import UDPLink -from .link import _UNSET -from ..config import Config -from ..utils.path import check_path_allowed, get_default_project_directory -from ..utils.application_id import get_next_application_id, is_iol_runner_environment -from ..utils.asyncio.pool import Pool -from ..utils.packet_filter_validation import validate_bpf_syntax -from ..utils.asyncio import locking -from ..utils.asyncio import aiozipstream -from ..utils.asyncio import wait_run_in_executor -from .export_project import export_project -from .import_project import import_project, update_snapshots, regenerate_topology_ids -from .controller_error import ControllerError, ControllerForbiddenError, ControllerNotFoundError from gns3server.agent.web_wireshark.manager import WebWiresharkManager -import logging +from ..config import Config +from ..utils.application_id import get_next_application_id, is_iol_runner_environment +from ..utils.asyncio import aiozipstream, locking, wait_run_in_executor +from ..utils.asyncio.pool import Pool +from ..utils.packet_filter_validation import validate_bpf_syntax +from ..utils.path import check_path_allowed, get_default_project_directory +from .compute import ComputeError +from .controller_error import ControllerError, ControllerForbiddenError, ControllerNotFoundError +from .drawing import Drawing +from .export_project import export_project +from .import_project import import_project, regenerate_topology_ids, update_snapshots +from .link import _UNSET +from .node import Node +from .snapshot import Snapshot +from .topology import load_topology, project_to_topology +from .udp_link import UDPLink log = logging.getLogger(__name__) diff --git a/gns3server/controller/snapshot.py b/gns3server/controller/snapshot.py index d203830f7..66d659b65 100644 --- a/gns3server/controller/snapshot.py +++ b/gns3server/controller/snapshot.py @@ -16,23 +16,22 @@ # along with this program. If not, see . +import logging import os -import uuid import shutil import tempfile -import aiofiles -import zipfile import time +import uuid +import zipfile from datetime import datetime, timezone +import aiofiles + +from ..utils.asyncio import aiozipstream, wait_run_in_executor from .controller_error import ControllerError -from ..utils.asyncio import wait_run_in_executor -from ..utils.asyncio import aiozipstream from .export_project import export_project from .import_project import import_project -import logging - log = logging.getLogger(__name__) diff --git a/gns3server/controller/symbols.py b/gns3server/controller/symbols.py index 2a7ee788d..69302d8bd 100644 --- a/gns3server/controller/symbols.py +++ b/gns3server/controller/symbols.py @@ -15,16 +15,15 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . +import logging import os import posixpath -from .symbol_themes import BUILTIN_SYMBOL_THEMES -from .controller_error import ControllerNotFoundError +from ..config import Config from ..utils.get_resource import get_resource from ..utils.picture import get_size -from ..config import Config - -import logging +from .controller_error import ControllerNotFoundError +from .symbol_themes import BUILTIN_SYMBOL_THEMES log = logging.getLogger(__name__) diff --git a/gns3server/controller/topology.py b/gns3server/controller/topology.py index 1e5dd3810..579b40c22 100644 --- a/gns3server/controller/topology.py +++ b/gns3server/controller/topology.py @@ -15,36 +15,35 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . -import os +import glob import html import json -import uuid -import glob +import logging +import os import shutil +import uuid import zipfile -import pydantic - from typing import Optional -from ..version import __version__ -from ..utils.qt import qt_font_to_style -from ..compute.dynamips import PLATFORMS_DEFAULT_RAM -from .controller_error import ControllerError -from .compute import Compute -from .drawing import Drawing -from .node import Node -from .link import Link +import pydantic +from gns3server.schemas.compute.dynamips_nodes import DynamipsCreate +from gns3server.schemas.controller.topology import Topology from gns3server.utils.hostname import ( is_ios_hostname_valid, is_rfc1123_hostname_valid, - to_rfc1123_hostname, to_ios_hostname, + to_rfc1123_hostname, ) -from gns3server.schemas.controller.topology import Topology -from gns3server.schemas.compute.dynamips_nodes import DynamipsCreate -import logging +from ..compute.dynamips import PLATFORMS_DEFAULT_RAM +from ..utils.qt import qt_font_to_style +from ..version import __version__ +from .compute import Compute +from .controller_error import ControllerError +from .drawing import Drawing +from .link import Link +from .node import Node log = logging.getLogger(__name__) diff --git a/gns3server/controller/udp_link.py b/gns3server/controller/udp_link.py index f5fdcbb9c..1a543bcd3 100644 --- a/gns3server/controller/udp_link.py +++ b/gns3server/controller/udp_link.py @@ -19,10 +19,11 @@ import asyncio import logging +from gns3server.utils.packet_filter_validation import FilterValidationError, validate_bpf_syntax + from .controller_error import ControllerError, ControllerNotFoundError -from .link import Link, _UNSET +from .link import _UNSET, Link from .node_types import BUILTIN_NODE_TYPES -from gns3server.utils.packet_filter_validation import validate_bpf_syntax, FilterValidationError # Node types that can host a marker (have a uBridge bridge to attach the # `mark` filter to). Mirrors _get_filter_node in link.py, minus "nat"