58 lines
1.9 KiB
Python
58 lines
1.9 KiB
Python
"""Remote backend constructor
|
|
|
|
This package will exposes the major important object for the package core remote
|
|
part of the vxsdk.
|
|
|
|
=========================== ============================================
|
|
Object name Description
|
|
=========================== ============================================
|
|
PKG_CORE_BACKEND_REMOTE Remote ackend object
|
|
PKG_CORE_BACKEND_LOCAL Local backend object
|
|
VxRemoteBackend Abstract class for backend implementation
|
|
=========================== ======================================
|
|
|
|
This part of the vxsdk can be manually configured using a TOML configuration
|
|
which need to be located at <~/.config/vxsdk/configure.toml>. A special
|
|
section named 'package.remote' can be added to specify backend information:
|
|
|
|
[pkg]
|
|
backend.name = 'gitea'
|
|
backend.url = 'https://personal.gitea.instance.gaming'
|
|
|
|
This is the only configuration that you can set here.
|
|
"""
|
|
import os
|
|
import sys
|
|
|
|
from core.pkg.backend.local import VxBackendLocal
|
|
from core.logger import log
|
|
from core.config import config_get
|
|
|
|
__all__ = [
|
|
'PKG_CORE_BACKEND_REMOTE',
|
|
'PKG_CORE_BACKEND_LOCAL',
|
|
]
|
|
|
|
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'))
|
|
|
|
PKG_CORE_BACKEND_REMOTE = None
|
|
PKG_CORE_BACKEND_LOCAL = None
|
|
try:
|
|
mod = __import__(
|
|
f'core.pkg.backend.{backend_remote_name}',
|
|
fromlist=['VxBackendRemote']
|
|
)
|
|
if not hasattr(mod, 'VxBackendRemote'):
|
|
raise Exception(
|
|
f"backend '{backend_remote_name}' doesn't expose "
|
|
"VxBackendRemote class"
|
|
)
|
|
PKG_CORE_BACKEND_REMOTE = mod.VxBackendRemote(backend_remote_url)
|
|
PKG_CORE_BACKEND_LOCAL = VxBackendLocal(backend_local_url)
|
|
except ImportError as err:
|
|
log.emergency("[backend] unable to load remote backend, abord")
|
|
log.emergency(err)
|
|
sys.exit(84)
|