Browse Source

REMOVE_UNUSED_FILES option

boyska 3 years ago
parent
commit
255d97d42f
3 changed files with 19 additions and 5 deletions
  1. 7 1
      doc/source/install.rst
  2. 6 1
      larigira/config.py
  3. 6 3
      larigira/unused.py

+ 7 - 1
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
     If you are not using a socket, but a TCP address (which is *not* suggested), this is how you can specify the
     port.
     port.
 DEBUG
 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
 TMPDIR
     The base for larigira tmpdir. Please note that larigira will create its own directory inside this
     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
     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 <http://babel.pocoo.org/en/latest/dates.html>`_. Default is ``medium``.
     The format to show in ``/db/calendar`` page. The format is specified `here <http://babel.pocoo.org/en/latest/dates.html>`_. Default is ``medium``.
 
 
     As an example, ``eee dd LLL`` will show ``Sun 10 Mar`` for english, and ``dom 10 mar`` for italian.
     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.

+ 6 - 1
larigira/config.py

@@ -30,6 +30,9 @@ def get_conf(prefix="LARIGIRA_"):
     conf["CHECK_SECS"] = 20  # period for checking playlist length
     conf["CHECK_SECS"] = 20  # period for checking playlist length
     conf["EVENT_TICK_SECS"] = 30  # period for scheduling events
     conf["EVENT_TICK_SECS"] = 30  # period for scheduling events
     conf["DEBUG"] = False
     conf["DEBUG"] = False
+    conf[
+        "REMOVE_UNUSED_FILES"
+    ] = True  # please keep it to True unless you are into deep debugging!
     conf["LOG_CONFIG"] = False
     conf["LOG_CONFIG"] = False
     conf["TMPDIR"] = os.getenv("TMPDIR", "/tmp/")
     conf["TMPDIR"] = os.getenv("TMPDIR", "/tmp/")
     conf["FILE_PATH_SUGGESTION"] = ()  # tuple of paths
     conf["FILE_PATH_SUGGESTION"] = ()  # tuple of paths
@@ -71,7 +74,9 @@ def from_envvars(prefix=None, envvars=None, as_json=True):
 
 
     if not envvars:
     if not envvars:
         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():
     for env_name, name in envvars.items():

+ 6 - 3
larigira/unused.py

@@ -4,9 +4,10 @@ This component will look for files to be removed. There are some assumptions:
       own specific TMPDIR
       own specific TMPDIR
     * MPD URIs are parsed, and only file:/// is supported
     * MPD URIs are parsed, and only file:/// is supported
 """
 """
+import logging
 import os
 import os
 from os.path import normpath
 from os.path import normpath
-import logging
+
 import mpd
 import mpd
 
 
 
 
@@ -64,11 +65,13 @@ class UnusedCleaner:
         """check playlist + internal watchlist to see what can be removed"""
         """check playlist + internal watchlist to see what can be removed"""
         mpdc = self._get_mpd()
         mpdc = self._get_mpd()
         files_in_playlist = {
         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:
         for fpath in self.waiting_removal_files - files_in_playlist:
             # we can remove it!
             # we can remove it!
             self.log.debug("removing unused: %s", fpath)
             self.log.debug("removing unused: %s", fpath)
             self.waiting_removal_files.remove(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)
                 os.unlink(fpath)