Implement automatic module installer/updater

This commit is contained in:
Kumi 2023-10-31 09:33:37 +01:00
parent 6e23793588
commit d0ede85592
Signed by: kumi
GPG key ID: ECBCC9082395383F
4 changed files with 51 additions and 1 deletions

View file

@ -1,4 +1,4 @@
from .modules import BaseModule, DownloaderModule
from .exceptions import DownloadError, StitchingError, ConversionError
from .exceptions import DownloadError, StitchingError, ConversionError, InstallError
from .http import HTTPRequest
from .stitching import BaseStitcher, PILStitcher, BlenderStitcher, DEFAULT_CUBEMAP_TO_EQUIRECTANGULAR_STITCHER, DEFAULT_STITCHER

View file

@ -11,4 +11,9 @@ class DownloadError(ConversionError):
class StitchingError(ConversionError):
"""Generic error that occurred while attempting to stitch content
"""
pass
class InstallError(Exception):
"""Generic error that occurred while attempting to install a module
"""
pass

View file

@ -0,0 +1,31 @@
from .classes import HTTPRequest, InstallError
import json
import subprocess
class Installer:
MODULES_JSON = "https://git.kumi/-/snippets/131/raw/main/modules.json"
def __init__(self):
self.available_modules = self.fetch_modules()
def fetch_modules(self):
request = HTTPRequest(self.MODULES_JSON).open()
return json.loads(request.read().decode())
def install_all(self):
for module in self.available_modules:
try:
self.install_module(module)
except InstallError as e:
print(f"Error while installing module {module['name']}: {e}")
def install_module(self, module):
try:
subprocess.run(["pip", "install", "-U", module["source"]], check=True)
except Exception as e:
raise InstallError(f"Error while installing module {module['name']}: {e}") from e
if __name__ == "__main__":
installer = Installer()
installer.install_all()

View file

@ -0,0 +1,14 @@
from django.core.management.base import BaseCommand, CommandError
from ...installer import Installer
import logging
class Command(BaseCommand):
help = 'Run the worker'
def handle(self, *args, **options):
"""Handle the command
"""
installer = Installer()
installer.install_all()