Fixed some calls by adding user agents
Some checks are pending
Test and docs / build-docs (push) Waiting to run
Test and docs / test (3.12) (push) Waiting to run
Test and docs / test (3.7) (push) Waiting to run
Test and docs / test (3.8) (push) Waiting to run
Test and docs / test (3.9) (push) Waiting to run
Test and docs / test (3.10) (push) Waiting to run
Test and docs / test (3.11) (push) Waiting to run

This commit is contained in:
Manuel Cortez 2025-01-26 17:12:25 -06:00
parent c4d870252a
commit f0136b89f1
3 changed files with 12 additions and 6 deletions

View File

@ -1,7 +1,7 @@
from setuptools import setup from setuptools import setup
setup(name="updater", setup(name="updater",
version="0.3.0", version="0.3.1",
author="MCVSoftware", author="MCVSoftware",
author_email="support@mcvsoftware.com", author_email="support@mcvsoftware.com",
url="https://github.com/mcvsoftware/updater", url="https://github.com/mcvsoftware/updater",

View File

@ -38,6 +38,8 @@ class UpdaterCore(object):
self.current_version = current_version self.current_version = current_version
self.app_name = app_name self.app_name = app_name
self.password = password self.password = password
self.update_version = None
self.update_description = None
def get_update_information(self) -> Dict[str, Any]: def get_update_information(self) -> Dict[str, Any]:
""" Calls the provided URL endpoint and returns information about the available update sent by the server. The format should adhere to the json specifications for updates. """ Calls the provided URL endpoint and returns information about the available update sent by the server. The format should adhere to the json specifications for updates.
@ -46,8 +48,10 @@ class UpdaterCore(object):
:rtype: dict :rtype: dict
""" """
response = urllib.request.urlopen(self.endpoint) headers = {"User-Agent": f"{self.app_name}/{self.current_version}"}
data: str = response.read() req = urllib.request.Request(self.endpoint, headers=headers)
with urllib.request.urlopen(req) as response:
data: str = response.read()
content: Dict[str, Any] = json.loads(data) content: Dict[str, Any] = json.loads(data)
return content return content
@ -97,8 +101,8 @@ class UpdaterCore(object):
def _download_callback(transferred_blocks, block_size, total_size): def _download_callback(transferred_blocks, block_size, total_size):
total_downloaded = transferred_blocks*block_size total_downloaded = transferred_blocks*block_size
pub.sendMessage("updater.update-progress", total_downloaded=total_downloaded, total_size=total_size) pub.sendMessage("updater.update-progress", total_downloaded=total_downloaded, total_size=total_size)
request = urllib.request.Request(update_url, headers={"User-Agent": f"{self.app_name}/{self.current_version}"})
filename, headers = urllib.request.urlretrieve(update_url, update_destination, _download_callback) filename, headers = urllib.request.urlretrieve(request, update_destination, _download_callback)
log.debug("Update downloaded") log.debug("Update downloaded")
return update_destination return update_destination

View File

@ -112,7 +112,7 @@ class WXUpdater(core.UpdaterCore):
:returns: True if user wants to download the update, False otherwise. :returns: True if user wants to download the update, False otherwise.
:rtype: bool :rtype: bool
""" """
dialog = wx.MessageDialog(None, self.new_update_msg, self.new_update_title, style=wx.YES|wx.NO|wx.ICON_WARNING) dialog = wx.MessageDialog(None, self.new_update_msg.format(app_name=self.app_name, update_version=self.update_version, update_description=self.update_description), self.new_update_title.format(app_name=self.app_name), style=wx.YES|wx.NO|wx.ICON_WARNING)
response = dialog.ShowModal() response = dialog.ShowModal()
dialog.Destroy() dialog.Destroy()
if response == wx.ID_YES: if response == wx.ID_YES:
@ -156,6 +156,8 @@ class WXUpdater(core.UpdaterCore):
version_data = self.get_version_data(update_info) version_data = self.get_version_data(update_info)
if version_data[0] == False: if version_data[0] == False:
return None return None
self.update_version = version_data[0]
self.update_description = version_data[1]
response = self.on_new_update_available() response = self.on_new_update_available()
if response == False: if response == False:
return None return None