pm deleted, profiler updated. now it is able to gather all packages

This commit is contained in:
misano 2024-08-23 14:21:54 +03:30
parent 879d862e28
commit 63f2074105
6 changed files with 41 additions and 15 deletions

View file

@ -1,3 +1,5 @@
from typing import Dict, Type, List
from .base import PackageConfig, PackageManager
from .pacman import PacmanConf, Pacman
@ -9,4 +11,23 @@ except:
pass # TODO: write a log for flatpak
package_managers = {
pckmng.__class__.__name__.lower() : pckmng for pckmng in [
Pacman(),
Paru(),
Flatpak()
]
}
def pckmng_gen(*pckmng_names: str) -> Dict[str, Type[PackageConfig]]:
return {
pm : package_managers[pm].list() for pm in pckmng_names
}
def pckmng_ins(package_list: List[PackageConfig]):
for package in package_list:
pass

View file

@ -11,9 +11,9 @@ class Paru(PackageManager):
pckconf: ParuConf = ParuConf
def install(self):
cmd = sudo[paru['-Syu', self.pckconf.packages]]
cmd = sudo[paru["-S", "--noconfirm", self.pckconf.packages]]
cmd()
def list(self):
cmd = paru["-Qeq"]
cmd = paru["-Qmq"]
return ParuConf(packages=cmd().splitlines())

View file

@ -4,16 +4,15 @@ from pydantic import BaseModel
class PackageConfig(BaseModel):
pm: str # package manager name
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, pckconf: PackageConfig):
# if isinstance(pckconf, self.pckconf):
# self.pckconf = pckconf
@abstractmethod
def install(self):

View file

@ -4,7 +4,7 @@ from .base import PackageConfig, PackageManager
class FlatpakConf(PackageConfig):
pm: str = 'flatpak'
pass
class Flatpak(PackageManager):

View file

@ -4,14 +4,14 @@ from .base import PackageConfig, PackageManager
class PacmanConf(PackageConfig):
pm: str = 'pacman'
pass
class Pacman(PackageManager):
pckconf: PacmanConf = PacmanConf
def install(self):
cmd = sudo[pacman['-Syu', self.pckconf.packages]]
cmd = sudo[pacman["-S", "--noconfirm", self.pckconf.packages]]
cmd()
def list(self):

View file

@ -1,13 +1,19 @@
from typing import List
from typing import Dict
import toml
from pydantic import BaseModel
from .pckmng import PackageConfig
from pckmng import PackageConfig, pckmng_gen
class Config(BaseModel):
packages: List[PackageConfig]
packages: Dict[str, PackageConfig]
class Profiler:
def install_config(conf: Config):
pass
def generate_config(*pm_names):
return Config(
packages=pckmng_gen(*pm_names)
).model_dump()