From ceed90217b66d1043679a06af80cef6d0106d193 Mon Sep 17 00:00:00 2001 From: Matthias Date: Fri, 7 Jan 2022 01:03:05 +0100 Subject: [PATCH 1/3] restructuring --- InvenTree/plugin/serializers.py | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/InvenTree/plugin/serializers.py b/InvenTree/plugin/serializers.py index e25e253498..f59348601f 100644 --- a/InvenTree/plugin/serializers.py +++ b/InvenTree/plugin/serializers.py @@ -83,26 +83,28 @@ class PluginConfigInstallSerializer(serializers.Serializer): url = data.get('url', '') # build up the command - command = 'python -m pip install'.split() + install_name = [] if url: # use custom registration / VCS if True in [identifier in url for identifier in ['git+https', 'hg+https', 'svn+svn', ]]: # using a VCS provider if packagename: - command.append(f'{packagename}@{url}') + install_name.append(f'{packagename}@{url}') else: - command.append(url) + install_name.append(url) else: # using a custom package repositories - command.append('-i') - command.append(url) - command.append(packagename) + install_name.append('-i') + install_name.append(url) + install_name.append(packagename) elif packagename: # use pypi - command.append(packagename) + install_name.append(packagename) + command = 'python -m pip install'.split() + command.extend(install_name) ret = {'command': ' '.join(command)} # execute pypi try: From edc648d61932bd097597f6eff214ab21c0bf7618 Mon Sep 17 00:00:00 2001 From: Matthias Date: Fri, 7 Jan 2022 01:09:44 +0100 Subject: [PATCH 2/3] write installd plugins to plugins.txt --- InvenTree/plugin/serializers.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/InvenTree/plugin/serializers.py b/InvenTree/plugin/serializers.py index f59348601f..83c3136620 100644 --- a/InvenTree/plugin/serializers.py +++ b/InvenTree/plugin/serializers.py @@ -11,10 +11,12 @@ import subprocess from django.core.exceptions import ValidationError from django.conf import settings from django.utils.translation import ugettext_lazy as _ +from django.utils import timezone from rest_framework import serializers from plugin.models import PluginConfig +from InvenTree.config import get_plugin_file class PluginConfigSerializer(serializers.ModelSerializer): @@ -106,16 +108,20 @@ class PluginConfigInstallSerializer(serializers.Serializer): command = 'python -m pip install'.split() command.extend(install_name) ret = {'command': ' '.join(command)} + success = False # execute pypi try: result = subprocess.check_output(command, cwd=os.path.dirname(settings.BASE_DIR)) ret['result'] = str(result, 'utf-8') ret['success'] = True + success = True except subprocess.CalledProcessError as error: ret['result'] = str(error.output, 'utf-8') ret['error'] = True - # register plugins - # TODO + # save plugin to plugin_file if installed successfull + if success: + with open(get_plugin_file(), "a") as plugin_file: + plugin_file.write(f'{" ".join(install_name)} # Installed {timezone.now()} by {str(self.context["request"].user)}\n') return ret From 0974ebb5cd0b3a96eedbaac1bb6047df8885dec5 Mon Sep 17 00:00:00 2001 From: Matthias Date: Fri, 7 Jan 2022 01:10:44 +0100 Subject: [PATCH 3/3] shield plugin package load --- InvenTree/plugin/registry.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/InvenTree/plugin/registry.py b/InvenTree/plugin/registry.py index d858d6c7f0..1a05a2ed34 100644 --- a/InvenTree/plugin/registry.py +++ b/InvenTree/plugin/registry.py @@ -150,9 +150,12 @@ class Plugins: if (not settings.PLUGIN_TESTING) or (settings.PLUGIN_TESTING and settings.PLUGIN_TESTING_SETUP): # Collect plugins from setup entry points for entry in metadata.entry_points().get('inventree_plugins', []): - plugin = entry.load() - plugin.is_package = True - self.plugin_modules.append(plugin) + try: + plugin = entry.load() + plugin.is_package = True + self.plugin_modules.append(plugin) + except Exception as error: + get_plugin_error(error, do_log=True, log_name='discovery') # Log collected plugins logger.info(f'Collected {len(self.plugin_modules)} plugins!')