You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
moonstone/ubuntu_smoother/utils/configurator.py

79 lines
2.1 KiB
Python

import logging
from ubuntu_smoother.utils import checks
from ubuntu_smoother.utils.apt import Apt
from ubuntu_smoother.utils.flatpak import Flatpak
from ubuntu_smoother.utils.snap import Snap
logger = logging.getLogger("UbuntuSmoother::Configurator")
2 years ago
class Configurator:
def __init__(self, config: 'Config', fake: bool = False):
self.config = config
self.fake = fake
def apply(self):
self.__enable_snap() if self.config.snap else self.__disable_snap()
self.__enable_flatpak() if self.config.flatpak else self.__disable_flatpak()
self.__enable_apport() if self.config.apport else self.__disable_apport()
2 years ago
def __enable_snap(self):
if self.fake:
logger.info("Fake: Snap enabled")
return
pkgs = []
if not checks.is_snap_installed():
pkgs += ['snapd', 'gnome-software-plugin-snap']
Apt.install(pkgs)
Apt.update()
if not self.config.flatpak:
Snap.install(['snap-store'])
2 years ago
def __disable_snap(self):
if self.fake:
logger.info("Fake: Snap disabled")
return
if checks.is_snap_installed():
Apt.purge(['snapd'])
2 years ago
def __enable_flatpak(self):
if self.fake:
logger.info("Fake: Flatpak enabled")
return
if not checks.is_flatpak_installed():
Apt.install(['flatpak'])
Flatpak.add_repo("https://flathub.org/repo/flathub.flatpakrepo")
Apt.update()
def __disable_flatpak(self):
if self.fake:
logger.info("Fake: Flatpak disabled")
return
if checks.is_flatpak_installed():
Apt.purge(['flatpak'])
def __enable_apport(self):
if self.fake:
logger.info("Fake: Apport enabled")
return
if not checks.is_apport_installed():
Apt.install(['apport'])
Apt.update()
def __disable_apport(self):
if self.fake:
logger.info("Fake: Apport disabled")
return
if checks.is_apport_installed():
Apt.purge(['apport'])