diff --git a/custom_components/mikrotik_router/librouteros/__init__.py b/custom_components/mikrotik_router/librouteros_custom/__init__.py similarity index 89% rename from custom_components/mikrotik_router/librouteros/__init__.py rename to custom_components/mikrotik_router/librouteros_custom/__init__.py index 86836f3..b345228 100644 --- a/custom_components/mikrotik_router/librouteros/__init__.py +++ b/custom_components/mikrotik_router/librouteros_custom/__init__.py @@ -3,17 +3,17 @@ from socket import create_connection from collections import ChainMap -from librouteros.exceptions import ( +from .exceptions import ( ConnectionClosed, FatalError, ) -from librouteros.connections import SocketTransport -from librouteros.protocol import ApiProtocol -from librouteros.login import ( +from .connections import SocketTransport +from .protocol import ApiProtocol +from .login import ( plain, token, ) -from librouteros.api import Api +from .api import Api DEFAULTS = { 'timeout': 10, diff --git a/custom_components/mikrotik_router/librouteros/api.py b/custom_components/mikrotik_router/librouteros_custom/api.py similarity index 96% rename from custom_components/mikrotik_router/librouteros/api.py rename to custom_components/mikrotik_router/librouteros_custom/api.py index 863e297..e8c4a17 100644 --- a/custom_components/mikrotik_router/librouteros/api.py +++ b/custom_components/mikrotik_router/librouteros_custom/api.py @@ -2,12 +2,12 @@ from posixpath import join as pjoin -from librouteros.exceptions import TrapError, MultiTrapError -from librouteros.protocol import ( +from .exceptions import TrapError, MultiTrapError +from .protocol import ( compose_word, parse_word, ) -from librouteros.query import Query +from .query import Query class Api: diff --git a/custom_components/mikrotik_router/librouteros/connections.py b/custom_components/mikrotik_router/librouteros_custom/connections.py similarity index 93% rename from custom_components/mikrotik_router/librouteros/connections.py rename to custom_components/mikrotik_router/librouteros_custom/connections.py index 6fac4df..63cd8db 100644 --- a/custom_components/mikrotik_router/librouteros/connections.py +++ b/custom_components/mikrotik_router/librouteros_custom/connections.py @@ -1,6 +1,6 @@ # -*- coding: UTF-8 -*- -from librouteros.exceptions import ConnectionClosed +from .exceptions import ConnectionClosed class SocketTransport: diff --git a/custom_components/mikrotik_router/librouteros/exceptions.py b/custom_components/mikrotik_router/librouteros_custom/exceptions.py similarity index 100% rename from custom_components/mikrotik_router/librouteros/exceptions.py rename to custom_components/mikrotik_router/librouteros_custom/exceptions.py diff --git a/custom_components/mikrotik_router/librouteros/login.py b/custom_components/mikrotik_router/librouteros_custom/login.py similarity index 100% rename from custom_components/mikrotik_router/librouteros/login.py rename to custom_components/mikrotik_router/librouteros_custom/login.py diff --git a/custom_components/mikrotik_router/librouteros/protocol.py b/custom_components/mikrotik_router/librouteros_custom/protocol.py similarity index 99% rename from custom_components/mikrotik_router/librouteros/protocol.py rename to custom_components/mikrotik_router/librouteros_custom/protocol.py index 7de29c5..8c31a2b 100644 --- a/custom_components/mikrotik_router/librouteros/protocol.py +++ b/custom_components/mikrotik_router/librouteros_custom/protocol.py @@ -3,7 +3,7 @@ from struct import pack, unpack from logging import getLogger, NullHandler -from librouteros.exceptions import ( +from .exceptions import ( ProtocolError, FatalError, ) diff --git a/custom_components/mikrotik_router/librouteros/query.py b/custom_components/mikrotik_router/librouteros_custom/query.py similarity index 97% rename from custom_components/mikrotik_router/librouteros/query.py rename to custom_components/mikrotik_router/librouteros_custom/query.py index 91a71f9..c3f9bf2 100644 --- a/custom_components/mikrotik_router/librouteros/query.py +++ b/custom_components/mikrotik_router/librouteros_custom/query.py @@ -1,6 +1,6 @@ # -*- coding: UTF-8 -*- from itertools import chain -from librouteros.protocol import ( +from .protocol import ( cast_to_api, ) diff --git a/custom_components/mikrotik_router/mikrotikapi.py b/custom_components/mikrotik_router/mikrotikapi.py index 4d8ef67..09964ea 100644 --- a/custom_components/mikrotik_router/mikrotikapi.py +++ b/custom_components/mikrotik_router/mikrotikapi.py @@ -11,12 +11,12 @@ DEFAULT_ENCODING, ) -MODULE_PATH = os.path.join(os.path.dirname(__file__), "librouteros", "__init__.py") -MODULE_NAME = "librouteros" +MODULE_PATH = os.path.join(os.path.dirname(__file__), "librouteros_custom", "__init__.py") +MODULE_NAME = "librouteros_custom" spec = importlib.util.spec_from_file_location(MODULE_NAME, MODULE_PATH) -librouteros = importlib.util.module_from_spec(spec) -sys.modules[spec.name] = librouteros -spec.loader.exec_module(librouteros) +librouteros_custom = importlib.util.module_from_spec(spec) +sys.modules[spec.name] = librouteros_custom +spec.loader.exec_module(librouteros_custom) _LOGGER = logging.getLogger(__name__) @@ -69,13 +69,13 @@ def connect(self): kwargs["ssl_wrapper"] = self._ssl_wrapper try: - self._connection = librouteros.connect(self._host, self._username, self._password, **kwargs) + self._connection = librouteros_custom.connect(self._host, self._username, self._password, **kwargs) except ( - librouteros.exceptions.TrapError, - librouteros.exceptions.MultiTrapError, - librouteros.exceptions.ConnectionClosed, - librouteros.exceptions.ProtocolError, - librouteros.exceptions.FatalError, + librouteros_custom.exceptions.TrapError, + librouteros_custom.exceptions.MultiTrapError, + librouteros_custom.exceptions.ConnectionClosed, + librouteros_custom.exceptions.ProtocolError, + librouteros_custom.exceptions.FatalError, ssl.SSLError ) as api_error: _LOGGER.error("Mikrotik %s: %s", self._host, api_error) @@ -121,16 +121,16 @@ def path(self, path): try: response = self._connection.path(path) tuple(response) - except librouteros.exceptions.ConnectionClosed: + except librouteros_custom.exceptions.ConnectionClosed: _LOGGER.error("Mikrotik %s connection closed", self._host) self._connected = False self._connection = None return None except ( - librouteros.exceptions.TrapError, - librouteros.exceptions.MultiTrapError, - librouteros.exceptions.ProtocolError, - librouteros.exceptions.FatalError + librouteros_custom.exceptions.TrapError, + librouteros_custom.exceptions.MultiTrapError, + librouteros_custom.exceptions.ProtocolError, + librouteros_custom.exceptions.FatalError ) as api_error: _LOGGER.error("Mikrotik %s connection error %s", self._host, api_error) return None @@ -166,16 +166,16 @@ def update(self, path, param, value, mod_param, mod_value): try: response.update(**params) - except librouteros.exceptions.ConnectionClosed: + except librouteros_custom.exceptions.ConnectionClosed: _LOGGER.error("Mikrotik %s connection closed", self._host) self._connected = False self._connection = None return None except ( - librouteros.exceptions.TrapError, - librouteros.exceptions.MultiTrapError, - librouteros.exceptions.ProtocolError, - librouteros.exceptions.FatalError + librouteros_custom.exceptions.TrapError, + librouteros_custom.exceptions.MultiTrapError, + librouteros_custom.exceptions.ProtocolError, + librouteros_custom.exceptions.FatalError ) as api_error: _LOGGER.error("Mikrotik %s connection error %s", self._host, api_error) return None @@ -210,16 +210,16 @@ def run_script(self, name): entry_found = True try: run = response('run', **{'.id': tmp['.id']}) - except librouteros.exceptions.ConnectionClosed: + except librouteros_custom.exceptions.ConnectionClosed: _LOGGER.error("Mikrotik %s connection closed", self._host) self._connected = False self._connection = None return None except ( - librouteros.exceptions.TrapError, - librouteros.exceptions.MultiTrapError, - librouteros.exceptions.ProtocolError, - librouteros.exceptions.FatalError + librouteros_custom.exceptions.TrapError, + librouteros_custom.exceptions.MultiTrapError, + librouteros_custom.exceptions.ProtocolError, + librouteros_custom.exceptions.FatalError ) as api_error: _LOGGER.error("Mikrotik %s connection error %s", self._host, api_error) return None @@ -249,16 +249,16 @@ def get_traffic(self, interfaces): args = {'interface': interfaces, 'once': True} try: traffic = response('monitor-traffic', **args) - except librouteros.exceptions.ConnectionClosed: + except librouteros_custom.exceptions.ConnectionClosed: _LOGGER.error("Mikrotik %s connection closed", self._host) self._connected = False self._connection = None return None except ( - librouteros.exceptions.TrapError, - librouteros.exceptions.MultiTrapError, - librouteros.exceptions.ProtocolError, - librouteros.exceptions.FatalError + librouteros_custom.exceptions.TrapError, + librouteros_custom.exceptions.MultiTrapError, + librouteros_custom.exceptions.ProtocolError, + librouteros_custom.exceptions.FatalError ) as api_error: _LOGGER.error("Mikrotik %s connection error %s", self._host, api_error) return None