installation fixed
This commit is contained in:
parent
63f2074105
commit
140a09baa5
6 changed files with 63 additions and 39 deletions
|
@ -1,6 +1,6 @@
|
|||
from typing import Dict, Type, List
|
||||
|
||||
from .base import PackageConfig, PackageManager
|
||||
from .base import PackageConfig, PackageManager, PACKAGES
|
||||
|
||||
from .pacman import PacmanConf, Pacman
|
||||
from .aur import ParuConf, Paru
|
||||
|
@ -11,7 +11,7 @@ except:
|
|||
pass # TODO: write a log for flatpak
|
||||
|
||||
|
||||
package_managers = {
|
||||
_package_managers = {
|
||||
pckmng.__class__.__name__.lower() : pckmng for pckmng in [
|
||||
Pacman(),
|
||||
Paru(),
|
||||
|
@ -20,14 +20,17 @@ package_managers = {
|
|||
}
|
||||
|
||||
|
||||
def pckmng_gen(*pckmng_names: str) -> Dict[str, Type[PackageConfig]]:
|
||||
def package_manager(name: str) -> PackageManager:
|
||||
return _package_managers[name]
|
||||
|
||||
|
||||
def pckmng_gen(*packages: str) -> PACKAGES:
|
||||
return {
|
||||
pm : package_managers[pm].list() for pm in pckmng_names
|
||||
name : package_manager(name).list() for name in packages
|
||||
}
|
||||
|
||||
|
||||
def pckmng_ins(package_list: List[PackageConfig]):
|
||||
for package in package_list:
|
||||
pass
|
||||
|
||||
|
||||
def pckmng_ins(packages: PACKAGES):
|
||||
for name, config in packages.items():
|
||||
pc: PackageManager = package_manager(name)
|
||||
pc.install(config)
|
||||
|
|
|
@ -4,16 +4,22 @@ from .base import PackageConfig, PackageManager
|
|||
|
||||
|
||||
class ParuConf(PackageConfig):
|
||||
pm: str = 'paru'
|
||||
pass
|
||||
|
||||
|
||||
# command
|
||||
install_pck = paru["-S", "--noconfirm"]
|
||||
list_pck = paru["-Qmq"]
|
||||
|
||||
|
||||
class Paru(PackageManager):
|
||||
pckconf: ParuConf = ParuConf
|
||||
|
||||
def install(self):
|
||||
cmd = sudo[paru["-S", "--noconfirm", self.pckconf.packages]]
|
||||
cmd()
|
||||
def install(self, pckconf: ParuConf):
|
||||
cmd = install_pck[pckconf.packages]
|
||||
return cmd()
|
||||
|
||||
def list(self):
|
||||
cmd = paru["-Qmq"]
|
||||
return ParuConf(packages=cmd().splitlines())
|
||||
@classmethod
|
||||
def list(cls):
|
||||
cmd = list_pck
|
||||
return cls.pckconf(packages=cmd().splitlines())
|
||||
|
|
|
@ -1,23 +1,26 @@
|
|||
from typing import Type, List
|
||||
from typing import Type, List, NewType, Dict
|
||||
from abc import ABC, abstractmethod
|
||||
from pydantic import BaseModel
|
||||
|
||||
|
||||
class PackageConfig(BaseModel):
|
||||
packages: List[str]
|
||||
packages: List[str] = []
|
||||
|
||||
|
||||
class PackageManager(ABC):
|
||||
pckconf: Type[PackageConfig] = None
|
||||
|
||||
# def __init__(self, pckconf: PackageConfig):
|
||||
# if isinstance(pckconf, self.pckconf):
|
||||
# self.pckconf = pckconf
|
||||
def __init__(self):
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def install(self):
|
||||
def install(self, packages: PackageConfig):
|
||||
raise NotImplemented()
|
||||
|
||||
@property
|
||||
def list(self):
|
||||
@classmethod
|
||||
@abstractmethod
|
||||
def list(cls) -> PackageConfig:
|
||||
raise NotImplemented()
|
||||
|
||||
|
||||
PACKAGES = NewType("PACKAGES", Dict[str, PackageConfig])
|
||||
|
|
|
@ -7,14 +7,20 @@ class FlatpakConf(PackageConfig):
|
|||
pass
|
||||
|
||||
|
||||
# commands
|
||||
install_pck = flatpak["install", "-y"]
|
||||
list_pck = flatpak["list", "--app", "--columns=application"]
|
||||
|
||||
|
||||
class Flatpak(PackageManager):
|
||||
pckconf: FlatpakConf = FlatpakConf
|
||||
|
||||
def install(self):
|
||||
cmd = flatpak["install", "-y", self.pckconf.packages]
|
||||
cmd = install_pck[self.pckconf.packages]
|
||||
return cmd()
|
||||
|
||||
def list(self):
|
||||
cmd = flatpak["list", "--app", "--columns=application"]
|
||||
return FlatpakConf(packages=cmd().splitlines())
|
||||
@classmethod
|
||||
def list(cls):
|
||||
cmd = list_pck
|
||||
return cls.pckconf(packages=cmd().splitlines())
|
||||
|
||||
|
|
|
@ -7,13 +7,19 @@ class PacmanConf(PackageConfig):
|
|||
pass
|
||||
|
||||
|
||||
# commands
|
||||
install_pck = sudo[pacman["-S", "--noconfirm"]]
|
||||
list_pck = pacman["-Qeq"]
|
||||
|
||||
|
||||
class Pacman(PackageManager):
|
||||
pckconf: PacmanConf = PacmanConf
|
||||
|
||||
def install(self):
|
||||
cmd = sudo[pacman["-S", "--noconfirm", self.pckconf.packages]]
|
||||
cmd()
|
||||
def install(self, pckconf: PacmanConf):
|
||||
cmd = install_pck[pckconf.packages]
|
||||
return cmd()
|
||||
|
||||
def list(self):
|
||||
cmd = pacman["-Qeq"]
|
||||
return PacmanConf(packages=cmd().splitlines())
|
||||
@classmethod
|
||||
def list(cls) -> PacmanConf:
|
||||
cmd = list_pck
|
||||
return cls.pckconf(packages=cmd().splitlines())
|
||||
|
|
|
@ -1,19 +1,19 @@
|
|||
from typing import Dict
|
||||
from typing import Dict, Type
|
||||
|
||||
from pydantic import BaseModel
|
||||
|
||||
from pckmng import PackageConfig, pckmng_gen
|
||||
from pckmng import PackageConfig, pckmng_gen, pckmng_ins, PACKAGES
|
||||
|
||||
|
||||
class Config(BaseModel):
|
||||
packages: Dict[str, PackageConfig]
|
||||
packages: PACKAGES
|
||||
|
||||
|
||||
def install_config(conf: Config):
|
||||
pass
|
||||
pckmng_ins(conf.packages)
|
||||
|
||||
|
||||
def generate_config(*pm_names):
|
||||
return Config(
|
||||
packages=pckmng_gen(*pm_names)
|
||||
).model_dump()
|
||||
)
|
||||
|
|
Loading…
Add table
Reference in a new issue