parent
efa4e290ce
commit
b4efbd01ff
@ -0,0 +1,7 @@
|
||||
class Config:
|
||||
|
||||
def __init__(self, snap: bool, flatpak: bool, apport: bool):
|
||||
self.snap = snap
|
||||
self.flatpak = flatpak
|
||||
self.apport = apport
|
||||
|
@ -0,0 +1,10 @@
|
||||
pkgdatadir = join_paths(get_option('prefix'), get_option('datadir'), meson.project_name())
|
||||
modelsdir = join_paths(pkgdatadir, 'ubuntu_smoother/models')
|
||||
|
||||
sources = [
|
||||
'__init__.py',
|
||||
'config.py',
|
||||
'preset.py',
|
||||
]
|
||||
|
||||
install_data(sources, install_dir: modelsdir)
|
@ -0,0 +1,6 @@
|
||||
class Preset:
|
||||
|
||||
snap: bool = True
|
||||
flatpak: bool = True
|
||||
apport: bool = True
|
||||
|
@ -0,0 +1,44 @@
|
||||
import subprocess
|
||||
|
||||
|
||||
class Apt:
|
||||
|
||||
@staticmethod
|
||||
def install(self, packages: list):
|
||||
subprocess.run(
|
||||
['sudo', 'apt', 'install'] + packages,
|
||||
env={'DEBIAN_FRONTEND': 'noninteractive'},
|
||||
check=True
|
||||
)
|
||||
|
||||
@staticmethod
|
||||
def remove(self, packages: list):
|
||||
subprocess.run(
|
||||
['sudo', 'apt', 'remove'] + packages,
|
||||
env={'DEBIAN_FRONTEND': 'noninteractive'},
|
||||
check=True
|
||||
)
|
||||
|
||||
@staticmethod
|
||||
def purge(self, packages: list):
|
||||
subprocess.run(
|
||||
['sudo', 'apt', 'purge'] + packages,
|
||||
env={'DEBIAN_FRONTEND': 'noninteractive'},
|
||||
check=True
|
||||
)
|
||||
|
||||
@staticmethod
|
||||
def update(self):
|
||||
subprocess.run(
|
||||
['sudo', 'apt', 'update'],
|
||||
env={'DEBIAN_FRONTEND': 'noninteractive'},
|
||||
check=True
|
||||
)
|
||||
|
||||
@staticmethod
|
||||
def upgrade(self):
|
||||
subprocess.run(
|
||||
['sudo', 'apt', 'upgrade'],
|
||||
env={'DEBIAN_FRONTEND': 'noninteractive'},
|
||||
check=True
|
||||
)
|
@ -0,0 +1,10 @@
|
||||
import shutil
|
||||
|
||||
def is_snap_installed():
|
||||
return shutil.which('snap') is not None
|
||||
|
||||
def is_flatpak_installed():
|
||||
return shutil.which('flatpak') is not None
|
||||
|
||||
def is_apport_installed():
|
||||
return shutil.which('apport') is not None
|
@ -0,0 +1,39 @@
|
||||
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
|
||||
|
||||
|
||||
class Configurator:
|
||||
|
||||
def __init__(self, config: 'Config'):
|
||||
self.config = config
|
||||
|
||||
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()
|
||||
|
||||
def __enable_snap(self):
|
||||
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'])
|
||||
|
||||
def __disable_snap(self):
|
||||
if checks.is_snap_installed():
|
||||
Apt.purge(['snapd'])
|
||||
|
||||
def __enable_flatpak(self):
|
||||
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 checks.is_flatpak_installed():
|
||||
Apt.purge(['flatpak'])
|
@ -0,0 +1,25 @@
|
||||
import subprocess
|
||||
|
||||
|
||||
class Flatpak:
|
||||
|
||||
@staticmethod
|
||||
def install(self, packages: list):
|
||||
subprocess.run(
|
||||
['flatpak', 'install', '--user'] + packages,
|
||||
check=True
|
||||
)
|
||||
|
||||
@staticmethod
|
||||
def remove(self, packages: list):
|
||||
subprocess.run(
|
||||
['flatpak', 'remove', '--user'] + packages,
|
||||
check=True
|
||||
)
|
||||
|
||||
@staticmethod
|
||||
def add_repo(self, repo: str):
|
||||
subprocess.run(
|
||||
['flatpak', 'remote-add', '--user', '--if-not-exists', repo],
|
||||
check=True
|
||||
)
|
@ -0,0 +1,13 @@
|
||||
pkgdatadir = join_paths(get_option('prefix'), get_option('datadir'), meson.project_name())
|
||||
utilsdir = join_paths(pkgdatadir, 'ubuntu_smoother/utils')
|
||||
|
||||
sources = [
|
||||
'__init__.py',
|
||||
'checks.py',
|
||||
'apt.py',
|
||||
'flatpak.py',
|
||||
'snap.py',
|
||||
'configurator.py',
|
||||
]
|
||||
|
||||
install_data(sources, install_dir: utilsdir)
|
@ -0,0 +1,18 @@
|
||||
import subprocess
|
||||
|
||||
|
||||
class Snap:
|
||||
|
||||
@staticmethod
|
||||
def install(self, packages: list):
|
||||
subprocess.run(
|
||||
['snap', 'install'] + packages,
|
||||
check=True
|
||||
)
|
||||
|
||||
@staticmethod
|
||||
def remove(self, packages: list):
|
||||
subprocess.run(
|
||||
['snap', 'remove'] + packages,
|
||||
check=True
|
||||
)
|
Loading…
Reference in New Issue