mirror of
https://github.com/bombsquad-community/plugin-manager.git
synced 2025-10-08 14:54:36 +00:00
Add md5sum checks
This commit is contained in:
parent
4a17820ea7
commit
c5cb42bc21
1 changed files with 27 additions and 13 deletions
|
|
@ -12,6 +12,7 @@ import asyncio
|
||||||
import re
|
import re
|
||||||
import pathlib
|
import pathlib
|
||||||
import contextlib
|
import contextlib
|
||||||
|
import hashlib
|
||||||
import copy
|
import copy
|
||||||
|
|
||||||
from typing import Union, Optional
|
from typing import Union, Optional
|
||||||
|
|
@ -420,15 +421,23 @@ class PluginLocal:
|
||||||
# ba.app.config["Community Plugin Manager"]["Installed Plugins"][self.name]["entry_points"].append(entry_point)
|
# ba.app.config["Community Plugin Manager"]["Installed Plugins"][self.name]["entry_points"].append(entry_point)
|
||||||
|
|
||||||
async def set_content(self, content):
|
async def set_content(self, content):
|
||||||
|
if not self._content:
|
||||||
loop = asyncio.get_event_loop()
|
loop = asyncio.get_event_loop()
|
||||||
await loop.run_in_executor(None, self._set_content, content)
|
await loop.run_in_executor(None, self._set_content, content)
|
||||||
self._content = content
|
self._content = content
|
||||||
return self
|
return self
|
||||||
|
|
||||||
async def set_content_from_network_response(self, request):
|
async def set_content_from_network_response(self, request, md5sum=None, retries=3):
|
||||||
|
if not self._content:
|
||||||
content = await async_stream_network_response_to_file(request, self.install_path)
|
content = await async_stream_network_response_to_file(request, self.install_path)
|
||||||
|
content += b"\n"
|
||||||
|
if md5sum and hashlib.md5(content).hexdigest() != md5sum:
|
||||||
|
if retries <= 0:
|
||||||
|
# TODO: Raise a more fitting exception.
|
||||||
|
raise TypeError("md5sum match failed")
|
||||||
|
return await self.set_content_from_network_response(request, md5sum, retries=retries-1)
|
||||||
self._content = content
|
self._content = content
|
||||||
return self
|
return self._content
|
||||||
|
|
||||||
def save(self):
|
def save(self):
|
||||||
ba.app.config.commit()
|
ba.app.config.commit()
|
||||||
|
|
@ -456,15 +465,20 @@ class PluginVersion:
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
return f"<PluginVersion({self.plugin.name} {self.number})>"
|
return f"<PluginVersion({self.plugin.name} {self.number})>"
|
||||||
|
|
||||||
async def _download(self):
|
async def _download(self, retries=3):
|
||||||
local_plugin = self.plugin.create_local()
|
local_plugin = self.plugin.create_local()
|
||||||
await local_plugin.set_content_from_network_response(self.download_url)
|
await local_plugin.set_content_from_network_response(self.download_url, self.md5sum)
|
||||||
local_plugin.set_version(self.number)
|
local_plugin.set_version(self.number)
|
||||||
local_plugin.save()
|
local_plugin.save()
|
||||||
return local_plugin
|
return local_plugin
|
||||||
|
|
||||||
async def install(self):
|
async def install(self):
|
||||||
|
try:
|
||||||
local_plugin = await self._download()
|
local_plugin = await self._download()
|
||||||
|
except TypeError:
|
||||||
|
# TODO: Catch MD5ValidationCheckFailed or smth here instead.
|
||||||
|
ba.screenmessage("Got unexpected md5sum", color = (1,0,0))
|
||||||
|
else:
|
||||||
if ba.app.config["Community Plugin Manager"]["Settings"]["Auto Enable Plugins After Installation"]:
|
if ba.app.config["Community Plugin Manager"]["Settings"]["Auto Enable Plugins After Installation"]:
|
||||||
await local_plugin.enable()
|
await local_plugin.enable()
|
||||||
ba.screenmessage("Plugin Installed", color = (0,1,0))
|
ba.screenmessage("Plugin Installed", color = (0,1,0))
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue