diff --git a/.bumpversion.cfg b/.bumpversion.cfg index d332eb4..02482c5 100644 --- a/.bumpversion.cfg +++ b/.bumpversion.cfg @@ -1,5 +1,5 @@ [bumpversion] -current_version = 0.3.2 +current_version = 0.3.1 commit = True tag = True diff --git a/pyproject.toml b/pyproject.toml index d2ba66e..96ab12a 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "ucast" -version = "0.3.2" +version = "0.3.1" description = "YouTube to Podcast converter" authors = ["Theta-Dev "] packages = [ diff --git a/ucast/__init__.py b/ucast/__init__.py index 0b6e0b2..521568f 100644 --- a/ucast/__init__.py +++ b/ucast/__init__.py @@ -1,4 +1,4 @@ -__version__ = "0.3.2" +__version__ = "0.3.1" def template_context(request): diff --git a/ucast/service/storage.py b/ucast/service/storage.py index e1b6af0..e0a87ba 100644 --- a/ucast/service/storage.py +++ b/ucast/service/storage.py @@ -1,7 +1,5 @@ import os -import shutil import tempfile -from datetime import datetime, timedelta from pathlib import Path from django.conf import settings @@ -75,18 +73,3 @@ class Cache: def create_tmpdir(self, prefix="dld") -> tempfile.TemporaryDirectory: return tempfile.TemporaryDirectory(prefix=prefix + "_", dir=self.dir_cache) - - def cleanup(self): - """ - Delete temporary directories that are older than 24h and are most likely left - over after unexpected shutdowns. - """ - for dirname in os.listdir(self.dir_cache): - if dirname == "yt_dlp": - continue - - ctime = os.path.getctime(dirname) - age = datetime.now() - datetime.fromtimestamp(ctime) - - if age > timedelta(days=1): - shutil.rmtree(self.dir_cache / dirname) diff --git a/ucast/tasks/library.py b/ucast/tasks/library.py index 2a19bb6..b6b3481 100644 --- a/ucast/tasks/library.py +++ b/ucast/tasks/library.py @@ -105,8 +105,3 @@ def update_channel_info(channel: Channel): def update_channel_infos(): for channel in Channel.objects.filter(active=True): queue.enqueue(update_channel_info, channel) - - -def clean_cache(): - cache = storage.Cache() - cache.cleanup() diff --git a/ucast/tasks/schedule.py b/ucast/tasks/schedule.py index 9786e93..f56b86b 100644 --- a/ucast/tasks/schedule.py +++ b/ucast/tasks/schedule.py @@ -1,5 +1,5 @@ import logging -from datetime import datetime, timedelta +from datetime import datetime from django.conf import settings @@ -28,15 +28,8 @@ def register_scheduled_jobs(): ) scheduler.schedule( - datetime.utcnow() + timedelta(days=1), + datetime.utcnow(), library.update_channel_infos, id="schedule_update_channel_infos", interval=24 * 3600, ) - - scheduler.schedule( - datetime.utcnow() + timedelta(days=1), - library.clean_cache, - id="schedule_clean_cache", - interval=24 * 3600, - ) diff --git a/ucast/tests/service/test_storage.py b/ucast/tests/service/test_storage.py index fa99f2a..083e3e5 100644 --- a/ucast/tests/service/test_storage.py +++ b/ucast/tests/service/test_storage.py @@ -1,6 +1,5 @@ import os import tempfile -from datetime import datetime, timedelta from pathlib import Path from ucast.service import storage @@ -55,30 +54,3 @@ def test_channel_folder(): == ucast_dir / "thumbnails" / "my_video_title_sm.webp" ) assert cf.get_audio("my_video_title") == tmpdir / "my_video_title.mp3" - - -def test_clean_cache(settings, mocker): - tmpdir_o = tempfile.TemporaryDirectory() - tmpdir = Path(tmpdir_o.name) - - os.mkdir(tmpdir / "yt_dlp") - os.mkdir(tmpdir / "dld_old") - os.mkdir(tmpdir / "dld_new") - - def mock_ctime(path): - if path == "dld_new": - return datetime.now().timestamp() - if path == "dld_old": - return (datetime.now() - timedelta(days=1, minutes=1)).timestamp() - raise Exception("invalid path") - - mocker.patch.object(os.path, "getctime", mock_ctime) - - settings.CACHE_ROOT = tmpdir - cache = storage.Cache() - - cache.cleanup() - - assert os.path.isdir(tmpdir / "yt_dlp") - assert os.path.isdir(tmpdir / "dld_new") - assert not os.path.exists(tmpdir / "dld_old") diff --git a/ucast_project/settings.py b/ucast_project/settings.py index b98373b..3e16b0a 100644 --- a/ucast_project/settings.py +++ b/ucast_project/settings.py @@ -32,11 +32,8 @@ def get_env(name, default=None): def get_env_path(name, default=None): raw_env = get_env(name) if not raw_env: - folder = default - else: - folder = Path(raw_env).absolute() - os.makedirs(folder, exist_ok=True) - return folder + return default + return Path(raw_env).absolute() def get_env_list(name): @@ -145,7 +142,7 @@ def _get_db_config() -> dict: if db_engine == "sqlite": return { "ENGINE": "django.db.backends.sqlite3", - "NAME": DB_DIR / f"{db_name}.sqlite", + "NAME": BASE_DIR / f"{db_name}.sqlite", } db_port = get_env("DB_PORT") @@ -165,18 +162,6 @@ def _get_db_config() -> dict: } -# Static files (CSS, JavaScript, Images) -# https://docs.djangoproject.com/en/4.0/howto/static-files/ - -STATIC_URL = "static/" -STATIC_ROOT = get_env_path("STATIC_ROOT", BASE_DIR / "static") -DOWNLOAD_ROOT = get_env_path("DOWNLOAD_ROOT", BASE_DIR / "data") -CACHE_ROOT = get_env_path("CACHE_ROOT", BASE_DIR / "cache") -DB_DIR = get_env_path("DB_DIR", BASE_DIR / "db") - -STATICFILES_DIRS = [resources.path("ucast", "static")] - - # Database # https://docs.djangoproject.com/en/4.0/ref/settings/#databases DATABASES = { @@ -217,6 +202,16 @@ USE_I18N = True USE_TZ = True +# Static files (CSS, JavaScript, Images) +# https://docs.djangoproject.com/en/4.0/howto/static-files/ + +STATIC_URL = "static/" +STATIC_ROOT = get_env_path("STATIC_ROOT", BASE_DIR / "static") +DOWNLOAD_ROOT = get_env_path("DOWNLOAD_ROOT", BASE_DIR / "data") +CACHE_ROOT = get_env_path("CACHE_ROOT", BASE_DIR / "cache") + +STATICFILES_DIRS = [resources.path("ucast", "static")] + # Default primary key field type # https://docs.djangoproject.com/en/4.0/ref/settings/#default-auto-field