add flatpak, snap, apt backend

also connect some widgets
main
mirkobrombin 2 years ago
parent efa4e290ce
commit b4efbd01ff

@ -38,7 +38,7 @@
<property name="valign">fill</property>
<property name="hexpand">true</property>
<child>
<object class="GtkButton">
<object class="GtkButton" id="btn_start">
<property name="label">Let's Start</property>
<property name="halign">center</property>
<style>
@ -65,7 +65,7 @@
<property name="title">Snap</property>
<property name="subtitle">Will replace GNOME Software with Snap store if the only package manager.</property>
<child>
<object class="GtkSwitch">
<object class="GtkSwitch" id="switch_snap">
<property name="valign">center</property>
</object>
</child>
@ -76,7 +76,7 @@
<property name="title">Flatpak</property>
<property name="subtitle">Will also configure the Flathub repository.</property>
<child>
<object class="GtkSwitch">
<object class="GtkSwitch" id="switch_flatpak">
<property name="valign">center</property>
</object>
</child>
@ -92,7 +92,7 @@
<property name="title">Apport</property>
<property name="subtitle">Do you want to keep the Bug Reporter utility?</property>
<child>
<object class="GtkSwitch">
<object class="GtkSwitch" id="switch_apport">
<property name="valign">center</property>
</object>
</child>
@ -103,7 +103,7 @@
</object>
</child>
<child>
<object class="GtkButton">
<object class="GtkButton" id="btn_save">
<property name="label">Save Changes</property>
<property name="halign">center</property>
<style>

@ -25,6 +25,9 @@ configure_file(
install_dir: get_option('bindir')
)
subdir('utils')
subdir('models')
ubuntu_smoother_sources = [
'__init__.py',
'main.py',

@ -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
)

@ -16,10 +16,35 @@
from gi.repository import Gtk, Gio, Adw
from ubuntu_smoother.models.preset import Preset
from ubuntu_smoother.models.config import Config
@Gtk.Template(resource_path='/pm/mirko/UbuntuSmoother/gtk/window.ui')
class UbuntuSmootherWindow(Adw.ApplicationWindow):
__gtype_name__ = 'UbuntuSmootherWindow'
carousel = Gtk.Template.Child()
btn_start = Gtk.Template.Child()
btn_save = Gtk.Template.Child()
switch_snap = Gtk.Template.Child()
switch_flatpak = Gtk.Template.Child()
switch_apport = Gtk.Template.Child()
def __init__(self, **kwargs):
super().__init__(**kwargs)
self.__buiild_ui()
self.__connect_signals()
def __buiild_ui(self):
self.switch_snap.set_active(Preset.snap)
self.switch_flatpak.set_active(Preset.flatpak)
self.switch_apport.set_active(Preset.apport)
def __connect_signals(self):
self.btn_start.connect('clicked', self.__on_btn_start_clicked)
def __on_btn_start_clicked(self, widget):
index = int(self.carousel.get_position())
next_page = self.carousel.get_nth_page(index + 1)
self.carousel.scroll_to(next_page, True)

Loading…
Cancel
Save