misc: Show error log on fail

main
mirkobrombin 2 years ago
parent 7ac5786c21
commit 986a8802a1

@ -17,10 +17,34 @@
<child> <child>
<object class="GtkBox"> <object class="GtkBox">
<property name="halign">center</property> <property name="halign">center</property>
<property name="orientation">vertical</property>
<child>
<object class="GtkBox" id="log_box">
<property name="visible">false</property>
<property name="margin-start">40</property>
<property name="margin-end">40</property>
<property name="margin-top">1</property>
<property name="margin-bottom">18</property>
<property name="width-request">500</property>
<property name="height-request">200</property>
<property name="orientation">vertical</property>
<child>
<object class="GtkLabel" id="log_output">
<property name="margin-top">12</property>
<property name="margin-start">12</property>
<property name="margin-end">12</property>
</object>
</child>
<style>
<class name="card"/>
</style>
</object>
</child>
<child> <child>
<object class="GtkButton" id="btn_reboot"> <object class="GtkButton" id="btn_reboot">
<property name="label">Reboot Now</property> <property name="label">Reboot Now</property>
<property name="halign">center</property> <property name="halign">center</property>
<property name="valign">center</property>
<style> <style>
<class name="pill" /> <class name="pill" />
<class name="suggested-action" /> <class name="suggested-action" />

@ -37,6 +37,14 @@ class Processor:
logger.info("processing the following commands: \n%s" % logger.info("processing the following commands: \n%s" %
'\n'.join(commands)) '\n'.join(commands))
# connection check
cn = subprocess.run(["wget", "-q", "--spider", "cloudflare.com"],
stdout=subprocess.DEVNULL,
stderr=subprocess.DEVNULL)
if cn.returncode != 0:
logger.critical("No internet connection")
return False, "No internet connection."
# nextBoot commands are collected in ~/.local/org.vanillaos.FirstSetup.nextBoot # nextBoot commands are collected in ~/.local/org.vanillaos.FirstSetup.nextBoot
# and executed at the next boot by a desktop entry # and executed at the next boot by a desktop entry
@ -103,34 +111,32 @@ class Processor:
# fake the process if VANILLA_FAKE is set # fake the process if VANILLA_FAKE is set
if "VANILLA_FAKE" in os.environ: if "VANILLA_FAKE" in os.environ:
return True return True, ""
cmd = ["pkexec", "sh", f.name] cmd = ["pkexec", "sh", f.name]
if abroot_bin := shutil.which("abroot"): if abroot_bin := shutil.which("abroot"):
cmd = ["pkexec", abroot_bin, "exec", "--assume-yes", "sh", f.name] cmd = ["pkexec", abroot_bin, "exec", "--assume-yes", "sh", f.name]
proc = subprocess.run( #proc = subprocess.run(cmd)
cmd, # the above is wrong, we need to show the output in the console but also capture it
check=True, proc = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
stdout=subprocess.PIPE, out = proc.communicate()[0].decode("utf-8")
stderr=subprocess.STDOUT
)
# write the output to the log file so the packager can see what # write the output to the log file so the packager can see what
# happened during the installation process # happened during the installation process
try: try:
with open(log_path, 'a') as log: with open(log_path, 'a') as log:
log.write(proc.stdout.decode('utf-8')) log.write(out)
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" % logger.warning("the output of the commands is: %s" %
proc.stdout.decode('utf-8')) out)
if proc.returncode != 0: if proc.returncode != 0:
logger.critical( logger.critical(
"Error while processing commands, see log for details.") "Error while processing commands, see log for details.")
return False return False, out
autostart_file = os.path.expanduser( autostart_file = os.path.expanduser(
"~/.config/autostart/org.vanillaos.FirstSetup.desktop") "~/.config/autostart/org.vanillaos.FirstSetup.desktop")
@ -142,4 +148,4 @@ class Processor:
logger.info("running outRun commands: \n%s" % out_run) logger.info("running outRun commands: \n%s" % out_run)
subprocess.run(out_run, shell=True) subprocess.run(out_run, shell=True)
return True return True, ""

@ -25,6 +25,8 @@ class VanillaDone(Adw.Bin):
status_page = Gtk.Template.Child() status_page = Gtk.Template.Child()
btn_reboot = Gtk.Template.Child() btn_reboot = Gtk.Template.Child()
btn_close = Gtk.Template.Child() btn_close = Gtk.Template.Child()
log_box = Gtk.Template.Child()
log_output = Gtk.Template.Child()
def __init__(self, window, reboot: bool=True, title: str="", description: str="", fail_title: str="", fail_description: str="", **kwargs): def __init__(self, window, reboot: bool=True, title: str="", description: str="", fail_title: str="", fail_description: str="", **kwargs):
super().__init__(**kwargs) super().__init__(**kwargs)
@ -50,16 +52,21 @@ class VanillaDone(Adw.Bin):
self.btn_close.connect("clicked", self.__on_close_clicked) self.btn_close.connect("clicked", self.__on_close_clicked)
def set_result(self, result): def set_result(self, result):
if result: res, msg = result
if res:
return return
self.status_page.set_icon_name("dialog-error-symbolic") self.status_page.set_icon_name("dialog-error-symbolic")
if not self.__fail_title and not self.__fail_description: if not self.__fail_title and not self.__fail_description:
self.status_page.set_title(_("Something went wrong")) self.status_page.set_title(_("Something went wrong"))
self.status_page.set_description(_("Please contact the distribution developers.")) self.status_page.set_description(_("Please contact the distribution developers."))
self.log_box.set_visible(True)
self.log_output.set_text(msg)
else: else:
self.status_page.set_title(self.__fail_title) self.status_page.set_title(self.__fail_title)
self.status_page.set_description(self.__fail_description) self.status_page.set_description(self.__fail_description)
self.log_box.set_visible(False)
self.btn_reboot.set_visible(False) self.btn_reboot.set_visible(False)
self.btn_close.set_visible(True) self.btn_close.set_visible(True)

Loading…
Cancel
Save