[BACKEND] File lock directory config parameter (#455)
* [BACKEND] File lock directory config parameter * [BACKEND] File lock directory config parameter
This commit is contained in:
parent
74c7c3be01
commit
251cd541ec
2 changed files with 20 additions and 5 deletions
|
|
@ -4,7 +4,6 @@ import fcntl
|
||||||
import gc
|
import gc
|
||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
import tempfile
|
|
||||||
from contextlib import contextmanager
|
from contextlib import contextmanager
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from typing import List
|
from typing import List
|
||||||
|
|
@ -133,7 +132,11 @@ def _working_directory_lock(config: ConfigFile):
|
||||||
Other lock error occurred
|
Other lock error occurred
|
||||||
"""
|
"""
|
||||||
working_directory_path = Path(os.getcwd()) / config.config_options.working_directory
|
working_directory_path = Path(os.getcwd()) / config.config_options.working_directory
|
||||||
lock_file_path = Path(tempfile.gettempdir()) / str(working_directory_path).replace("/", "_")
|
lock_file_path = (
|
||||||
|
Path(os.getcwd())
|
||||||
|
/ config.config_options.lock_directory
|
||||||
|
/ str(working_directory_path).replace("/", "_")
|
||||||
|
)
|
||||||
|
|
||||||
lock_file = open(lock_file_path, "w", encoding="utf-8")
|
lock_file = open(lock_file_path, "w", encoding="utf-8")
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -12,7 +12,7 @@ from ytdl_sub.validators.validators import StringValidator
|
||||||
|
|
||||||
class ConfigOptions(StrictDictValidator):
|
class ConfigOptions(StrictDictValidator):
|
||||||
_required_keys = {"working_directory"}
|
_required_keys = {"working_directory"}
|
||||||
_optional_keys = {"umask", "dl_aliases"}
|
_optional_keys = {"umask", "dl_aliases", "lock_directory"}
|
||||||
|
|
||||||
def __init__(self, name: str, value: Any):
|
def __init__(self, name: str, value: Any):
|
||||||
super().__init__(name, value)
|
super().__init__(name, value)
|
||||||
|
|
@ -26,6 +26,9 @@ class ConfigOptions(StrictDictValidator):
|
||||||
self._dl_aliases = self._validate_key_if_present(
|
self._dl_aliases = self._validate_key_if_present(
|
||||||
key="dl_aliases", validator=LiteralDictValidator
|
key="dl_aliases", validator=LiteralDictValidator
|
||||||
)
|
)
|
||||||
|
self._lock_directory = self._validate_key(
|
||||||
|
key="lock_directory", validator=StringValidator, default="/tmp"
|
||||||
|
)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def working_directory(self) -> str:
|
def working_directory(self) -> str:
|
||||||
|
|
@ -38,14 +41,14 @@ class ConfigOptions(StrictDictValidator):
|
||||||
@property
|
@property
|
||||||
def umask(self) -> Optional[str]:
|
def umask(self) -> Optional[str]:
|
||||||
"""
|
"""
|
||||||
Umask (octal format) to apply to every created file. Defaults to "022".
|
Optional. Umask (octal format) to apply to every created file. Defaults to "022".
|
||||||
"""
|
"""
|
||||||
return self._umask.value
|
return self._umask.value
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def dl_aliases(self) -> Optional[Dict[str, str]]:
|
def dl_aliases(self) -> Optional[Dict[str, str]]:
|
||||||
"""
|
"""
|
||||||
Alias definitions to shorten ``ytdl-sub dl`` arguments. For example,
|
Optional. Alias definitions to shorten ``ytdl-sub dl`` arguments. For example,
|
||||||
|
|
||||||
.. code-block:: yaml
|
.. code-block:: yaml
|
||||||
|
|
||||||
|
|
@ -70,6 +73,15 @@ class ConfigOptions(StrictDictValidator):
|
||||||
return self._dl_aliases.dict
|
return self._dl_aliases.dict
|
||||||
return {}
|
return {}
|
||||||
|
|
||||||
|
@property
|
||||||
|
def lock_directory(self) -> str:
|
||||||
|
"""
|
||||||
|
Optional. The directory to temporarily store file locks, which prevents multiple instances
|
||||||
|
of ``ytdl-sub`` from running. Note that file locks do not work on network-mounted
|
||||||
|
directories. Ensure that this directory resides on the host machine. Defaults to ``/tmp``.
|
||||||
|
"""
|
||||||
|
return self._lock_directory.value
|
||||||
|
|
||||||
|
|
||||||
class ConfigValidator(StrictDictValidator):
|
class ConfigValidator(StrictDictValidator):
|
||||||
_required_keys = {"configuration", "presets"}
|
_required_keys = {"configuration", "presets"}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue