PackageManager has both install and uninstall.

This commit is contained in:
Fabio Manganiello 2023-08-20 13:33:49 +02:00
parent 5efcae64c1
commit a6f8021150
Signed by: blacklight
GPG key ID: D90FBA7F76362774
2 changed files with 13 additions and 7 deletions

View file

@ -6,6 +6,7 @@ WORKDIR /var/lib/platypush
ARG DOCKER_CTX=1
ENV DOCKER_CTX=1
RUN apk update
RUN /install/platypush/install/scripts/alpine/install.sh
RUN cd /install && pip install -U --no-input --no-cache-dir .
RUN rm -rf /install

View file

@ -55,8 +55,10 @@ class PackageManager:
executable: str
""" The executable name. """
command: Iterable[str] = field(default_factory=tuple)
""" The command to execute, as a sequence of strings. """
install: Iterable[str] = field(default_factory=tuple)
""" The install command, as a sequence of strings. """
uninstall: Iterable[str] = field(default_factory=tuple)
""" The uninstall command, as a sequence of strings. """
class PackageManagers(Enum):
@ -66,17 +68,20 @@ class PackageManagers(Enum):
APK = PackageManager(
executable='apk',
command=('apk', 'add', '--update', '--no-interactive', '--no-cache'),
install=('apk', 'add', '--update', '--no-interactive', '--no-cache'),
uninstall=('apk', 'del', '--no-interactive'),
)
APT = PackageManager(
executable='apt',
command=('apt', 'install', '-y'),
install=('apt', 'install', '-y'),
uninstall=('apt', 'remove', '-y'),
)
PACMAN = PackageManager(
executable='pacman',
command=('pacman', '-S', '--noconfirm'),
install=('pacman', '-S', '--noconfirm'),
uninstall=('pacman', '-R', '--noconfirm'),
)
@classmethod
@ -90,7 +95,7 @@ class PackageManagers(Enum):
if not pkg_manager:
raise ValueError(f'Unknown package manager: {name}')
return pkg_manager.value.command
return pkg_manager.value.install
@classmethod
def scan(cls) -> Optional["PackageManagers"]:
@ -221,7 +226,7 @@ class Dependencies:
yield ' '.join(
[
*(['sudo'] if wants_sudo else []),
*pkg_manager.value.command,
*pkg_manager.value.install,
*sorted(self.packages), # type: ignore
]
)