mirror of
https://github.com/ArchiveBox/ArchiveBox.git
synced 2025-05-27 13:14:24 -04:00
fix plugin loading and admin config display
This commit is contained in:
parent
d0e3c9502e
commit
8e41aec099
19 changed files with 316 additions and 48 deletions
1
archivebox/plugins/defaults/__init__.py
Normal file
1
archivebox/plugins/defaults/__init__.py
Normal file
|
@ -0,0 +1 @@
|
|||
default_app_config = 'plugins.defaults.apps.DefaultsPluginAppConfig'
|
|
@ -8,11 +8,10 @@ from .models import (
|
|||
|
||||
|
||||
class DependencyAdmin(SingletonModelAdmin):
|
||||
readonly_fields = ('REQUIRED', 'ENABLED', 'BINARY', 'ARGS', 'bin_path', 'bin_version', 'is_valid', 'is_enabled')
|
||||
readonly_fields = ('id', 'NAME', 'LABEL', 'REQUIRED', 'bin_path', 'bin_version', 'is_valid', 'is_enabled')
|
||||
|
||||
class ExtractorAdmin(SingletonModelAdmin):
|
||||
# readonly_fields = ('REQUIRED', 'ENABLED', 'BINARY', 'ARGS', 'bin_path', 'bin_version', 'is_valid', 'is_enabled')
|
||||
pass
|
||||
readonly_fields = ('id', 'NAME', 'LABEL', 'DEFAULT_ENABLED', 'DEFAULT_CMD', 'CMD', 'ARGS', 'TIMEOUT', 'dependency', 'is_valid', 'is_enabled')
|
||||
|
||||
print('DefaultsPluginConfig.admin')
|
||||
|
||||
|
|
|
@ -1,13 +1,15 @@
|
|||
__package__ = 'archivebox.plugins.defaults'
|
||||
# __package__ = 'archivebox.plugins.defaults'
|
||||
|
||||
|
||||
|
||||
from django.apps import AppConfig
|
||||
|
||||
|
||||
class DefaultsPluginConfig(AppConfig):
|
||||
label = "ArchiveBox Defaults"
|
||||
name = "defaults"
|
||||
class DefaultsPluginAppConfig(AppConfig):
|
||||
name = "plugins.defaults"
|
||||
|
||||
# label = "ArchiveBox Defaults"
|
||||
verbose_name = "Plugin Configuration Defaults"
|
||||
|
||||
default_auto_field = "django.db.models.AutoField"
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
# Generated by Django 3.1.14 on 2024-01-24 08:06
|
||||
# Generated by Django 3.1.14 on 2024-01-24 08:56
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
@ -20,6 +20,7 @@ class Migration(migrations.Migration):
|
|||
('id', models.AutoField(default=1, primary_key=True, serialize=False)),
|
||||
],
|
||||
options={
|
||||
'verbose_name': 'Dependency Configuration Defaults',
|
||||
'abstract': False,
|
||||
},
|
||||
),
|
||||
|
@ -33,6 +34,7 @@ class Migration(migrations.Migration):
|
|||
('id', models.AutoField(default=1, primary_key=True, serialize=False)),
|
||||
],
|
||||
options={
|
||||
'verbose_name': 'Extractor Configuration Defaults',
|
||||
'abstract': False,
|
||||
},
|
||||
),
|
||||
|
|
|
@ -0,0 +1,31 @@
|
|||
# Generated by Django 3.1.14 on 2024-01-24 09:43
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('defaults', '0001_initial'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AlterModelOptions(
|
||||
name='archiveboxdefaultdependency',
|
||||
options={'verbose_name': 'Default Configuration: Dependencies'},
|
||||
),
|
||||
migrations.AlterModelOptions(
|
||||
name='archiveboxdefaultextractor',
|
||||
options={'verbose_name': 'Default Configuration: Extractors'},
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name='archiveboxdefaultdependency',
|
||||
name='BINARY',
|
||||
field=models.CharField(default='/bin/bash', max_length=255),
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name='archiveboxdefaultdependency',
|
||||
name='ENABLED',
|
||||
field=models.BooleanField(default=True),
|
||||
),
|
||||
]
|
|
@ -10,17 +10,20 @@ from django.utils.functional import cached_property
|
|||
|
||||
from solo.models import SingletonModel
|
||||
|
||||
|
||||
from config import bin_path, bin_version
|
||||
|
||||
ConfigDict = Dict[str, Any]
|
||||
|
||||
|
||||
def bin_path(binary: str) -> str | None:
|
||||
return shutil.which(str(Path(binary).expanduser())) or shutil.which(str(binary)) or binary
|
||||
# def bin_path(binary: str) -> str | None:
|
||||
# return shutil.which(str(Path(binary).expanduser())) or shutil.which(str(binary)) or binary
|
||||
|
||||
def bin_version(bin_path: str, cmd: str | None=None) -> str | None:
|
||||
return '0.0.0'
|
||||
# def bin_version(bin_path: str, cmd: str | None=None) -> str | None:
|
||||
# return '0.0.0'
|
||||
|
||||
|
||||
class ArchiveBoxBaseDependency(SingletonModel):
|
||||
class ArchiveBoxBaseDependency(models.Model):
|
||||
singleton_instance_id = 1
|
||||
|
||||
id = models.AutoField(default=singleton_instance_id, primary_key=True)
|
||||
|
@ -37,11 +40,11 @@ class ArchiveBoxBaseDependency(SingletonModel):
|
|||
PIP_DEPENDENCIES = []
|
||||
NPM_DEPENDENCIES = []
|
||||
|
||||
DEFAULT_BINARY = '/bin/false'
|
||||
DEFAULT_START_CMD = '/bin/false'
|
||||
DEFAULT_BINARY = '/bin/bash'
|
||||
DEFAULT_START_CMD = '/bin/bash -c "while true; do sleep 1; done"'
|
||||
DEFAULT_PID_FILE = 'logs/{NAME}_WORKER.pid'
|
||||
DEFAULT_STOP_CMD = 'kill "$(<{PID_FILE})"'
|
||||
DEFAULT_VERSION_COMMAND = '{CMD} --version'
|
||||
DEFAULT_VERSION_COMMAND = '{BINARY} --version'
|
||||
DEFAULT_ARGS = ''
|
||||
|
||||
VERSION_CMD = '{BINARY} --version'
|
||||
|
@ -58,7 +61,7 @@ class ArchiveBoxBaseDependency(SingletonModel):
|
|||
app_label = 'defaults'
|
||||
|
||||
def __str__(self):
|
||||
return "{self.LABEL} Dependency Configuration"
|
||||
return f"{self.LABEL} Dependency Configuration"
|
||||
|
||||
def __json__(self):
|
||||
return {
|
||||
|
@ -79,7 +82,9 @@ class ArchiveBoxBaseDependency(SingletonModel):
|
|||
|
||||
@cached_property
|
||||
def bin_version(self):
|
||||
return bin_version(self.bin_path, cmd=self.VERSION_CMD)
|
||||
print(f'ArchiveBoxBaseDependency.bin_version({self.bin_path}, cmd={self.VERSION_CMD.format(BINARY=self.BINARY)})')
|
||||
return bin_version(self.bin_path, cmd=self.VERSION_CMD.format(BINARY=self.BINARY))
|
||||
# return bin_version(self.bin_path, cmd=self.VERSION_CMD)
|
||||
|
||||
@cached_property
|
||||
def is_valid(self):
|
||||
|
@ -157,12 +162,15 @@ class ArchiveBoxDefaultDependency(ArchiveBoxBaseDependency, SingletonModel):
|
|||
|
||||
id = models.AutoField(default=singleton_instance_id, primary_key=True)
|
||||
|
||||
ENABLED = models.BooleanField(default=True, editable=True)
|
||||
|
||||
class Meta:
|
||||
abstract = False
|
||||
app_label = 'defaults'
|
||||
verbose_name = 'Default Configuration: Dependencies'
|
||||
|
||||
|
||||
class ArchiveBoxBaseExtractor(SingletonModel):
|
||||
class ArchiveBoxBaseExtractor(models.Model):
|
||||
singleton_instance_id = 1
|
||||
|
||||
id = models.AutoField(default=singleton_instance_id, primary_key=True)
|
||||
|
@ -258,7 +266,7 @@ class ArchiveBoxBaseExtractor(SingletonModel):
|
|||
|
||||
|
||||
def save(self, *args, **kwargs):
|
||||
assert self.is_valid
|
||||
# assert self.is_valid
|
||||
|
||||
with transaction.atomic():
|
||||
result = super().save(*args, **kwargs)
|
||||
|
@ -356,6 +364,11 @@ class ArchiveBoxDefaultExtractor(ArchiveBoxBaseExtractor, SingletonModel):
|
|||
|
||||
id = models.AutoField(default=singleton_instance_id, primary_key=True)
|
||||
|
||||
DEPENDENCY = ArchiveBoxDefaultDependency
|
||||
|
||||
ENABLED = models.BooleanField(default=True, editable=True)
|
||||
|
||||
class Meta:
|
||||
abstract = False
|
||||
app_label = 'defaults'
|
||||
verbose_name = 'Default Configuration: Extractors'
|
||||
|
|
|
@ -1,12 +1,15 @@
|
|||
from pathlib import Path
|
||||
|
||||
from django.conf import settings
|
||||
|
||||
def register_plugin_settings(settings=settings, name='defaults'):
|
||||
|
||||
settings.STATICFILES_DIRS += [
|
||||
str(Path(PACKAGE_DIR) / f'plugins/{name}/static'),
|
||||
str(Path(settings.PACKAGE_DIR) / f'plugins/{name}/static'),
|
||||
]
|
||||
|
||||
settings.TEMPLATE_DIRS += [
|
||||
str(Path(PACKAGE_DIR) / f'plugins/{name}/templates'),
|
||||
str(Path(settings.PACKAGE_DIR) / f'plugins/{name}/templates'),
|
||||
]
|
||||
|
||||
print('REGISTERED PLUGIN SETTINGS', name)
|
Loading…
Add table
Add a link
Reference in a new issue