make the magic happen

feat make the backend works
main
mirkobrombin 2 years ago
parent d5f9688c9f
commit af5f806d4d

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

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

@ -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 <http://www.gnu.org/licenses/>.
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()

@ -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'},

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

@ -9,6 +9,7 @@ sources = [
'snap.py',
'configurator.py',
'run_async.py',
'processor.py',
]
install_data(sources, install_dir: utilsdir)

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

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

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

Loading…
Cancel
Save