mirror of
ssh://git.janware.com/janware/proj/jw-pkg
synced 2026-04-25 09:35:54 +02:00
jw.pkg.cmds.distro: Add directory
Add the subdirectory structure for the distro subcommand. Signed-off-by: Jan Lindemann <jan@janware.com>
This commit is contained in:
parent
53601c8abd
commit
ad45ee8510
4 changed files with 98 additions and 0 deletions
44
src/python/jw/pkg/cmds/distro/Cmd.py
Normal file
44
src/python/jw/pkg/cmds/distro/Cmd.py
Normal file
|
|
@ -0,0 +1,44 @@
|
|||
# -*- 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
|
||||
Loading…
Add table
Add a link
Reference in a new issue