|
@@ -4,17 +4,19 @@ import inspect
|
|
|
from typing import Any
|
|
from typing import Any
|
|
|
|
|
|
|
|
from django.http import HttpRequest
|
|
from django.http import HttpRequest
|
|
|
|
|
+from django.conf import settings
|
|
|
from django.utils.html import format_html, mark_safe
|
|
from django.utils.html import format_html, mark_safe
|
|
|
|
|
|
|
|
from admin_data_views.typing import TableContext, ItemContext
|
|
from admin_data_views.typing import TableContext, ItemContext
|
|
|
from admin_data_views.utils import render_with_table_view, render_with_item_view, ItemLink
|
|
from admin_data_views.utils import render_with_table_view, render_with_item_view, ItemLink
|
|
|
|
|
|
|
|
|
|
|
|
|
-from plugantic.plugins import LOADED_PLUGINS
|
|
|
|
|
from django.conf import settings
|
|
from django.conf import settings
|
|
|
|
|
|
|
|
def obj_to_yaml(obj: Any, indent: int=0) -> str:
|
|
def obj_to_yaml(obj: Any, indent: int=0) -> str:
|
|
|
indent_str = " " * indent
|
|
indent_str = " " * indent
|
|
|
|
|
+ if indent == 0:
|
|
|
|
|
+ indent_str = '\n' # put extra newline between top-level entries
|
|
|
|
|
|
|
|
if isinstance(obj, dict):
|
|
if isinstance(obj, dict):
|
|
|
if not obj:
|
|
if not obj:
|
|
@@ -74,22 +76,34 @@ def binaries_list_view(request: HttpRequest, **kwargs) -> TableContext:
|
|
|
if '_BINARY' in key or '_VERSION' in key
|
|
if '_BINARY' in key or '_VERSION' in key
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- for plugin in LOADED_PLUGINS:
|
|
|
|
|
|
|
+ for plugin in settings.PLUGINS.values():
|
|
|
for binary in plugin.binaries:
|
|
for binary in plugin.binaries:
|
|
|
- binary = binary.load_or_install()
|
|
|
|
|
|
|
+ try:
|
|
|
|
|
+ binary = binary.load()
|
|
|
|
|
+ except Exception as e:
|
|
|
|
|
+ print(e)
|
|
|
|
|
|
|
|
rows['Binary'].append(ItemLink(binary.name, key=binary.name))
|
|
rows['Binary'].append(ItemLink(binary.name, key=binary.name))
|
|
|
- rows['Found Version'].append(binary.loaded_version)
|
|
|
|
|
|
|
+ rows['Found Version'].append(f'✅ {binary.loaded_version}' if binary.loaded_version else '❌ missing')
|
|
|
rows['From Plugin'].append(plugin.name)
|
|
rows['From Plugin'].append(plugin.name)
|
|
|
- rows['Provided By'].append(binary.loaded_provider)
|
|
|
|
|
- rows['Found Abspath'].append(binary.loaded_abspath)
|
|
|
|
|
|
|
+ rows['Provided By'].append(
|
|
|
|
|
+ ', '.join(
|
|
|
|
|
+ f'[{binprovider.name}]' if binprovider.name == getattr(binary.loaded_binprovider, 'name', None) else binprovider.name
|
|
|
|
|
+ for binprovider in binary.binproviders_supported
|
|
|
|
|
+ if binprovider
|
|
|
|
|
+ )
|
|
|
|
|
+ # binary.loaded_binprovider.name
|
|
|
|
|
+ # if binary.loaded_binprovider else
|
|
|
|
|
+ # ', '.join(getattr(provider, 'name', str(provider)) for provider in binary.binproviders_supported)
|
|
|
|
|
+ )
|
|
|
|
|
+ rows['Found Abspath'].append(binary.loaded_abspath or '❌ missing')
|
|
|
rows['Related Configuration'].append(mark_safe(', '.join(
|
|
rows['Related Configuration'].append(mark_safe(', '.join(
|
|
|
f'<a href="/admin/environment/config/{config_key}/">{config_key}</a>'
|
|
f'<a href="/admin/environment/config/{config_key}/">{config_key}</a>'
|
|
|
for config_key, config_value in relevant_configs.items()
|
|
for config_key, config_value in relevant_configs.items()
|
|
|
if binary.name.lower().replace('-', '').replace('_', '').replace('ytdlp', 'youtubedl') in config_key.lower()
|
|
if binary.name.lower().replace('-', '').replace('_', '').replace('ytdlp', 'youtubedl') in config_key.lower()
|
|
|
# or binary.name.lower().replace('-', '').replace('_', '') in str(config_value).lower()
|
|
# or binary.name.lower().replace('-', '').replace('_', '') in str(config_value).lower()
|
|
|
)))
|
|
)))
|
|
|
- rows['Overrides'].append(obj_to_yaml(binary.provider_overrides))
|
|
|
|
|
|
|
+ rows['Overrides'].append(str(obj_to_yaml(binary.provider_overrides))[:200])
|
|
|
# rows['Description'].append(binary.description)
|
|
# rows['Description'].append(binary.description)
|
|
|
|
|
|
|
|
return TableContext(
|
|
return TableContext(
|
|
@@ -104,7 +118,7 @@ def binary_detail_view(request: HttpRequest, key: str, **kwargs) -> ItemContext:
|
|
|
|
|
|
|
|
binary = None
|
|
binary = None
|
|
|
plugin = None
|
|
plugin = None
|
|
|
- for loaded_plugin in LOADED_PLUGINS:
|
|
|
|
|
|
|
+ for loaded_plugin in settings.PLUGINS.values():
|
|
|
for loaded_binary in loaded_plugin.binaries:
|
|
for loaded_binary in loaded_plugin.binaries:
|
|
|
if loaded_binary.name == key:
|
|
if loaded_binary.name == key:
|
|
|
binary = loaded_binary
|
|
binary = loaded_binary
|
|
@@ -112,7 +126,10 @@ def binary_detail_view(request: HttpRequest, key: str, **kwargs) -> ItemContext:
|
|
|
|
|
|
|
|
assert plugin and binary, f'Could not find a binary matching the specified name: {key}'
|
|
assert plugin and binary, f'Could not find a binary matching the specified name: {key}'
|
|
|
|
|
|
|
|
- binary = binary.load_or_install()
|
|
|
|
|
|
|
+ try:
|
|
|
|
|
+ binary = binary.load()
|
|
|
|
|
+ except Exception as e:
|
|
|
|
|
+ print(e)
|
|
|
|
|
|
|
|
return ItemContext(
|
|
return ItemContext(
|
|
|
slug=key,
|
|
slug=key,
|
|
@@ -120,14 +137,14 @@ def binary_detail_view(request: HttpRequest, key: str, **kwargs) -> ItemContext:
|
|
|
data=[
|
|
data=[
|
|
|
{
|
|
{
|
|
|
"name": binary.name,
|
|
"name": binary.name,
|
|
|
- "description": binary.description,
|
|
|
|
|
|
|
+ "description": binary.abspath,
|
|
|
"fields": {
|
|
"fields": {
|
|
|
'plugin': plugin.name,
|
|
'plugin': plugin.name,
|
|
|
- 'binprovider': binary.loaded_provider,
|
|
|
|
|
|
|
+ 'binprovider': binary.loaded_binprovider,
|
|
|
'abspath': binary.loaded_abspath,
|
|
'abspath': binary.loaded_abspath,
|
|
|
'version': binary.loaded_version,
|
|
'version': binary.loaded_version,
|
|
|
'overrides': obj_to_yaml(binary.provider_overrides),
|
|
'overrides': obj_to_yaml(binary.provider_overrides),
|
|
|
- 'providers': obj_to_yaml(binary.providers_supported),
|
|
|
|
|
|
|
+ 'providers': obj_to_yaml(binary.binproviders_supported),
|
|
|
},
|
|
},
|
|
|
"help_texts": {
|
|
"help_texts": {
|
|
|
# TODO
|
|
# TODO
|
|
@@ -148,12 +165,15 @@ def plugins_list_view(request: HttpRequest, **kwargs) -> TableContext:
|
|
|
"extractors": [],
|
|
"extractors": [],
|
|
|
"replayers": [],
|
|
"replayers": [],
|
|
|
"configs": [],
|
|
"configs": [],
|
|
|
- "description": [],
|
|
|
|
|
|
|
+ "verbose_name": [],
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
- for plugin in LOADED_PLUGINS:
|
|
|
|
|
- plugin = plugin.load_or_install()
|
|
|
|
|
|
|
+ for plugin in settings.PLUGINS.values():
|
|
|
|
|
+ try:
|
|
|
|
|
+ plugin = plugin.load_binaries()
|
|
|
|
|
+ except Exception as e:
|
|
|
|
|
+ print(e)
|
|
|
|
|
|
|
|
rows['Name'].append(ItemLink(plugin.name, key=plugin.name))
|
|
rows['Name'].append(ItemLink(plugin.name, key=plugin.name))
|
|
|
rows['binaries'].append(mark_safe(', '.join(
|
|
rows['binaries'].append(mark_safe(', '.join(
|
|
@@ -168,7 +188,7 @@ def plugins_list_view(request: HttpRequest, **kwargs) -> TableContext:
|
|
|
for config_key in configset.__fields__.keys()
|
|
for config_key in configset.__fields__.keys()
|
|
|
if config_key != 'section' and config_key in settings.CONFIG
|
|
if config_key != 'section' and config_key in settings.CONFIG
|
|
|
)))
|
|
)))
|
|
|
- rows['description'].append(str(plugin.description))
|
|
|
|
|
|
|
+ rows['verbose_name'].append(str(plugin.verbose_name))
|
|
|
|
|
|
|
|
return TableContext(
|
|
return TableContext(
|
|
|
title="Installed plugins",
|
|
title="Installed plugins",
|
|
@@ -181,13 +201,16 @@ def plugin_detail_view(request: HttpRequest, key: str, **kwargs) -> ItemContext:
|
|
|
assert request.user.is_superuser, 'Must be a superuser to view configuration settings.'
|
|
assert request.user.is_superuser, 'Must be a superuser to view configuration settings.'
|
|
|
|
|
|
|
|
plugin = None
|
|
plugin = None
|
|
|
- for loaded_plugin in LOADED_PLUGINS:
|
|
|
|
|
|
|
+ for loaded_plugin in settings.PLUGINS.values():
|
|
|
if loaded_plugin.name == key:
|
|
if loaded_plugin.name == key:
|
|
|
plugin = loaded_plugin
|
|
plugin = loaded_plugin
|
|
|
|
|
|
|
|
assert plugin, f'Could not find a plugin matching the specified name: {key}'
|
|
assert plugin, f'Could not find a plugin matching the specified name: {key}'
|
|
|
|
|
|
|
|
- plugin = plugin.load_or_install()
|
|
|
|
|
|
|
+ try:
|
|
|
|
|
+ plugin = plugin.load_binaries()
|
|
|
|
|
+ except Exception as e:
|
|
|
|
|
+ print(e)
|
|
|
|
|
|
|
|
return ItemContext(
|
|
return ItemContext(
|
|
|
slug=key,
|
|
slug=key,
|
|
@@ -195,12 +218,13 @@ def plugin_detail_view(request: HttpRequest, key: str, **kwargs) -> ItemContext:
|
|
|
data=[
|
|
data=[
|
|
|
{
|
|
{
|
|
|
"name": plugin.name,
|
|
"name": plugin.name,
|
|
|
- "description": plugin.description,
|
|
|
|
|
|
|
+ "description": plugin.verbose_name,
|
|
|
"fields": {
|
|
"fields": {
|
|
|
'configs': plugin.configs,
|
|
'configs': plugin.configs,
|
|
|
'binaries': plugin.binaries,
|
|
'binaries': plugin.binaries,
|
|
|
'extractors': plugin.extractors,
|
|
'extractors': plugin.extractors,
|
|
|
'replayers': plugin.replayers,
|
|
'replayers': plugin.replayers,
|
|
|
|
|
+ 'schema': obj_to_yaml(plugin.model_dump(include=('name', 'verbose_name', 'app_label', settings.PLUGIN_KEYS.keys()))),
|
|
|
},
|
|
},
|
|
|
"help_texts": {
|
|
"help_texts": {
|
|
|
# TODO
|
|
# TODO
|