From 89fc012c7e5a9d27a6824e5c0ad7cdb0eb8ca33c Mon Sep 17 00:00:00 2001 From: Arseniy Kuznetsov Date: Wed, 12 Jun 2024 15:36:12 +0100 Subject: [PATCH] fixes / optimisations --- mktxp/datasource/package_ds.py | 2 +- mktxp/datasource/system_resource_ds.py | 14 +++++++------- mktxp/utils/utils.py | 9 +++------ 3 files changed, 11 insertions(+), 14 deletions(-) diff --git a/mktxp/datasource/package_ds.py b/mktxp/datasource/package_ds.py index b311aeaa..07c5fcc6 100644 --- a/mktxp/datasource/package_ds.py +++ b/mktxp/datasource/package_ds.py @@ -39,5 +39,5 @@ def is_package_installed (router_entry, package_name = None): if package_record['name'] == package_name: return True except Exception as exc: - print(f'Error getting installed packages info from router {router_entry.router_name}@{router_entry.config_entry.hostname}: {exc}') + print(f'Error getting an installed package status from router {router_entry.router_name}@{router_entry.config_entry.hostname}: {exc}') return False diff --git a/mktxp/datasource/system_resource_ds.py b/mktxp/datasource/system_resource_ds.py index a905bf7a..fabf36d4 100644 --- a/mktxp/datasource/system_resource_ds.py +++ b/mktxp/datasource/system_resource_ds.py @@ -28,7 +28,7 @@ def metric_records(router_entry, *, metric_labels = None, translation_table=None return BaseDSProcessor.trimmed_records(router_entry, router_records = system_resource_records, metric_labels = metric_labels, translation_table=translation_table) except Exception as exc: print(f'Error getting system resource info from router {router_entry.router_name}@{router_entry.config_entry.hostname}: {exc}') - return None + return None @staticmethod def os_version(router_entry): @@ -37,14 +37,14 @@ def os_version(router_entry): for record in system_version_records: ver = record.get('version', None) if ver: - return ver - - return None + return ver except Exception as exc: - print(f'Error getting system resource info from router {router_entry.router_name}@{router_entry.config_entry.hostname}: {exc}') - return False + print(f'Error getting OS version info from router {router_entry.router_name}@{router_entry.config_entry.hostname}: {exc}') + return None @staticmethod def has_builtin_wifi_capsman(router_entry): ver = SystemResourceMetricsDataSource.os_version(router_entry) - return builtin_wifi_capsman_version(ver) + if ver: + return builtin_wifi_capsman_version(ver) + return False diff --git a/mktxp/utils/utils.py b/mktxp/utils/utils.py index d3a26d04..aa7a33cf 100755 --- a/mktxp/utils/utils.py +++ b/mktxp/utils/utils.py @@ -317,16 +317,13 @@ def parse_ros_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(version) if cur_version >= parse('7.13'): return True except Exception as err: - print(f'could not get current RouterOS version, because: {str(err)}') - return None - + print(f'could not get current RouterOS version, because: {err}') return False def check_for_updates(cur_version): @@ -342,10 +339,10 @@ def check_for_updates(cur_version): print(f'unknown update channel {channel}') error = True except urllib.error.HTTPError as err: - print(f'update feed returned: {str(err)}') + print(f'update feed returned: {err}') error = True except Exception as err: - print(f'could not check for updates, because: {str(err)}') + print(f'could not check for updates, because: {err}') error = True if error: