support pre-run, post-run commands

main
Mirko Brombin 2 years ago
parent 1a9b4db2b1
commit c689be9aa2

@ -2,6 +2,14 @@
"log_file": "/etc/vanilla/first-setup.log", "log_file": "/etc/vanilla/first-setup.log",
"distro_name": "Vanilla OS", "distro_name": "Vanilla OS",
"distro_logo": "io.github.vanilla-os.FirstSetup", "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": { "steps": {
"welcome": { "welcome": {
"template": "welcome" "template": "welcome"
@ -115,7 +123,7 @@
"if": "immutability", "if": "immutability",
"type": "command", "type": "command",
"commands": [ "commands": [
"sudo apt install -y almost", "sudo apt install -y almost almost-extras",
"sudo almost enter rw" "sudo almost enter rw"
] ]
} }

@ -26,7 +26,9 @@ logger = logging.getLogger("FirstSetup::Processor")
class Processor: class Processor:
@staticmethod @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" % logger.info("processing the following commands: \n%s" %
'\n'.join(commands)) '\n'.join(commands))
@ -65,7 +67,8 @@ class Processor:
log.flush() log.flush()
except Exception as e: except Exception as e:
logger.warning("failed to write to the log file: %s" % 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: if proc.returncode != 0:
logger.critical( logger.critical(

@ -69,7 +69,12 @@ class VanillaWindow(Adw.ApplicationWindow):
commands = Parser.parse(finals) commands = Parser.parse(finals)
# process the commands # 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): def on_done(result, *args):
self.__view_done.set_result(result) self.__view_done.set_result(result)

Loading…
Cancel
Save