fix: keep upgrades out of codebase (#2957)
* fix: keep upgrades out of codebase * chore: code format
This commit is contained in:
parent
1cef614349
commit
b76d8b5458
4 changed files with 13 additions and 16 deletions
|
|
@ -366,6 +366,11 @@ async def restore_installed_extension(app: FastAPI, ext: InstallableExtension):
|
|||
|
||||
|
||||
def register_custom_extensions_path():
|
||||
upgrades_dir = settings.lnbits_extensions_upgrade_path
|
||||
shutil.rmtree(upgrades_dir, True)
|
||||
Path(upgrades_dir).mkdir(parents=True, exist_ok=True)
|
||||
sys.path.append(str(upgrades_dir))
|
||||
|
||||
if settings.has_default_extension_path:
|
||||
return
|
||||
default_ext_path = os.path.join("lnbits", "extensions")
|
||||
|
|
@ -384,11 +389,6 @@ def register_custom_extensions_path():
|
|||
Path(extensions_dir).mkdir(parents=True, exist_ok=True)
|
||||
sys.path.append(str(extensions_dir))
|
||||
|
||||
upgrades_dir = Path(settings.lnbits_extensions_path, "upgrades")
|
||||
shutil.rmtree(upgrades_dir, True)
|
||||
Path(upgrades_dir).mkdir(parents=True, exist_ok=True)
|
||||
sys.path.append(str(upgrades_dir))
|
||||
|
||||
|
||||
def register_new_ext_routes(app: FastAPI) -> Callable:
|
||||
# Returns a function that registers new routes for an extension.
|
||||
|
|
|
|||
|
|
@ -339,7 +339,7 @@ async def extensions_update(
|
|||
if not await _can_run_operation(url):
|
||||
return
|
||||
|
||||
upgrades_dir = Path(settings.lnbits_extensions_path, "upgrades")
|
||||
upgrades_dir = settings.lnbits_extensions_upgrade_path
|
||||
Path(upgrades_dir).mkdir(parents=True, exist_ok=True)
|
||||
sys.path.append(str(upgrades_dir))
|
||||
|
||||
|
|
|
|||
|
|
@ -148,8 +148,6 @@ class Extension(BaseModel):
|
|||
@property
|
||||
def module_name(self) -> str:
|
||||
if self.is_upgrade_extension:
|
||||
if settings.has_default_extension_path:
|
||||
return f"lnbits.upgrades.{self.code}-{self.upgrade_hash}"
|
||||
return f"{self.code}-{self.upgrade_hash}"
|
||||
|
||||
if settings.has_default_extension_path:
|
||||
|
|
@ -343,15 +341,11 @@ class InstallableExtension(BaseModel):
|
|||
|
||||
@property
|
||||
def ext_upgrade_dir(self) -> Path:
|
||||
return Path(
|
||||
settings.lnbits_extensions_path, "upgrades", f"{self.id}-{self.hash}"
|
||||
)
|
||||
return Path(settings.lnbits_extensions_upgrade_path, f"{self.id}-{self.hash}")
|
||||
|
||||
@property
|
||||
def module_name(self) -> str:
|
||||
if self.ext_upgrade_dir.is_dir():
|
||||
if settings.has_default_extension_path:
|
||||
return f"lnbits.upgrades.{self.id}-{self.hash}"
|
||||
return f"{self.id}-{self.hash}"
|
||||
|
||||
if settings.has_default_extension_path:
|
||||
|
|
@ -411,9 +405,7 @@ class InstallableExtension(BaseModel):
|
|||
|
||||
def extract_archive(self):
|
||||
logger.info(f"Extracting extension {self.name} ({self.installed_version}).")
|
||||
Path(settings.lnbits_extensions_path, "upgrades").mkdir(
|
||||
parents=True, exist_ok=True
|
||||
)
|
||||
Path(settings.lnbits_extensions_upgrade_path).mkdir(parents=True, exist_ok=True)
|
||||
|
||||
tmp_dir = Path(settings.lnbits_data_folder, "unzip-temp", self.hash)
|
||||
shutil.rmtree(tmp_dir, True)
|
||||
|
|
|
|||
|
|
@ -9,6 +9,7 @@ from datetime import datetime, timezone
|
|||
from enum import Enum
|
||||
from hashlib import sha256
|
||||
from os import path
|
||||
from pathlib import Path
|
||||
from time import gmtime, strftime, time
|
||||
from typing import Any, Optional
|
||||
|
||||
|
|
@ -859,6 +860,10 @@ class ReadOnlySettings(
|
|||
):
|
||||
lnbits_admin_ui: bool = Field(default=True)
|
||||
|
||||
@property
|
||||
def lnbits_extensions_upgrade_path(self) -> str:
|
||||
return str(Path(self.lnbits_data_folder, "upgrades"))
|
||||
|
||||
@validator(
|
||||
"lnbits_allowed_funding_sources",
|
||||
pre=True,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue