From 45b199a8efb02f81ecaa59031c9e36239f190807 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?dni=20=E2=9A=A1?= Date: Tue, 9 May 2023 10:04:27 +0200 Subject: [PATCH] create datadir on launch (#1674) * create datadir on launch * change makedirs to Path.mkdir --- lnbits/extension_manager.py | 6 +++--- lnbits/server.py | 4 ++++ 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/lnbits/extension_manager.py b/lnbits/extension_manager.py index 092f2f97..8f3163b1 100644 --- a/lnbits/extension_manager.py +++ b/lnbits/extension_manager.py @@ -180,7 +180,7 @@ class Extension(NamedTuple): class ExtensionManager: def __init__(self): p = Path(settings.lnbits_path, "extensions") - os.makedirs(p, exist_ok=True) + Path(p).mkdir(parents=True, exist_ok=True) self._extension_folders: List[Path] = [f for f in p.iterdir() if f.is_dir()] @property @@ -283,7 +283,7 @@ class InstallableExtension(BaseModel): @property def zip_path(self) -> Path: extensions_data_dir = Path(settings.lnbits_data_folder, "extensions") - os.makedirs(extensions_data_dir, exist_ok=True) + Path(extensions_data_dir).mkdir(parents=True, exist_ok=True) return Path(extensions_data_dir, f"{self.id}.zip") @property @@ -335,7 +335,7 @@ class InstallableExtension(BaseModel): def extract_archive(self): logger.info(f"Extracting extension {self.name}.") - os.makedirs(Path("lnbits", "upgrades"), exist_ok=True) + Path("lnbits", "upgrades").mkdir(parents=True, exist_ok=True) shutil.rmtree(self.ext_upgrade_dir, True) with zipfile.ZipFile(self.zip_path, "r") as zip_ref: zip_ref.extractall(self.ext_upgrade_dir) diff --git a/lnbits/server.py b/lnbits/server.py index 70b15868..7e216936 100644 --- a/lnbits/server.py +++ b/lnbits/server.py @@ -4,6 +4,7 @@ uvloop.install() import multiprocessing as mp import time +from pathlib import Path import click import uvicorn @@ -37,6 +38,9 @@ def main( ): """Launched with `poetry run lnbits` at root level""" + # create data dir if it does not exist + Path(settings.lnbits_data_folder).mkdir(parents=True, exist_ok=True) + set_cli_settings(host=host, port=port, forwarded_allow_ips=forwarded_allow_ips) # this beautiful beast parses all command line arguments and passes them to the uvicorn server