From c689be9aa2873eeca3fe4eb90d94a3c364595fed Mon Sep 17 00:00:00 2001 From: Mirko Brombin Date: Sun, 9 Oct 2022 10:58:08 +0200 Subject: [PATCH] support pre-run, post-run commands --- recipe.json | 10 +++++++++- vanilla_first_setup/utils/processor.py | 7 +++++-- vanilla_first_setup/window.py | 7 ++++++- 3 files changed, 20 insertions(+), 4 deletions(-) diff --git a/recipe.json b/recipe.json index fe5009e..1814da5 100644 --- a/recipe.json +++ b/recipe.json @@ -2,6 +2,14 @@ "log_file": "/etc/vanilla/first-setup.log", "distro_name": "Vanilla OS", "distro_logo": "io.github.vanilla-os.FirstSetup", + "pre_run": [ + "sudo apt update", + "sudo apt install -f" + ], + "post_run": [ + "sudo apt update", + "sudo apt install -f" + ], "steps": { "welcome": { "template": "welcome" @@ -115,7 +123,7 @@ "if": "immutability", "type": "command", "commands": [ - "sudo apt install -y almost", + "sudo apt install -y almost almost-extras", "sudo almost enter rw" ] } diff --git a/vanilla_first_setup/utils/processor.py b/vanilla_first_setup/utils/processor.py index 5ced266..6749bad 100644 --- a/vanilla_first_setup/utils/processor.py +++ b/vanilla_first_setup/utils/processor.py @@ -26,7 +26,9 @@ logger = logging.getLogger("FirstSetup::Processor") class Processor: @staticmethod - def run(log_path, commands): + def run(log_path, pre_run, post_run, commands): + command = pre_run + commands + post_run + logger.info("processing the following commands: \n%s" % '\n'.join(commands)) @@ -65,7 +67,8 @@ class Processor: log.flush() except Exception as e: logger.warning("failed to write to the log file: %s" % e) - logger.warning("the output of the commands is: %s" % proc.stdout) + logger.warning("the output of the commands is: %s" % + proc.stdout.decode('utf-8')) if proc.returncode != 0: logger.critical( diff --git a/vanilla_first_setup/window.py b/vanilla_first_setup/window.py index 9330aaf..32739ce 100644 --- a/vanilla_first_setup/window.py +++ b/vanilla_first_setup/window.py @@ -69,7 +69,12 @@ class VanillaWindow(Adw.ApplicationWindow): commands = Parser.parse(finals) # process the commands - return Processor.run(self.recipe["log_file"], commands) + return Processor.run( + self.recipe.get("log_file", "/tmp/vanilla_first_setup.log"), + self.recipe.get("pre_run", []), + self.recipe.get("post_run"), + commands + ) def on_done(result, *args): self.__view_done.set_result(result)