create datadir on launch (#1674)

* create datadir on launch
* change makedirs to Path.mkdir
This commit is contained in:
dni ⚡ 2023-05-09 10:04:27 +02:00 committed by GitHub
parent 159aa24a4e
commit 45b199a8ef
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 7 additions and 3 deletions

View File

@ -180,7 +180,7 @@ class Extension(NamedTuple):
class ExtensionManager: class ExtensionManager:
def __init__(self): def __init__(self):
p = Path(settings.lnbits_path, "extensions") 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()] self._extension_folders: List[Path] = [f for f in p.iterdir() if f.is_dir()]
@property @property
@ -283,7 +283,7 @@ class InstallableExtension(BaseModel):
@property @property
def zip_path(self) -> Path: def zip_path(self) -> Path:
extensions_data_dir = Path(settings.lnbits_data_folder, "extensions") 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") return Path(extensions_data_dir, f"{self.id}.zip")
@property @property
@ -335,7 +335,7 @@ class InstallableExtension(BaseModel):
def extract_archive(self): def extract_archive(self):
logger.info(f"Extracting extension {self.name}.") 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) shutil.rmtree(self.ext_upgrade_dir, True)
with zipfile.ZipFile(self.zip_path, "r") as zip_ref: with zipfile.ZipFile(self.zip_path, "r") as zip_ref:
zip_ref.extractall(self.ext_upgrade_dir) zip_ref.extractall(self.ext_upgrade_dir)

View File

@ -4,6 +4,7 @@ uvloop.install()
import multiprocessing as mp import multiprocessing as mp
import time import time
from pathlib import Path
import click import click
import uvicorn import uvicorn
@ -37,6 +38,9 @@ def main(
): ):
"""Launched with `poetry run lnbits` at root level""" """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) 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 # this beautiful beast parses all command line arguments and passes them to the uvicorn server