diff --git a/tubearchivist/config/management/commands/ta_config_backup.py b/tubearchivist/config/management/commands/ta_config_backup.py new file mode 100644 index 00000000..40802ddd --- /dev/null +++ b/tubearchivist/config/management/commands/ta_config_backup.py @@ -0,0 +1,76 @@ +"""backup config for sqlite reset and restore""" + +import json +from pathlib import Path + +from django.contrib.auth import get_user_model +from django.core.management.base import BaseCommand +from home.models import CustomPeriodicTask +from home.src.ta.settings import EnvironmentSettings +from rest_framework.authtoken.models import Token + +User = get_user_model() + + +class Command(BaseCommand): + """export""" + + help = "Exports all users and their auth tokens to a JSON file" + FILE = Path(EnvironmentSettings.CACHE_DIR) / "backup" / "migration.json" + + def handle(self, *args, **kwargs): + """entry point""" + + data = { + "user_data": self.get_users(), + "schedule_data": self.get_schedules(), + } + + with open(self.FILE, "w", encoding="utf-8") as json_file: + json_file.write(json.dumps(data)) + + def get_users(self): + """get users""" + + users = User.objects.all() + + user_data = [] + + for user in users: + user_info = { + "username": user.name, + "is_staff": user.is_staff, + "is_superuser": user.is_superuser, + "password": user.password, + "tokens": [], + } + + try: + token = Token.objects.get(user=user) + user_info["tokens"] = [token.key] + except Token.DoesNotExist: + user_info["tokens"] = [] + + user_data.append(user_info) + + return user_data + + def get_schedules(self): + """get schedules""" + + all_schedules = CustomPeriodicTask.objects.all() + schedule_data = [] + + for schedule in all_schedules: + schedule_info = { + "name": schedule.name, + "crontab": { + "minute": schedule.crontab.minute, + "hour": schedule.crontab.hour, + "day_of_week": schedule.crontab.day_of_week, + }, + } + + schedule_data.append(schedule_info) + + return schedule_data diff --git a/tubearchivist/config/settings.py b/tubearchivist/config/settings.py index da90ffff..012ede28 100644 --- a/tubearchivist/config/settings.py +++ b/tubearchivist/config/settings.py @@ -276,4 +276,4 @@ CORS_ALLOW_HEADERS = list(default_headers) + [ # TA application settings TA_UPSTREAM = "https://github.com/tubearchivist/tubearchivist" -TA_VERSION = "v0.4.12" +TA_VERSION = "v0.4.13-unstable" diff --git a/tubearchivist/requirements-dev.txt b/tubearchivist/requirements-dev.txt index 3aac969a..d3e1039f 100644 --- a/tubearchivist/requirements-dev.txt +++ b/tubearchivist/requirements-dev.txt @@ -4,8 +4,8 @@ codespell==2.3.0 flake8==7.1.1 isort==5.13.2 pylint-django==2.6.1 -pylint==3.3.2 +pylint==3.3.3 pytest-django==4.9.0 pytest==8.3.4 -requirementscheck==0.0.4 +requirementscheck==0.0.5 types-requests==2.32.0.20241016 diff --git a/tubearchivist/requirements.txt b/tubearchivist/requirements.txt index b2a3f921..61693f9f 100644 --- a/tubearchivist/requirements.txt +++ b/tubearchivist/requirements.txt @@ -1,14 +1,14 @@ -apprise==1.9.1 +apprise==1.9.2 celery==5.4.0 django-auth-ldap==5.1.0 django-celery-beat==2.7.0 django-cors-headers==4.6.0 -Django==5.1.4 +Django==5.1.5 djangorestframework==3.15.2 -Pillow==11.0.0 +Pillow==11.1.0 redis==5.2.1 requests==2.32.3 ryd-client==0.0.6 uWSGI==2.0.28 whitenoise==6.8.2 -yt-dlp[default]==2024.12.13 +yt-dlp[default]==2025.1.12