2024-01-24 21:07:07 +13:00
|
|
|
# __package__ = 'archivebox.plugins.system'
|
|
|
|
|
|
|
|
|
|
|
|
import os
|
|
|
|
import shutil
|
|
|
|
import sys
|
|
|
|
import inspect
|
|
|
|
import django
|
2024-01-24 23:15:02 +13:00
|
|
|
from sqlite3 import dbapi2 as sqlite3
|
2024-01-24 21:07:07 +13:00
|
|
|
|
|
|
|
from pathlib import Path
|
|
|
|
from typing import List, Dict, Any
|
|
|
|
|
|
|
|
from django.db import models
|
|
|
|
from django.utils.functional import cached_property
|
|
|
|
|
|
|
|
from solo.models import SingletonModel
|
|
|
|
|
2024-01-24 23:15:02 +13:00
|
|
|
from config import bin_path, bin_version, VERSION
|
|
|
|
|
|
|
|
from plugins.defaults.models import ArchiveBoxBaseDependency
|
2024-01-24 21:07:07 +13:00
|
|
|
|
|
|
|
ConfigDict = Dict[str, Any]
|
|
|
|
|
|
|
|
|
2024-01-24 23:15:02 +13:00
|
|
|
class BashEnvironmentDependency(ArchiveBoxBaseDependency):
|
2024-01-24 21:07:07 +13:00
|
|
|
singleton_instance_id = 1
|
|
|
|
|
|
|
|
id = models.AutoField(primary_key=True)
|
|
|
|
|
|
|
|
NAME = 'BASH'
|
|
|
|
LABEL = "Bash"
|
|
|
|
REQUIRED = True
|
|
|
|
|
|
|
|
PARENT_DEPENDENCIES = []
|
|
|
|
|
2024-02-09 02:55:02 +13:00
|
|
|
BIN_DEPENDENCIES: List[str] = ['bash']
|
|
|
|
APT_DEPENDENCIES: List[str] = []
|
|
|
|
BREW_DEPENDENCIES: List[str] = []
|
|
|
|
PIP_DEPENDENCIES: List[str] = []
|
|
|
|
NPM_DEPENDENCIES: List[str] = []
|
2024-01-24 21:07:07 +13:00
|
|
|
|
|
|
|
DEFAULT_BINARY = 'bash'
|
|
|
|
DEFAULT_START_CMD = None
|
|
|
|
DEFAULT_STOP_CMD = None
|
|
|
|
DEFAULT_PID_FILE = None
|
|
|
|
DEFAULT_ARGS = '-c'
|
2024-01-24 23:15:02 +13:00
|
|
|
|
2024-01-24 21:07:07 +13:00
|
|
|
ENABLED = models.BooleanField(default=True, editable=not REQUIRED)
|
|
|
|
BINARY = models.CharField(max_length=255, default=DEFAULT_BINARY)
|
|
|
|
ARGS = models.CharField(max_length=255, default=DEFAULT_ARGS)
|
2024-01-24 23:15:02 +13:00
|
|
|
|
|
|
|
VERSION_CMD = models.CharField(max_length=255, default='{BINARY} --version')
|
2024-01-24 21:07:07 +13:00
|
|
|
|
|
|
|
# START_CMD = models.CharField(max_length=255, default=DEFAULT_START_CMD)
|
|
|
|
# WORKERS = models.IntegerField(default=1)
|
|
|
|
|
|
|
|
class Meta:
|
|
|
|
abstract = False
|
|
|
|
app_label = 'system'
|
2024-01-24 23:15:02 +13:00
|
|
|
verbose_name = "Shell Environment: bash"
|
|
|
|
verbose_name_plural = "Shell Environments: bash"
|
2024-01-24 21:07:07 +13:00
|
|
|
|
|
|
|
# @task
|
|
|
|
def install_pkgs(self, os_pkgs=()):
|
|
|
|
assert self.is_valid, 'Bash environment is not available on this host'
|
|
|
|
|
|
|
|
for os_dependency in os_pkgs:
|
|
|
|
assert bin_path(os_dependency)
|
|
|
|
|
|
|
|
return True
|
|
|
|
|
2024-01-24 23:15:02 +13:00
|
|
|
class PythonEnvironmentDependency(ArchiveBoxBaseDependency):
|
|
|
|
singleton_instance_id = 1
|
|
|
|
|
|
|
|
id = models.AutoField(primary_key=True)
|
|
|
|
|
|
|
|
NAME = 'PYTHON'
|
|
|
|
LABEL = "Python"
|
|
|
|
REQUIRED = True
|
|
|
|
|
|
|
|
PARENT_DEPENDENCIES = []
|
|
|
|
|
|
|
|
BIN_DEPENDENCIES = ['python3']
|
|
|
|
APT_DEPENDENCIES = []
|
|
|
|
BREW_DEPENDENCIES = []
|
|
|
|
PIP_DEPENDENCIES = []
|
|
|
|
NPM_DEPENDENCIES = []
|
|
|
|
|
|
|
|
DEFAULT_BINARY = 'python3'
|
|
|
|
DEFAULT_START_CMD = None
|
|
|
|
DEFAULT_STOP_CMD = None
|
|
|
|
DEFAULT_PID_FILE = None
|
|
|
|
DEFAULT_ARGS = '-c'
|
|
|
|
VERSION_CMD = '{BINARY} --version'
|
|
|
|
|
|
|
|
ENABLED = models.BooleanField(default=True, editable=not REQUIRED)
|
|
|
|
BINARY = models.CharField(max_length=255, default=DEFAULT_BINARY)
|
|
|
|
ARGS = models.CharField(max_length=255, default=DEFAULT_ARGS)
|
|
|
|
|
|
|
|
# START_CMD = models.CharField(max_length=255, default=DEFAULT_START_CMD)
|
|
|
|
# WORKERS = models.IntegerField(default=1)
|
|
|
|
|
|
|
|
class Meta:
|
|
|
|
abstract = False
|
|
|
|
app_label = 'system'
|
|
|
|
verbose_name = "Shell Environment: python3"
|
|
|
|
|
|
|
|
class NodeJSEnvironmentDependency(ArchiveBoxBaseDependency, SingletonModel):
|
|
|
|
singleton_instance_id = 1
|
|
|
|
|
|
|
|
id = models.AutoField(primary_key=True)
|
|
|
|
|
|
|
|
NAME = 'NODEJS'
|
|
|
|
LABEL = "NodeJS"
|
|
|
|
REQUIRED = True
|
|
|
|
|
|
|
|
PARENT_DEPENDENCIES = []
|
|
|
|
|
|
|
|
BIN_DEPENDENCIES = ['node']
|
|
|
|
APT_DEPENDENCIES = []
|
|
|
|
BREW_DEPENDENCIES = []
|
|
|
|
PIP_DEPENDENCIES = []
|
|
|
|
NPM_DEPENDENCIES = []
|
|
|
|
|
|
|
|
DEFAULT_BINARY = 'node'
|
|
|
|
DEFAULT_START_CMD = None
|
|
|
|
DEFAULT_STOP_CMD = None
|
|
|
|
DEFAULT_PID_FILE = None
|
|
|
|
DEFAULT_ARGS = '-c'
|
|
|
|
VERSION_CMD = '{BINARY} --version'
|
|
|
|
|
|
|
|
ENABLED = models.BooleanField(default=True, editable=True)
|
|
|
|
BINARY = models.CharField(max_length=255, default=DEFAULT_BINARY)
|
|
|
|
ARGS = models.CharField(max_length=255, default=DEFAULT_ARGS)
|
|
|
|
|
|
|
|
# START_CMD = models.CharField(max_length=255, default=DEFAULT_START_CMD)
|
|
|
|
# WORKERS = models.IntegerField(default=1)
|
|
|
|
|
|
|
|
class Meta:
|
|
|
|
abstract = False
|
|
|
|
app_label = 'system'
|
|
|
|
verbose_name = "Shell Environment: node"
|
|
|
|
|
|
|
|
|
2024-01-24 21:07:07 +13:00
|
|
|
class AptEnvironmentDependency(ArchiveBoxBaseDependency, SingletonModel):
|
|
|
|
singleton_instance_id = 1
|
|
|
|
|
|
|
|
id = models.AutoField(primary_key=True)
|
|
|
|
|
|
|
|
NAME = 'APT'
|
|
|
|
LABEL = "apt"
|
|
|
|
REQUIRED = False
|
|
|
|
|
2024-02-09 02:55:02 +13:00
|
|
|
PARENT_DEPENDENCIES = ['BashEnvironmentDependency']
|
2024-01-24 21:07:07 +13:00
|
|
|
|
|
|
|
BIN_DEPENDENCIES = ['apt-get']
|
|
|
|
APT_DEPENDENCIES = []
|
|
|
|
BREW_DEPENDENCIES = []
|
|
|
|
PIP_PACKAGES = []
|
|
|
|
NPM_PACKAGES = []
|
|
|
|
|
|
|
|
DEFAULT_BINARY = 'apt-get'
|
|
|
|
DEFAULT_START_CMD = None
|
|
|
|
DEFAULT_STOP_CMD = None
|
|
|
|
DEFAULT_PID_FILE = None
|
|
|
|
DEFAULT_ARGS = '-qq'
|
|
|
|
|
|
|
|
ENABLED = models.BooleanField(default=True, editable=not REQUIRED)
|
|
|
|
BINARY = models.CharField(max_length=255, default=DEFAULT_BINARY)
|
|
|
|
ARGS = models.CharField(max_length=255, default=DEFAULT_ARGS)
|
|
|
|
|
|
|
|
class Meta:
|
|
|
|
abstract = False
|
|
|
|
app_label = 'system'
|
2024-01-24 23:15:02 +13:00
|
|
|
verbose_name = "Package Manager: apt"
|
2024-01-24 21:07:07 +13:00
|
|
|
|
|
|
|
# @task
|
|
|
|
def install_pkgs(self, apt_pkgs=()):
|
|
|
|
assert self.is_valid, 'Apt environment is not available on this host'
|
|
|
|
|
2024-01-28 23:57:45 +13:00
|
|
|
# with huey.lock_task('apt-install'):
|
|
|
|
|
2024-01-24 21:07:07 +13:00
|
|
|
run(cmd=[self.DEFAULT_BINARY, '-qq', 'update'])
|
|
|
|
for apt_package in apt_pkgs:
|
|
|
|
run(cmd=[self.DEFAULT_BINARY, 'install', '-y', apt_package])
|
|
|
|
|
|
|
|
return True
|
|
|
|
|
|
|
|
class BrewEnvironmentDependency(ArchiveBoxBaseDependency, SingletonModel):
|
|
|
|
singleton_instance_id = 1
|
|
|
|
|
|
|
|
id = models.AutoField(primary_key=True)
|
|
|
|
|
|
|
|
NAME = 'BREW'
|
|
|
|
LABEL = "homebrew"
|
|
|
|
REQUIRED = False
|
|
|
|
|
2024-02-09 02:55:02 +13:00
|
|
|
PARENT_DEPENDENCIES = ['BashEnvironmentDependency']
|
2024-01-24 21:07:07 +13:00
|
|
|
|
|
|
|
BIN_DEPENDENCIES = ['brew']
|
|
|
|
APT_DEPENDENCIES = []
|
|
|
|
BREW_DEPENDENCIES = []
|
|
|
|
PIP_PACKAGES = []
|
|
|
|
NPM_PACKAGES = []
|
|
|
|
|
|
|
|
DEFAULT_BINARY = 'brew'
|
|
|
|
DEFAULT_START_CMD = None
|
|
|
|
DEFAULT_STOP_CMD = None
|
|
|
|
DEFAULT_PID_FILE = None
|
|
|
|
DEFAULT_ARGS = ''
|
|
|
|
|
|
|
|
ENABLED = models.BooleanField(default=True, editable=True)
|
|
|
|
BINARY = models.CharField(max_length=255, default=DEFAULT_BINARY)
|
|
|
|
ARGS = models.CharField(max_length=255, default=DEFAULT_ARGS)
|
|
|
|
|
|
|
|
class Meta:
|
|
|
|
abstract = False
|
|
|
|
app_label = 'system'
|
2024-01-24 23:15:02 +13:00
|
|
|
verbose_name = "Package Manager: brew"
|
2024-01-24 21:07:07 +13:00
|
|
|
|
|
|
|
# @task
|
|
|
|
def install_pkgs(self, brew_pkgs=()):
|
|
|
|
assert self.is_valid, 'Brw environment is not available on this host'
|
|
|
|
|
|
|
|
run(cmd=[self.DEFAULT_BINARY, 'update'])
|
|
|
|
|
|
|
|
for brew_pkg in brew_pkgs:
|
|
|
|
run(cmd=[self.DEFAULT_BINARY, 'install', brew_pkg])
|
|
|
|
|
|
|
|
return True
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class PipEnvironmentDependency(ArchiveBoxBaseDependency, SingletonModel):
|
|
|
|
singleton_instance_id = 1
|
|
|
|
|
|
|
|
id = models.AutoField(primary_key=True)
|
|
|
|
|
|
|
|
NAME = 'PIP'
|
|
|
|
LABEL = "pip"
|
|
|
|
REQUIRED = False
|
|
|
|
|
2024-02-09 02:55:02 +13:00
|
|
|
PARENT_DEPENDENCIES = ['BashEnvironmentDependency']
|
2024-01-24 21:07:07 +13:00
|
|
|
|
|
|
|
BIN_DEPENDENCIES = ['python3', 'pip3']
|
|
|
|
APT_DEPENDENCIES = ['python3.11', 'pip3', 'pipx']
|
|
|
|
BREW_DEPENDENCIES = ['python@3.11', 'pipx']
|
|
|
|
PIP_PACKAGES = ['setuptools', 'pipx']
|
|
|
|
NPM_PACKAGES = []
|
|
|
|
|
|
|
|
DEFAULT_BINARY = 'pip3'
|
|
|
|
DEFAULT_START_CMD = None
|
|
|
|
DEFAULT_STOP_CMD = None
|
|
|
|
DEFAULT_PID_FILE = None
|
|
|
|
DEFAULT_ARGS = ''
|
|
|
|
VERSION_CMD = '{BINARY} --version'
|
|
|
|
|
|
|
|
ENABLED = models.BooleanField(default=True, editable=True)
|
|
|
|
BINARY = models.CharField(max_length=255, default=DEFAULT_BINARY)
|
|
|
|
ARGS = models.CharField(max_length=255, default=DEFAULT_ARGS)
|
|
|
|
|
|
|
|
class Meta:
|
|
|
|
abstract = False
|
|
|
|
app_label = 'system'
|
2024-01-24 23:15:02 +13:00
|
|
|
verbose_name = "Package Manager: pip"
|
2024-01-24 21:07:07 +13:00
|
|
|
|
|
|
|
# @task
|
|
|
|
def install_pkgs(self, pip_pkgs=()):
|
|
|
|
assert self.is_valid, 'Pip environment is not available on this host'
|
|
|
|
|
|
|
|
for pip_pkg in pip_pkgs:
|
|
|
|
run(cmd=[self.DEFAULT_BINARY, 'install', '--update', '--ignore-installed', pip_pkg])
|
|
|
|
|
|
|
|
return True
|
|
|
|
|
|
|
|
|
|
|
|
class NPMEnvironmentDependency(ArchiveBoxBaseDependency, SingletonModel):
|
|
|
|
singleton_instance_id = 1
|
|
|
|
|
|
|
|
id = models.AutoField(primary_key=True)
|
|
|
|
|
|
|
|
NAME = 'NODEJS'
|
|
|
|
LABEL = "NodeJS"
|
|
|
|
REQUIRED = False
|
|
|
|
|
2024-02-09 02:55:02 +13:00
|
|
|
PARENT_DEPENDENCIES = ['BashEnvironmentDependency']
|
2024-01-24 21:07:07 +13:00
|
|
|
|
|
|
|
BIN_DEPENDENCIES = ['node', 'npm']
|
|
|
|
APT_DEPENDENCIES = ['node', 'npm']
|
|
|
|
BREW_DEPENDENCIES = ['node', 'npm']
|
|
|
|
PIP_PACKAGES = []
|
|
|
|
NPM_PACKAGES = ['npm']
|
|
|
|
|
|
|
|
DEFAULT_BINARY = 'node'
|
|
|
|
DEFAULT_START_CMD = None
|
|
|
|
DEFAULT_STOP_CMD = None
|
|
|
|
DEFAULT_PID_FILE = None
|
|
|
|
DEFAULT_ARGS = ''
|
|
|
|
VERSION_CMD = '{BINARY} --version'
|
|
|
|
|
|
|
|
ENABLED = models.BooleanField(default=True, editable=True)
|
|
|
|
BINARY = models.CharField(max_length=255, default=DEFAULT_BINARY)
|
|
|
|
ARGS = models.CharField(max_length=255, default=DEFAULT_ARGS)
|
|
|
|
|
|
|
|
class Meta:
|
|
|
|
abstract = False
|
|
|
|
app_label = 'system'
|
2024-01-24 23:15:02 +13:00
|
|
|
verbose_name = "Package Manager: npm"
|
2024-01-24 21:07:07 +13:00
|
|
|
|
|
|
|
# @task
|
|
|
|
def install_pkgs(self, npm_pkgs=()):
|
|
|
|
assert self.is_valid, 'NPM environment is not available on this host'
|
|
|
|
|
|
|
|
for npm_pkg in npm_pkgs:
|
|
|
|
run(cmd=[self.DEFAULT_BINARY, 'install', npm_pkg])
|
|
|
|
|
|
|
|
return True
|
|
|
|
|
|
|
|
|
|
|
|
class DjangoDependency(ArchiveBoxBaseDependency, SingletonModel):
|
|
|
|
singleton_instance_id = 1
|
|
|
|
|
|
|
|
id = models.AutoField(primary_key=True)
|
|
|
|
|
|
|
|
NAME = 'DJANGO'
|
|
|
|
LABEL = "Django"
|
|
|
|
REQUIRED = True
|
|
|
|
|
|
|
|
PARENT_DEPENDENCIES = []
|
|
|
|
|
|
|
|
BIN_DEPENDENCIES = ['django-admin.py']
|
|
|
|
APT_DEPENDENCIES = []
|
|
|
|
BREW_DEPENDENCIES = []
|
|
|
|
PIP_PACKAGES = ['django==3.1.14']
|
|
|
|
NPM_PACKAGES = []
|
|
|
|
|
|
|
|
DEFAULT_BINARY = 'django-admin.py'
|
|
|
|
DEFAULT_START_CMD = 'archivebox server 0.0.0.0:8000'
|
|
|
|
DEFAULT_PID_FILE = 'logs/{NAME}_WORKER.pid'
|
|
|
|
DEFAULT_STOP_CMD = 'kill "$(<{PID_FILE})"'
|
|
|
|
DEFAULT_ARGS = []
|
|
|
|
VERSION_CMD = '{BINARY} --version'
|
|
|
|
|
|
|
|
ENABLED = models.BooleanField(default=True, editable=False)
|
|
|
|
BINARY = models.CharField(max_length=255, default=DEFAULT_BINARY, editable=False)
|
|
|
|
ARGS = models.CharField(max_length=255, default=DEFAULT_ARGS, editable=False)
|
|
|
|
|
|
|
|
class Meta:
|
|
|
|
abstract = False
|
|
|
|
app_label = 'system'
|
2024-01-24 23:15:02 +13:00
|
|
|
verbose_name = "Internal Dependency: django"
|
2024-01-24 21:07:07 +13:00
|
|
|
|
|
|
|
@cached_property
|
|
|
|
def bin_path(self):
|
|
|
|
return inspect.getfile(django)
|
|
|
|
|
|
|
|
@cached_property
|
|
|
|
def bin_version(self):
|
2024-01-24 23:15:02 +13:00
|
|
|
return '.'.join(str(v) for v in django.VERSION[:3])
|
2024-01-24 21:07:07 +13:00
|
|
|
|
|
|
|
|
|
|
|
class SQLiteDependency(ArchiveBoxBaseDependency, SingletonModel):
|
|
|
|
singleton_instance_id = 1
|
|
|
|
|
|
|
|
id = models.AutoField(primary_key=True)
|
|
|
|
|
|
|
|
NAME = 'SQLITE'
|
|
|
|
LABEL = "SQLite"
|
|
|
|
REQUIRED = True
|
|
|
|
|
|
|
|
PARENT_DEPENDENCIES = []
|
|
|
|
|
|
|
|
BIN_DEPENDENCIES = []
|
|
|
|
APT_DEPENDENCIES = []
|
|
|
|
BREW_DEPENDENCIES = []
|
|
|
|
PIP_PACKAGES = []
|
|
|
|
NPM_PACKAGES = []
|
|
|
|
|
|
|
|
DEFAULT_BINARY = 'sqlite3'
|
|
|
|
DEFAULT_START_CMD = None
|
|
|
|
DEFAULT_STOP_CMD = None
|
|
|
|
DEFAULT_PID_FILE = None
|
|
|
|
DEFAULT_ARGS = []
|
|
|
|
VERSION_CMD = 'python3 -c ""'
|
|
|
|
|
|
|
|
ENABLED = models.BooleanField(default=True, editable=False)
|
|
|
|
BINARY = models.CharField(max_length=255, default=DEFAULT_BINARY, editable=False)
|
|
|
|
ARGS = models.CharField(max_length=255, default=DEFAULT_ARGS, editable=False)
|
|
|
|
|
|
|
|
class Meta:
|
|
|
|
abstract = False
|
|
|
|
app_label = 'system'
|
2024-01-24 23:15:02 +13:00
|
|
|
verbose_name = "Internal Dependency: sqlite3"
|
2024-01-24 21:07:07 +13:00
|
|
|
|
|
|
|
@cached_property
|
|
|
|
def bin_path(self):
|
|
|
|
return inspect.getfile(sqlite3)
|
|
|
|
|
|
|
|
@cached_property
|
|
|
|
def bin_version(self):
|
|
|
|
return sqlite3.version
|
|
|
|
|
2024-01-24 23:15:02 +13:00
|
|
|
class ArchiveBoxDependency(ArchiveBoxBaseDependency):
|
2024-01-24 21:07:07 +13:00
|
|
|
singleton_instance_id = 1
|
|
|
|
|
|
|
|
id = models.AutoField(primary_key=True)
|
|
|
|
|
|
|
|
NAME = 'ARCHIVEBOX'
|
|
|
|
LABEL = "ArchiveBox"
|
|
|
|
REQUIRED = True
|
|
|
|
|
|
|
|
PARENT_DEPENDENCIES = [
|
2024-02-09 02:55:02 +13:00
|
|
|
'PipEnvironmentDependency',
|
|
|
|
'DjangoDependency',
|
|
|
|
'SQLiteDependency',
|
2024-01-24 21:07:07 +13:00
|
|
|
]
|
|
|
|
|
|
|
|
BIN_DEPENDENCIES = ['archivebox']
|
|
|
|
APT_DEPENDENCIES = []
|
|
|
|
BREW_DEPENDENCIES = []
|
|
|
|
PIP_PACKAGES = ['archivebox']
|
|
|
|
NPM_PACKAGES = []
|
|
|
|
|
|
|
|
DEFAULT_BINARY = 'archivebox'
|
|
|
|
DEFAULT_START_CMD = '{BINARY} server 0.0.0.0:8000'
|
|
|
|
DEFAULT_ARGS = []
|
|
|
|
VERSION_CMD = 'archivebox --version'
|
|
|
|
|
|
|
|
ENABLED = models.BooleanField(default=True, editable=False)
|
|
|
|
BINARY = models.CharField(max_length=255, default=DEFAULT_BINARY, editable=False)
|
|
|
|
ARGS = models.CharField(max_length=255, default=DEFAULT_ARGS, editable=False)
|
|
|
|
|
|
|
|
class Meta:
|
|
|
|
abstract = False
|
|
|
|
app_label = 'system'
|
2024-01-24 23:15:02 +13:00
|
|
|
verbose_name = "Internal Dependency: archivebox"
|
2024-01-24 21:07:07 +13:00
|
|
|
|
|
|
|
@cached_property
|
|
|
|
def bin_path(self):
|
|
|
|
return sys.argv[0] or bin_path('archivebox')
|
|
|
|
|
|
|
|
@cached_property
|
|
|
|
def bin_version(self):
|
|
|
|
# return config['VERSION']
|
2024-01-24 23:15:02 +13:00
|
|
|
return VERSION
|
2024-01-24 21:07:07 +13:00
|
|
|
|