mirror of
https://github.com/KevinMidboe/mktxp-no-cli.git
synced 2025-10-29 17:50:23 +00:00
pkg_resources deprication
This commit is contained in:
@@ -30,4 +30,4 @@
|
||||
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)
|
||||
|
||||
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
|
||||
@@ -17,7 +17,7 @@ import shutil
|
||||
from collections import namedtuple
|
||||
from configobj import ConfigObj
|
||||
from abc import ABCMeta, abstractmethod
|
||||
from pkg_resources import Requirement, resource_filename
|
||||
import importlib.resources
|
||||
from mktxp.utils.utils import FSHelper
|
||||
|
||||
|
||||
@@ -262,9 +262,9 @@ class MKTXPConfigHandler:
|
||||
self.os_config.mktxp_user_dir_path, '_mktxp.conf')
|
||||
|
||||
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,
|
||||
'mktxp/cli/config/_mktxp.conf')
|
||||
'cli/config/_mktxp.conf')
|
||||
|
||||
self.re_compiled = {}
|
||||
|
||||
@@ -309,9 +309,9 @@ class MKTXPConfigHandler:
|
||||
def _create_os_path(self, os_path, resource_path):
|
||||
if not os.path.exists(os_path):
|
||||
# stage from the conf templates
|
||||
lookup_path = resource_filename(
|
||||
Requirement.parse("mktxp"), resource_path)
|
||||
shutil.copy(lookup_path, os_path)
|
||||
ref = importlib.resources.files('mktxp') / resource_path
|
||||
with importlib.resources.as_file(ref) as path:
|
||||
shutil.copy(path, os_path)
|
||||
|
||||
def _system_entry_reader(self):
|
||||
system_entry_reader = {}
|
||||
|
||||
@@ -21,8 +21,7 @@ import xml.etree.ElementTree as ET
|
||||
from contextlib import contextmanager
|
||||
from multiprocessing import Process, Event
|
||||
from datetime import timedelta
|
||||
from pkg_resources import packaging
|
||||
|
||||
from packaging.version import parse
|
||||
|
||||
|
||||
''' Utilities / Helpers
|
||||
@@ -309,7 +308,7 @@ def get_available_updates(channel, ttl_hash=get_ttl_hash()):
|
||||
title, _, _, _, _, _ = child
|
||||
# extract and parse the version number from title
|
||||
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)
|
||||
return versions
|
||||
|
||||
@@ -322,15 +321,15 @@ def parse_ros_version(string):
|
||||
1.2.3, stable
|
||||
"""
|
||||
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).
|
||||
If anything goes wrong, return None.
|
||||
Returns a boolean"""
|
||||
try:
|
||||
cur_version, _ = parse_ros_version(string)
|
||||
if cur_version >= packaging.version.parse('7.13'):
|
||||
cur_version, _ = parse_ros_version(version)
|
||||
if cur_version >= parse('7.13'):
|
||||
return True
|
||||
except Exception as err:
|
||||
print(f'could not get current RouterOS version, because: {str(err)}')
|
||||
|
||||
Reference in New Issue
Block a user