mirror of
https://github.com/inventree/InvenTree.git
synced 2025-04-29 12:06:44 +00:00
commit
4a5e4a88ac
@ -173,9 +173,12 @@ class PluginsRegistry:
|
|||||||
if (not settings.PLUGIN_TESTING) or (settings.PLUGIN_TESTING and settings.PLUGIN_TESTING_SETUP):
|
if (not settings.PLUGIN_TESTING) or (settings.PLUGIN_TESTING and settings.PLUGIN_TESTING_SETUP):
|
||||||
# Collect plugins from setup entry points
|
# Collect plugins from setup entry points
|
||||||
for entry in metadata.entry_points().get('inventree_plugins', []):
|
for entry in metadata.entry_points().get('inventree_plugins', []):
|
||||||
|
try:
|
||||||
plugin = entry.load()
|
plugin = entry.load()
|
||||||
plugin.is_package = True
|
plugin.is_package = True
|
||||||
self.plugin_modules.append(plugin)
|
self.plugin_modules.append(plugin)
|
||||||
|
except Exception as error:
|
||||||
|
get_plugin_error(error, do_log=True, log_name='discovery')
|
||||||
|
|
||||||
# Log collected plugins
|
# Log collected plugins
|
||||||
logger.info(f'Collected {len(self.plugin_modules)} plugins!')
|
logger.info(f'Collected {len(self.plugin_modules)} plugins!')
|
||||||
|
@ -11,12 +11,13 @@ import subprocess
|
|||||||
from django.core.exceptions import ValidationError
|
from django.core.exceptions import ValidationError
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
from django.utils.translation import ugettext_lazy as _
|
from django.utils.translation import ugettext_lazy as _
|
||||||
|
from django.utils import timezone
|
||||||
|
|
||||||
from rest_framework import serializers
|
from rest_framework import serializers
|
||||||
|
|
||||||
from common.serializers import SettingsSerializer
|
|
||||||
|
|
||||||
from plugin.models import PluginConfig, PluginSetting
|
from plugin.models import PluginConfig, PluginSetting
|
||||||
|
from InvenTree.config import get_plugin_file
|
||||||
|
from common.serializers import SettingsSerializer
|
||||||
|
|
||||||
|
|
||||||
class PluginConfigSerializer(serializers.ModelSerializer):
|
class PluginConfigSerializer(serializers.ModelSerializer):
|
||||||
@ -86,38 +87,44 @@ class PluginConfigInstallSerializer(serializers.Serializer):
|
|||||||
url = data.get('url', '')
|
url = data.get('url', '')
|
||||||
|
|
||||||
# build up the command
|
# build up the command
|
||||||
command = 'python -m pip install'.split()
|
install_name = []
|
||||||
|
|
||||||
if url:
|
if url:
|
||||||
# use custom registration / VCS
|
# use custom registration / VCS
|
||||||
if True in [identifier in url for identifier in ['git+https', 'hg+https', 'svn+svn', ]]:
|
if True in [identifier in url for identifier in ['git+https', 'hg+https', 'svn+svn', ]]:
|
||||||
# using a VCS provider
|
# using a VCS provider
|
||||||
if packagename:
|
if packagename:
|
||||||
command.append(f'{packagename}@{url}')
|
install_name.append(f'{packagename}@{url}')
|
||||||
else:
|
else:
|
||||||
command.append(url)
|
install_name.append(url)
|
||||||
else:
|
else:
|
||||||
# using a custom package repositories
|
# using a custom package repositories
|
||||||
command.append('-i')
|
install_name.append('-i')
|
||||||
command.append(url)
|
install_name.append(url)
|
||||||
command.append(packagename)
|
install_name.append(packagename)
|
||||||
|
|
||||||
elif packagename:
|
elif packagename:
|
||||||
# use pypi
|
# use pypi
|
||||||
command.append(packagename)
|
install_name.append(packagename)
|
||||||
|
|
||||||
|
command = 'python -m pip install'.split()
|
||||||
|
command.extend(install_name)
|
||||||
ret = {'command': ' '.join(command)}
|
ret = {'command': ' '.join(command)}
|
||||||
|
success = False
|
||||||
# execute pypi
|
# execute pypi
|
||||||
try:
|
try:
|
||||||
result = subprocess.check_output(command, cwd=os.path.dirname(settings.BASE_DIR))
|
result = subprocess.check_output(command, cwd=os.path.dirname(settings.BASE_DIR))
|
||||||
ret['result'] = str(result, 'utf-8')
|
ret['result'] = str(result, 'utf-8')
|
||||||
ret['success'] = True
|
ret['success'] = True
|
||||||
|
success = True
|
||||||
except subprocess.CalledProcessError as error:
|
except subprocess.CalledProcessError as error:
|
||||||
ret['result'] = str(error.output, 'utf-8')
|
ret['result'] = str(error.output, 'utf-8')
|
||||||
ret['error'] = True
|
ret['error'] = True
|
||||||
|
|
||||||
# Register plugins
|
# save plugin to plugin_file if installed successfull
|
||||||
# TODO
|
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
|
return ret
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user