From eab9504225e022a283a3cb84597a48ea19af74d2 Mon Sep 17 00:00:00 2001 From: mirkobrombin Date: Mon, 5 Sep 2022 21:31:36 +0200 Subject: [PATCH] add distrobox as an option --- ubuntu_smoother/gtk/window.ui | 15 ++++++++++++++ ubuntu_smoother/models/config.py | 15 ++++++++------ ubuntu_smoother/models/preset.py | 1 + ubuntu_smoother/utils/configurator.py | 28 +++++++++++++-------------- ubuntu_smoother/window.py | 10 +++++++++- 5 files changed, 47 insertions(+), 22 deletions(-) diff --git a/ubuntu_smoother/gtk/window.ui b/ubuntu_smoother/gtk/window.ui index f44f711..1cfa040 100644 --- a/ubuntu_smoother/gtk/window.ui +++ b/ubuntu_smoother/gtk/window.ui @@ -68,6 +68,7 @@ Snap Will replace GNOME Software with Snap store if the only package manager. + switch_snap center @@ -79,6 +80,7 @@ Flatpak Will also configure the Flathub repository. + switch_flatpak center @@ -95,6 +97,7 @@ Apport Do you want to keep the Bug Reporter utility? + switch_apport center @@ -102,6 +105,18 @@ + + + Distrobox + Allows you to create containers with different distributions. + switch_distrobox + + + center + + + + diff --git a/ubuntu_smoother/models/config.py b/ubuntu_smoother/models/config.py index 40ae2f0..22e2277 100644 --- a/ubuntu_smoother/models/config.py +++ b/ubuntu_smoother/models/config.py @@ -1,25 +1,28 @@ class Config: - def __init__(self, snap: bool, flatpak: bool, apport: bool): + def __init__(self, snap: bool, flatpak: bool, apport: bool, distrobox: bool): self.snap = snap self.flatpak = flatpak self.apport = apport + self.distrobox = distrobox def get_str(self) -> str: - return "snap::{0}|flatpak::{1}|apport::{2}".format( - self.snap, self.flatpak, self.apport + return "snap::{0}|flatpak::{1}|apport::{2}|distrobox::{3}".format( + self.snap, self.flatpak, self.apport, self.distrobox ) - + @classmethod def from_str(cls, config_str: str) -> 'Config': items = config_str.split('|') - + snap = items[0].split('::')[1] flatpak = items[1].split('::')[1] apport = items[2].split('::')[1] + distrobox = items[3].split('::')[1] return cls( snap=bool(snap), flatpak=bool(flatpak), - apport=bool(apport) + apport=bool(apport), + distrobox=bool(distrobox) ) diff --git a/ubuntu_smoother/models/preset.py b/ubuntu_smoother/models/preset.py index 9fb1d42..a7923b5 100644 --- a/ubuntu_smoother/models/preset.py +++ b/ubuntu_smoother/models/preset.py @@ -3,3 +3,4 @@ class Preset: snap: bool = True flatpak: bool = True apport: bool = True + distrobox: bool = True diff --git a/ubuntu_smoother/utils/configurator.py b/ubuntu_smoother/utils/configurator.py index 6e025d4..3d4334a 100644 --- a/ubuntu_smoother/utils/configurator.py +++ b/ubuntu_smoother/utils/configurator.py @@ -1,6 +1,7 @@ import os import time import logging +import subprocess from ubuntu_smoother.utils import checks from ubuntu_smoother.utils.apt import Apt @@ -21,6 +22,8 @@ class Configurator: 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() + if self.config.distrobox: + self.__enable_distrobox() def __fake(self, msg: str): time.sleep(1) @@ -74,6 +77,16 @@ class Configurator: if checks.is_apport_installed(): Apt.purge(['apport']) + + def __enable_distrobox(self): + if self.fake: + return self.__fake("Fake: Distrobox enabled") + + Apt.install(['curl', 'podman']) + Apt.update() + + proc = subprocess.run(['curl', '-s', 'https://raw.githubusercontent.com/89luca89/distrobox/main/install'], stdout=subprocess.PIPE) + proc = subprocess.run(['sudo', 'sh'], input=proc.stdout, stdout=subprocess.PIPE) def __disable_on_startup(self): if self.fake: @@ -82,18 +95,3 @@ class Configurator: autostart_file = os.path.expanduser("~/.config/autostart/ubuntu-smoother.desktop") if os.path.exists(autostart_file): os.remove(autostart_file) - - def __enable_on_startup(self): - if self.fake: - return self.__fake("Fake: Enable on startup") - - autostart_file = os.path.expanduser("~/.config/autostart/ubuntu-smoother.desktop") - if not os.path.exists(autostart_file): - with open(autostart_file, "w") as f: - f.write("[Desktop Entry]") - f.write("Type=Application") - f.write("Name=Ubuntu Smoother") - f.write("Exec=ubuntu-smoother") - f.write("Terminal=false") - f.write("X-GNOME-Autostart-enabled=true") - \ No newline at end of file diff --git a/ubuntu_smoother/window.py b/ubuntu_smoother/window.py index ab46155..205da19 100644 --- a/ubuntu_smoother/window.py +++ b/ubuntu_smoother/window.py @@ -33,6 +33,7 @@ class UbuntuSmootherWindow(Adw.ApplicationWindow): switch_snap = Gtk.Template.Child() switch_flatpak = Gtk.Template.Child() switch_apport = Gtk.Template.Child() + switch_distrobox = Gtk.Template.Child() page_welcome = -1 page_configuration = 0 page_progress = 1 @@ -44,7 +45,8 @@ class UbuntuSmootherWindow(Adw.ApplicationWindow): self.__config = Config( snap=Preset.snap, flatpak=Preset.flatpak, - apport=Preset.apport + apport=Preset.apport, + distrobox=Preset.distrobox ) self.__buiild_ui() self.__connect_signals() @@ -53,6 +55,7 @@ class UbuntuSmootherWindow(Adw.ApplicationWindow): self.switch_snap.set_active(Preset.snap) self.switch_flatpak.set_active(Preset.flatpak) self.switch_apport.set_active(Preset.apport) + self.switch_distrobox.set_active(Preset.distrobox) def __connect_signals(self): self.btn_start.connect('clicked', self.__on_btn_start_clicked) @@ -63,6 +66,8 @@ class UbuntuSmootherWindow(Adw.ApplicationWindow): 'state-set', self.__on_switch_flatpak_state_set) self.switch_apport.connect( 'state-set', self.__on_switch_apport_state_set) + self.switch_distrobox.connect( + 'state-set', self.__on_switch_distrobox_state_set) def __show_page(self, page: int): _page = self.carousel.get_nth_page(page + 1) @@ -90,5 +95,8 @@ class UbuntuSmootherWindow(Adw.ApplicationWindow): def __on_switch_apport_state_set(self, widget, state): self.__config.apport = state + def __on_switch_distrobox_state_set(self, widget, state): + self.__config.distrobox = state + def on_btn_close_clicked(self, widget): self.get_application().quit()