diff --git a/ubuntu_smoother/meson.build b/ubuntu_smoother/meson.build index 517e770..581569d 100644 --- a/ubuntu_smoother/meson.build +++ b/ubuntu_smoother/meson.build @@ -25,6 +25,14 @@ configure_file( install_dir: get_option('bindir') ) +configure_file( + input: 'ubuntu-smoother-processor.in', + output: 'ubuntu-smoother-processor', + configuration: conf, + install: true, + install_dir: get_option('bindir') +) + subdir('utils') subdir('models') diff --git a/ubuntu_smoother/models/config.py b/ubuntu_smoother/models/config.py index cae9f63..40ae2f0 100644 --- a/ubuntu_smoother/models/config.py +++ b/ubuntu_smoother/models/config.py @@ -4,3 +4,22 @@ class Config: self.snap = snap self.flatpak = flatpak self.apport = apport + + def get_str(self) -> str: + return "snap::{0}|flatpak::{1}|apport::{2}".format( + self.snap, self.flatpak, self.apport + ) + + @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] + + return cls( + snap=bool(snap), + flatpak=bool(flatpak), + apport=bool(apport) + ) diff --git a/ubuntu_smoother/ubuntu-smoother-processor.in b/ubuntu_smoother/ubuntu-smoother-processor.in new file mode 100644 index 0000000..da6e649 --- /dev/null +++ b/ubuntu_smoother/ubuntu-smoother-processor.in @@ -0,0 +1,45 @@ +#!@PYTHON@ + +# ubuntu-smoother-processor.in +# +# Copyright 2022 mirkobrombin +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundationat version 3 of the License. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +import os +import sys +import signal +import locale +import gettext +import argparse + +VERSION = '@VERSION@' +pkgdatadir = '@pkgdatadir@' +localedir = '@localedir@' + +sys.path.insert(1, pkgdatadir) +signal.signal(signal.SIGINT, signal.SIG_DFL) +locale.bindtextdomain('ubuntu_smoother', localedir) +locale.textdomain('ubuntu_smoother') +gettext.install('ubuntu_smoother', localedir) + +if __name__ == '__main__': + from ubuntu_smoother.utils.configurator import Configurator + from ubuntu_smoother.models.config import Config + + parser = argparse.ArgumentParser() + parser.add_argument('config', help='The configuration string (e.g. snap::True|flatpak::False|apport::True)') + args = parser.parse_args() + + config = Config.from_str(args.config) + Configurator(config).apply() diff --git a/ubuntu_smoother/utils/apt.py b/ubuntu_smoother/utils/apt.py index e64d303..0d9e19c 100644 --- a/ubuntu_smoother/utils/apt.py +++ b/ubuntu_smoother/utils/apt.py @@ -4,7 +4,7 @@ import subprocess class Apt: @staticmethod - def install(self, packages: list): + def install(packages: list): subprocess.run( ['sudo', 'apt', 'install'] + packages, env={'DEBIAN_FRONTEND': 'noninteractive'}, @@ -12,7 +12,7 @@ class Apt: ) @staticmethod - def remove(self, packages: list): + def remove(packages: list): subprocess.run( ['sudo', 'apt', 'remove'] + packages, env={'DEBIAN_FRONTEND': 'noninteractive'}, @@ -20,7 +20,7 @@ class Apt: ) @staticmethod - def purge(self, packages: list): + def purge(packages: list): subprocess.run( ['sudo', 'apt', 'purge'] + packages, env={'DEBIAN_FRONTEND': 'noninteractive'}, @@ -28,7 +28,7 @@ class Apt: ) @staticmethod - def update(self): + def update(): subprocess.run( ['sudo', 'apt', 'update'], env={'DEBIAN_FRONTEND': 'noninteractive'}, @@ -36,7 +36,7 @@ class Apt: ) @staticmethod - def upgrade(self): + def upgrade(): subprocess.run( ['sudo', 'apt', 'upgrade'], env={'DEBIAN_FRONTEND': 'noninteractive'}, diff --git a/ubuntu_smoother/utils/flatpak.py b/ubuntu_smoother/utils/flatpak.py index ba0368c..7c45833 100644 --- a/ubuntu_smoother/utils/flatpak.py +++ b/ubuntu_smoother/utils/flatpak.py @@ -4,21 +4,21 @@ import subprocess class Flatpak: @staticmethod - def install(self, packages: list): + def install(packages: list): subprocess.run( ['flatpak', 'install', '--user'] + packages, check=True ) @staticmethod - def remove(self, packages: list): + def remove(packages: list): subprocess.run( ['flatpak', 'remove', '--user'] + packages, check=True ) @staticmethod - def add_repo(self, repo: str): + def add_repo(repo: str): subprocess.run( ['flatpak', 'remote-add', '--user', '--if-not-exists', repo], check=True diff --git a/ubuntu_smoother/utils/meson.build b/ubuntu_smoother/utils/meson.build index f929c30..075a55c 100644 --- a/ubuntu_smoother/utils/meson.build +++ b/ubuntu_smoother/utils/meson.build @@ -9,6 +9,7 @@ sources = [ 'snap.py', 'configurator.py', 'run_async.py', + 'processor.py', ] install_data(sources, install_dir: utilsdir) \ No newline at end of file diff --git a/ubuntu_smoother/utils/processor.py b/ubuntu_smoother/utils/processor.py new file mode 100644 index 0000000..88a692b --- /dev/null +++ b/ubuntu_smoother/utils/processor.py @@ -0,0 +1,18 @@ +import subprocess + + +class Processor: + + def __init__(self, config: 'Config'): + self.__config = config + + def run(self): + proc = subprocess.run( + ["pkexec", "ubuntu-smoother-processor", self.__config.get_str()], + check=True + ) + + if proc.returncode != 0: + return False, "Error executing the Ubuntu Smoother Processor" + + return True \ No newline at end of file diff --git a/ubuntu_smoother/utils/snap.py b/ubuntu_smoother/utils/snap.py index ccd16ba..ae76ae6 100644 --- a/ubuntu_smoother/utils/snap.py +++ b/ubuntu_smoother/utils/snap.py @@ -4,14 +4,14 @@ import subprocess class Snap: @staticmethod - def install(self, packages: list): + def install(packages: list): subprocess.run( ['snap', 'install'] + packages, check=True ) @staticmethod - def remove(self, packages: list): + def remove(packages: list): subprocess.run( ['snap', 'remove'] + packages, check=True diff --git a/ubuntu_smoother/window.py b/ubuntu_smoother/window.py index 38f5502..ab46155 100644 --- a/ubuntu_smoother/window.py +++ b/ubuntu_smoother/window.py @@ -18,7 +18,7 @@ from gi.repository import Gtk, Gio, Adw from ubuntu_smoother.models.preset import Preset from ubuntu_smoother.models.config import Config -from ubuntu_smoother.utils.configurator import Configurator +from ubuntu_smoother.utils.processor import Processor from ubuntu_smoother.utils.run_async import RunAsync @@ -72,14 +72,14 @@ class UbuntuSmootherWindow(Adw.ApplicationWindow): self.__show_page(self.page_configuration) def on_btn_save_clicked(self, widget): - def on_done(*args): + def on_done(result, error=None): self.spinner.stop() self.__show_page(self.page_done) self.__show_page(self.page_progress) self.spinner.start() - RunAsync(Configurator(self.__config, fake=True).apply, on_done) + RunAsync(Processor(self.__config).run, on_done) def __on_switch_snap_state_set(self, widget, state): self.__config.snap = state