Skip to content

Commit

Permalink
fixes / optimisations
Browse files Browse the repository at this point in the history
  • Loading branch information
akpw committed Jun 12, 2024
1 parent 6cd62d2 commit 89fc012
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 14 deletions.
2 changes: 1 addition & 1 deletion mktxp/datasource/package_ds.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
14 changes: 7 additions & 7 deletions mktxp/datasource/system_resource_ds.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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
9 changes: 3 additions & 6 deletions mktxp/utils/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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:
Expand Down

0 comments on commit 89fc012

Please sign in to comment.