From 255d97d42f27eb0046a713140a1c3491fcb4fb21 Mon Sep 17 00:00:00 2001 From: boyska Date: Wed, 3 Mar 2021 01:10:32 +0100 Subject: [PATCH] REMOVE_UNUSED_FILES option --- doc/source/install.rst | 8 +++++++- larigira/config.py | 7 ++++++- larigira/unused.py | 9 ++++++--- 3 files changed, 19 insertions(+), 5 deletions(-) diff --git a/doc/source/install.rst b/doc/source/install.rst index 6b9b182..59d44cc 100644 --- a/doc/source/install.rst +++ b/doc/source/install.rst @@ -68,7 +68,7 @@ MPD_PORT If you are not using a socket, but a TCP address (which is *not* suggested), this is how you can specify the port. DEBUG - you can set it to ``true`` or ``false``. Defaults to ``false``. + you can set it to ``true`` or ``false``. Defaults to ``false``. Will enable extremely verbose output. TMPDIR The base for larigira tmpdir. Please note that larigira will create its own directory inside this temporary directory. This defaults to the system-wide ``$TMPDIR``, or to ``/tmp/`` if not ``TMPDIR`` is @@ -154,3 +154,9 @@ LARIGIRA_UI_CALENDAR_DATE_FMT The format to show in ``/db/calendar`` page. The format is specified `here `_. Default is ``medium``. As an example, ``eee dd LLL`` will show ``Sun 10 Mar`` for english, and ``dom 10 mar`` for italian. + +Debug and development +^^^^^^^^^^^^^^^^^^^^^^^ + +REMOVE_UNUSED_FILES + By default, larigira removes the file it generates, as soon as they are no longer in MPD playlist. There is no good reason to change this behavior, unless you need to debug what's going on. For example, if you want to inspect files. Set this to `false` keep everything. diff --git a/larigira/config.py b/larigira/config.py index f4288b8..e9f9de5 100644 --- a/larigira/config.py +++ b/larigira/config.py @@ -30,6 +30,9 @@ def get_conf(prefix="LARIGIRA_"): conf["CHECK_SECS"] = 20 # period for checking playlist length conf["EVENT_TICK_SECS"] = 30 # period for scheduling events conf["DEBUG"] = False + conf[ + "REMOVE_UNUSED_FILES" + ] = True # please keep it to True unless you are into deep debugging! conf["LOG_CONFIG"] = False conf["TMPDIR"] = os.getenv("TMPDIR", "/tmp/") conf["FILE_PATH_SUGGESTION"] = () # tuple of paths @@ -71,7 +74,9 @@ def from_envvars(prefix=None, envvars=None, as_json=True): if not envvars: envvars = { - k: k[len(prefix) :] for k in os.environ.keys() if k.startswith(prefix) + k: k[len(prefix) :] + for k in os.environ.keys() + if k.startswith(prefix) } for env_name, name in envvars.items(): diff --git a/larigira/unused.py b/larigira/unused.py index d7bb055..52f190f 100644 --- a/larigira/unused.py +++ b/larigira/unused.py @@ -4,9 +4,10 @@ This component will look for files to be removed. There are some assumptions: own specific TMPDIR * MPD URIs are parsed, and only file:/// is supported """ +import logging import os from os.path import normpath -import logging + import mpd @@ -64,11 +65,13 @@ class UnusedCleaner: """check playlist + internal watchlist to see what can be removed""" mpdc = self._get_mpd() files_in_playlist = { - song["file"] for song in mpdc.playlistid() if song["file"].startswith("/") + song["file"] + for song in mpdc.playlistid() + if song["file"].startswith("/") } for fpath in self.waiting_removal_files - files_in_playlist: # we can remove it! self.log.debug("removing unused: %s", fpath) self.waiting_removal_files.remove(fpath) - if os.path.exists(fpath): + if os.path.exists(fpath) and self.conf["REMOVE_UNUSED_FILES"]: os.unlink(fpath)