From 5672f102c40462dd0ecec76f79bb0a216e6a0ca9 Mon Sep 17 00:00:00 2001 From: Peter Barker Date: Thu, 3 Oct 2024 20:32:07 +1000 Subject: [PATCH] mavproxy_help: fix for xmlrpc no longer being available --- MAVProxy/modules/mavproxy_help.py | 64 ++++++++++++++++--------------- 1 file changed, 34 insertions(+), 30 deletions(-) diff --git a/MAVProxy/modules/mavproxy_help.py b/MAVProxy/modules/mavproxy_help.py index 4311504cb0..8f4cb754d1 100644 --- a/MAVProxy/modules/mavproxy_help.py +++ b/MAVProxy/modules/mavproxy_help.py @@ -5,8 +5,7 @@ """ import platform import re -import socket -import sys +import requests from MAVProxy.modules.lib import mp_util from MAVProxy.modules.lib import mp_module @@ -17,12 +16,6 @@ from MAVProxy.modules.lib.mp_menu import MPMenuOpenWeblink from MAVProxy.modules.lib.mp_menu import MPMenuChildMessageDialog -if sys.version_info.major < 3: - import xmlrpclib -else: - basestring = str - import xmlrpc.client as xmlrpclib - class HelpModule(mp_module.MPModule): def __init__(self, mpstate): @@ -48,27 +41,7 @@ def __init__(self, mpstate): self.wxVersion = '' # check for updates, if able - pypi = xmlrpclib.ServerProxy('https://pypi.python.org/pypi') - available = None - try: - available = pypi.package_releases('MAVProxy') - except socket.gaierror: - pass - - if available: - self.newversion = available[0] - else: - self.newversion = 'Error finding update' - - # and format the update string - if not isinstance(self.newversion, basestring): - self.newversion = "Error finding update" - elif re.search('[a-zA-Z]', self.newversion): - self.newversion = "Error finding update: " + self.newversion - elif self.newversion.strip() == self.version.strip(): - self.newversion = "Running latest version" - else: - self.newversion = "New version " + self.newversion + " available (currently running " + self.version + ")" + self.check_for_updates() if mp_util.has_wxpython: self.menu_added_console = False @@ -100,8 +73,39 @@ def __init__(self, mpstate): )) ]) + def check_for_updates(self): + url = "https://pypi.org/pypi/MAVProxy/json" + try: + response = requests.get(url) + except requests.exceptions.RequestException as e: + self.newversion = f"Error finding update: {e}" + return + + if response.status_code != 200: + self.newversion = f"HTTP error getting update ({response.status_code})" + return + + self.newversion = response.json()['info']['version'] + + # and format the update string + if not isinstance(self.newversion, str): + self.newversion = "Error finding update" + elif re.search('[a-zA-Z]', self.newversion): + self.newversion = "Error finding update: " + self.newversion + elif self.newversion.strip() == self.version.strip(): + self.newversion = "Running latest version" + else: + self.newversion = "New version " + self.newversion + " available (currently running " + self.version + ")" + def about_string(self): - return "MAVProxy Version " + self.version + "\nOS: " + self.host + "\nPython " + self.pythonversion + "\nWXPython " + self.wxVersion # noqa + bits = { + "MAVProxy Version": self.version, + "OS": self.host, + "Python": self.pythonversion, + "WXPython": self.wxVersion, + "LatestVersion": self.newversion, + } + return "".join([f"{x[0]}: {x[1]}\n" for x in bits.items()]) def idle_task(self): '''called on idle'''