misc: Show error log on fail

main
mirkobrombin 2 years ago
parent 7ac5786c21
commit 986a8802a1

@ -17,10 +17,34 @@
<child>
<object class="GtkBox">
<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>
<object class="GtkButton" id="btn_reboot">
<property name="label">Reboot Now</property>
<property name="halign">center</property>
<property name="valign">center</property>
<style>
<class name="pill" />
<class name="suggested-action" />

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

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

Loading…
Cancel
Save