mirror of
ssh://git.janware.com/janware/proj/jw-pkg
synced 2026-04-25 09:35:54 +02:00
44 lines
1.3 KiB
Python
44 lines
1.3 KiB
Python
|
|
# -*- coding: utf-8 -*-
|
||
|
|
|
||
|
|
import os, importlib
|
||
|
|
|
||
|
|
from ..Cmd import Cmd as Base
|
||
|
|
from ..CmdDistro import CmdDistro
|
||
|
|
|
||
|
|
class Cmd(Base): # export
|
||
|
|
|
||
|
|
def __init__(self, parent: CmdDistro, name: str, help: str) -> None:
|
||
|
|
super().__init__(parent, name, help)
|
||
|
|
self.__backend = None
|
||
|
|
|
||
|
|
@property
|
||
|
|
def distro_id(self) -> str:
|
||
|
|
return self.parent.distro_id
|
||
|
|
|
||
|
|
@property
|
||
|
|
def interactive(self) -> bool:
|
||
|
|
return self.parent.interactive
|
||
|
|
|
||
|
|
@property
|
||
|
|
def _backend(self):
|
||
|
|
if self.__backend is None:
|
||
|
|
class_name = self.__class__.__name__[3:] # Get rid of "Cmd"
|
||
|
|
backend_id = self.parent.distro_id.lower().replace('-', '_')
|
||
|
|
match backend_id:
|
||
|
|
case 'ubuntu' | 'raspbian':
|
||
|
|
backend_id = 'debian'
|
||
|
|
case 'centos':
|
||
|
|
backend_id = 'redhat'
|
||
|
|
case 'opensuse_tumbleweed':
|
||
|
|
backend_id = 'suse'
|
||
|
|
module_name = (
|
||
|
|
os.path.splitext(__name__)[0]
|
||
|
|
+ '.backend.'
|
||
|
|
+ backend_id
|
||
|
|
+ '.'
|
||
|
|
+ class_name
|
||
|
|
)
|
||
|
|
module = importlib.import_module(module_name)
|
||
|
|
cls = getattr(module, class_name)
|
||
|
|
self.__backend = cls(self)
|
||
|
|
return self.__backend
|