2023-03-17 18:25:35 +01:00
|
|
|
"""
|
|
|
|
core.pkg.backend - Remote backend constructor
|
2022-05-18 16:04:56 +02:00
|
|
|
|
2023-03-17 18:25:35 +01:00
|
|
|
This package will exposes the major important object for the package core
|
|
|
|
remote part of the vxsdk.
|
2022-05-18 16:04:56 +02:00
|
|
|
|
|
|
|
=========================== ============================================
|
|
|
|
Object name Description
|
|
|
|
=========================== ============================================
|
2022-11-03 10:43:24 +01:00
|
|
|
PKG_CORE_BACKEND_REMOTE Remote ackend object
|
|
|
|
PKG_CORE_BACKEND_LOCAL Local backend object
|
|
|
|
VxRemoteBackend Abstract class for backend implementation
|
|
|
|
=========================== ======================================
|
2022-05-18 16:04:56 +02:00
|
|
|
|
|
|
|
This part of the vxsdk can be manually configured using a TOML configuration
|
2022-11-03 10:43:24 +01:00
|
|
|
which need to be located at <~/.config/vxsdk/configure.toml>. A special
|
2022-05-18 16:04:56 +02:00
|
|
|
section named 'package.remote' can be added to specify backend information:
|
|
|
|
|
2022-11-03 10:43:24 +01:00
|
|
|
[pkg]
|
2022-05-18 16:04:56 +02:00
|
|
|
backend.name = 'gitea'
|
|
|
|
backend.url = 'https://personal.gitea.instance.gaming'
|
|
|
|
|
|
|
|
This is the only configuration that you can set here.
|
|
|
|
"""
|
|
|
|
import os
|
2022-11-03 10:43:24 +01:00
|
|
|
import sys
|
2022-05-18 16:04:56 +02:00
|
|
|
|
2022-08-02 11:34:41 +02:00
|
|
|
from core.pkg.backend.local import VxBackendLocal
|
2022-11-03 10:43:24 +01:00
|
|
|
from core.logger import log
|
2023-03-17 18:25:35 +01:00
|
|
|
from core.config import config
|
2022-07-17 13:45:45 +02:00
|
|
|
|
|
|
|
__all__ = [
|
2022-08-02 11:34:41 +02:00
|
|
|
'PKG_CORE_BACKEND_REMOTE',
|
|
|
|
'PKG_CORE_BACKEND_LOCAL',
|
2022-07-17 13:45:45 +02:00
|
|
|
]
|
|
|
|
|
2023-03-17 18:25:35 +01:00
|
|
|
#---
|
2023-03-25 19:52:02 +01:00
|
|
|
# Internals
|
2023-03-17 18:25:35 +01:00
|
|
|
#---
|
|
|
|
|
2023-03-25 19:52:02 +01:00
|
|
|
class _VxPKGBackendException(Exception):
|
2023-03-17 18:25:35 +01:00
|
|
|
""" custom backend exception wrapper """
|
|
|
|
|
|
|
|
#---
|
|
|
|
# Public
|
|
|
|
#---
|
|
|
|
|
|
|
|
backend_remote_name = config.get('pkg.backend.name')
|
|
|
|
backend_remote_url = config.get('pkg.backend.url')
|
|
|
|
backend_local_url = os.path.expanduser(config.get('pkg.local_storage'))
|
2022-05-18 16:04:56 +02:00
|
|
|
|
2022-08-02 11:34:41 +02:00
|
|
|
PKG_CORE_BACKEND_REMOTE = None
|
|
|
|
PKG_CORE_BACKEND_LOCAL = None
|
2022-05-18 16:04:56 +02:00
|
|
|
try:
|
|
|
|
mod = __import__(
|
2022-08-02 11:34:41 +02:00
|
|
|
f'core.pkg.backend.{backend_remote_name}',
|
|
|
|
fromlist=['VxBackendRemote']
|
2022-05-18 16:04:56 +02:00
|
|
|
)
|
2022-08-02 11:34:41 +02:00
|
|
|
if not hasattr(mod, 'VxBackendRemote'):
|
2023-03-25 19:52:02 +01:00
|
|
|
raise _VxPKGBackendException(
|
2022-11-03 10:43:24 +01:00
|
|
|
f"backend '{backend_remote_name}' doesn't expose "
|
|
|
|
"VxBackendRemote class"
|
2022-05-18 16:04:56 +02:00
|
|
|
)
|
2022-08-02 11:34:41 +02:00
|
|
|
PKG_CORE_BACKEND_REMOTE = mod.VxBackendRemote(backend_remote_url)
|
|
|
|
PKG_CORE_BACKEND_LOCAL = VxBackendLocal(backend_local_url)
|
2022-11-03 10:43:24 +01:00
|
|
|
except ImportError as err:
|
|
|
|
log.emergency("[backend] unable to load remote backend, abord")
|
|
|
|
log.emergency(err)
|
|
|
|
sys.exit(84)
|