fix bool identification and add some logs

main
mirkobrombin 2 years ago
parent b793834590
commit b2d5152f5e

@ -1,24 +0,0 @@
dh_update_autotools_config
dh_auto_configure
dh_auto_build
dh_auto_test
dh_prep
dh_auto_install
dh_installdocs
dh_installchangelogs
dh_installinit
dh_installgsettings
dh_icons
dh_perl
dh_link
dh_strip_nondeterminism
dh_compress
dh_fixperms
dh_missing
dh_strip
dh_makeshlibs
dh_shlibdeps
dh_installdeb
dh_gencontrol
dh_md5sums
dh_builddeb

@ -1,3 +1,9 @@
import logging
logger = logging.getLogger("FirstSetup::Config")
class Config: class Config:
def __init__(self, snap: bool, flatpak: bool, apport: bool, distrobox: bool): def __init__(self, snap: bool, flatpak: bool, apport: bool, distrobox: bool):
@ -10,9 +16,26 @@ class Config:
return "snap::{0}|flatpak::{1}|apport::{2}|distrobox::{3}".format( return "snap::{0}|flatpak::{1}|apport::{2}|distrobox::{3}".format(
self.snap, self.flatpak, self.apport, self.distrobox self.snap, self.flatpak, self.apport, self.distrobox
) )
def set_val(self, key: str, val: bool):
if key == "snap":
self.snap = val
elif key == "flatpak":
self.flatpak = val
elif key == "apport":
self.apport = val
elif key == "distrobox":
self.distrobox = val
else:
return
logger.info(f"Setting {key} to {val}")
@classmethod @classmethod
def from_str(cls, config_str: str) -> 'Config': def from_str(cls, config_str: str) -> 'Config':
def get_bool(value: str):
return "True" in value
items = config_str.split('|') items = config_str.split('|')
snap = items[0].split('::')[1] snap = items[0].split('::')[1]
@ -21,8 +44,8 @@ class Config:
distrobox = items[3].split('::')[1] distrobox = items[3].split('::')[1]
return cls( return cls(
snap=bool(snap), snap=get_bool(snap),
flatpak=bool(flatpak), flatpak=get_bool(flatpak),
apport=bool(apport), apport=get_bool(apport),
distrobox=bool(distrobox) distrobox=get_bool(distrobox)
) )

@ -19,6 +19,7 @@ class Configurator:
self.fake = fake self.fake = fake
def apply(self): def apply(self):
logging.info(f"Applying config: {self.config.get_str()}")
self.__enable_snap() if self.config.snap else self.__disable_snap() self.__enable_snap() if self.config.snap else self.__disable_snap()
self.__enable_flatpak() if self.config.flatpak else self.__disable_flatpak() self.__enable_flatpak() if self.config.flatpak else self.__disable_flatpak()
self.__enable_apport() if self.config.apport else self.__disable_apport() self.__enable_apport() if self.config.apport else self.__disable_apport()

@ -22,6 +22,11 @@ import signal
import locale import locale
import gettext import gettext
import argparse import argparse
import logging
logging.basicConfig(level=logging.INFO)
VERSION = '@VERSION@' VERSION = '@VERSION@'
pkgdatadir = '@pkgdatadir@' pkgdatadir = '@pkgdatadir@'
@ -33,13 +38,16 @@ locale.bindtextdomain('vanilla_first_setup', localedir)
locale.textdomain('vanilla_first_setup') locale.textdomain('vanilla_first_setup')
gettext.install('vanilla_first_setup', localedir) gettext.install('vanilla_first_setup', localedir)
if __name__ == '__main__': if __name__ == '__main__':
from vanilla_first_setup.utils.configurator import Configurator from vanilla_first_setup.utils.configurator import Configurator
from vanilla_first_setup.models.config import Config from vanilla_first_setup.models.config import Config
parser = argparse.ArgumentParser() parser = argparse.ArgumentParser()
parser.add_argument('config', help='The configuration string (e.g. snap::True|flatpak::False|apport::True)') parser.add_argument(
'config', help='The configuration string (e.g. snap::True|flatpak::False|apport::True)')
args = parser.parse_args() args = parser.parse_args()
config = Config.from_str(args.config) config = Config.from_str(args.config)
print(config.get_str())
Configurator(config).apply() Configurator(config).apply()

@ -91,16 +91,16 @@ class FirstSetupWindow(Adw.ApplicationWindow):
RunAsync(Processor(self.__config).run, on_done) RunAsync(Processor(self.__config).run, on_done)
def __on_switch_snap_state_set(self, widget, state): def __on_switch_snap_state_set(self, widget, state):
self.__config.snap = state self.__config.set_val('snap', state)
def __on_switch_flatpak_state_set(self, widget, state): def __on_switch_flatpak_state_set(self, widget, state):
self.__config.flatpak = state self.__config.set_val('flatpak', state)
def __on_switch_apport_state_set(self, widget, state): def __on_switch_apport_state_set(self, widget, state):
self.__config.apport = state self.__config.set_val('apport', state)
def __on_switch_distrobox_state_set(self, widget, state): def __on_switch_distrobox_state_set(self, widget, state):
self.__config.distrobox = state self.__config.set_val('distrobox', state)
def on_btn_close_clicked(self, widget): def on_btn_close_clicked(self, widget):
self.get_application().quit() self.get_application().quit()

Loading…
Cancel
Save