pkg_resources deprication

This commit is contained in:
Arseniy Kuznetsov
2024-03-18 15:11:06 +01:00
parent a49265b300
commit 5b280ccb34
4 changed files with 16 additions and 17 deletions

View File

@@ -112,7 +112,7 @@ The default configuration file comes with a sample configuration, making it easy
Most options are easy to understand at first glance, and some are described in more details [later](https://github.com/akpw/mktxp#advanced-features). Most options are easy to understand at first glance, and some are described in more details [later](https://github.com/akpw/mktxp#advanced-features).
💡 To automatically migrate from the older `mktxp.conf` format in the existing installs, just set `compact_default_conf_values = True` in [the mktxp system config](https://github.com/akpw/mktxp#mktxp-system-configuration) <sup>💡</sup> To automatically migrate from the older `mktxp.conf` format in the existing installs, just set `compact_default_conf_values = True` in [the mktxp system config](https://github.com/akpw/mktxp#mktxp-system-configuration)
#### Local install #### Local install
If you have a local MKTXP installation, you can edit the configuration file with your default system editor directly from mktxp: If you have a local MKTXP installation, you can edit the configuration file with your default system editor directly from mktxp:
@@ -143,7 +143,7 @@ docker run -v "$(pwd)/mktxp:/home/mktxp/mktxp/" -p 49090:49090 -it --rm ghcr.io/
#### MKTXP stack install #### MKTXP stack install
[MKTXP Stack Getting Started](https://github.com/akpw/mktxp-stack#install--getting-started) provides similar instructions around editing the mktxp.conf file and, if needed, adding a dedicated API user to your Mikrotik RouterOS devices as mentioned below. [MKTXP Stack Getting Started](https://github.com/akpw/mktxp-stack#install--getting-started) provides similar instructions around editing the mktxp.conf file and, if needed, adding a dedicated API user to your Mikrotik RouterOS devices as mentioned below.
💡 *In the case of usage within a [Docker Swarm](https://docs.docker.com/engine/swarm/), please do make sure to have all settings explicitly set in both the `mktxp.conf` and `_mktxp.conf` files. Not doing this may cause [issues](https://github.com/akpw/mktxp/issues/55#issuecomment-1346693843) regarding a `read-only` filesystem.* <sup>💡</sup> *In the case of usage within a [Docker Swarm](https://docs.docker.com/engine/swarm/), please do make sure to have all settings explicitly set in both the `mktxp.conf` and `_mktxp.conf` files. Not doing this may cause [issues](https://github.com/akpw/mktxp/issues/55#issuecomment-1346693843) regarding a `read-only` filesystem.*
## Mikrotik Device Config ## Mikrotik Device Config
For the purpose of RouterOS device monitoring, it's best to create a dedicated user with minimal required permissions. \ For the purpose of RouterOS device monitoring, it's best to create a dedicated user with minimal required permissions. \
@@ -241,7 +241,7 @@ mktxp edit -i
max_scrape_duration = 10 # Max duration of individual routers' metrics collection (parallel fetch only) max_scrape_duration = 10 # Max duration of individual routers' metrics collection (parallel fetch only)
total_max_scrape_duration = 30 # Max overall duration of all metrics collection (parallel fetch only) total_max_scrape_duration = 30 # Max overall duration of all metrics collection (parallel fetch only)
compact_default_conf_values = True # Compact mktxp.conf, so only specific values are kept on the individual routers' level compact_default_conf_values = False # Compact mktxp.conf, so only specific values are kept on the individual routers' level
``` ```
<sup>💡</sup> *When changing the default mktxp port for [docker image installs](https://github.com/akpw/mktxp#docker-image-install), you'll need to adjust the `docker run ... -p 49090:49090 ...` command to reflect the new port* <sup>💡</sup> *When changing the default mktxp port for [docker image installs](https://github.com/akpw/mktxp#docker-image-install), you'll need to adjust the `docker run ... -p 49090:49090 ...` command to reflect the new port*

View File

@@ -30,4 +30,4 @@
max_scrape_duration = 10 # Max duration of individual routers' metrics collection (parallel fetch only) max_scrape_duration = 10 # Max duration of individual routers' metrics collection (parallel fetch only)
total_max_scrape_duration = 30 # Max overall duration of all metrics collection (parallel fetch only) total_max_scrape_duration = 30 # Max overall duration of all metrics collection (parallel fetch only)
compact_default_conf_values = True # Compact mktxp.conf, so only specific values are kept on the individual routers' level compact_default_conf_values = False # Compact mktxp.conf, so only specific values are kept on the individual routers' level

View File

@@ -17,7 +17,7 @@ import shutil
from collections import namedtuple from collections import namedtuple
from configobj import ConfigObj from configobj import ConfigObj
from abc import ABCMeta, abstractmethod from abc import ABCMeta, abstractmethod
from pkg_resources import Requirement, resource_filename import importlib.resources
from mktxp.utils.utils import FSHelper from mktxp.utils.utils import FSHelper
@@ -262,9 +262,9 @@ class MKTXPConfigHandler:
self.os_config.mktxp_user_dir_path, '_mktxp.conf') self.os_config.mktxp_user_dir_path, '_mktxp.conf')
self._create_os_path(self.usr_conf_data_path, self._create_os_path(self.usr_conf_data_path,
'mktxp/cli/config/mktxp.conf') 'cli/config/mktxp.conf')
self._create_os_path(self.mktxp_conf_path, self._create_os_path(self.mktxp_conf_path,
'mktxp/cli/config/_mktxp.conf') 'cli/config/_mktxp.conf')
self.re_compiled = {} self.re_compiled = {}
@@ -309,9 +309,9 @@ class MKTXPConfigHandler:
def _create_os_path(self, os_path, resource_path): def _create_os_path(self, os_path, resource_path):
if not os.path.exists(os_path): if not os.path.exists(os_path):
# stage from the conf templates # stage from the conf templates
lookup_path = resource_filename( ref = importlib.resources.files('mktxp') / resource_path
Requirement.parse("mktxp"), resource_path) with importlib.resources.as_file(ref) as path:
shutil.copy(lookup_path, os_path) shutil.copy(path, os_path)
def _system_entry_reader(self): def _system_entry_reader(self):
system_entry_reader = {} system_entry_reader = {}

View File

@@ -21,8 +21,7 @@ import xml.etree.ElementTree as ET
from contextlib import contextmanager from contextlib import contextmanager
from multiprocessing import Process, Event from multiprocessing import Process, Event
from datetime import timedelta from datetime import timedelta
from pkg_resources import packaging from packaging.version import parse
''' Utilities / Helpers ''' Utilities / Helpers
@@ -309,7 +308,7 @@ def get_available_updates(channel, ttl_hash=get_ttl_hash()):
title, _, _, _, _, _ = child title, _, _, _, _, _ = child
# extract and parse the version number from title # extract and parse the version number from title
version_text = re.findall(r'[\d+\.]+', title.text)[0] version_text = re.findall(r'[\d+\.]+', title.text)[0]
version_number = packaging.version.parse(version_text) version_number = parse(version_text)
versions.append(version_number) versions.append(version_number)
return versions return versions
@@ -322,15 +321,15 @@ def parse_ros_version(string):
1.2.3, stable 1.2.3, stable
""" """
version, channel = re.findall(r'([\d\.]+).*?([\w]+)', string)[0] version, channel = re.findall(r'([\d\.]+).*?([\w]+)', string)[0]
return packaging.version.parse(version), channel return parse(version), channel
def builtin_wifi_capsman_version(string): def builtin_wifi_capsman_version(version):
"""Try to check if the version is Wifi version of RouterOS (>= 7.13). """Try to check if the version is Wifi version of RouterOS (>= 7.13).
If anything goes wrong, return None. If anything goes wrong, return None.
Returns a boolean""" Returns a boolean"""
try: try:
cur_version, _ = parse_ros_version(string) cur_version, _ = parse_ros_version(version)
if cur_version >= packaging.version.parse('7.13'): if cur_version >= parse('7.13'):
return True return True
except Exception as err: except Exception as err:
print(f'could not get current RouterOS version, because: {str(err)}') print(f'could not get current RouterOS version, because: {str(err)}')