sytem: fix updater when moonraker doesn't return configured_type

This commit is contained in:
alfrix 2022-02-13 17:23:37 -03:00
parent 926773f4f3
commit 1753105265

View File

@ -174,54 +174,48 @@ class SystemPanel(ScreenPanel):
i = 0 i = 0
label = Gtk.Label() label = Gtk.Label()
label.set_line_wrap(True) label.set_line_wrap(True)
if "configured_type" in info: if 'configured_type' in info and info['configured_type'] == 'git_repo':
if info['configured_type'] == 'git_repo': if not info['is_valid'] or info['is_dirty']:
if not info['is_valid'] or info['is_dirty']: label.set_markup(_("Do you want to recover %s?") % program)
label.set_markup(_("Do you want to recover %s?") % program) grid.attach(label, 0, i, 1, 1)
grid.attach(label, 0, i, 1, 1) scroll.add(grid)
scroll.add(grid) recoverybuttons = [
recoverybuttons = [ {"name": _("Recover Hard"), "response": Gtk.ResponseType.OK},
{"name": _("Recover Hard"), "response": Gtk.ResponseType.OK}, {"name": _("Recover Soft"), "response": Gtk.ResponseType.APPLY},
{"name": _("Recover Soft"), "response": Gtk.ResponseType.APPLY}, {"name": _("Cancel"), "response": Gtk.ResponseType.CANCEL}
{"name": _("Cancel"), "response": Gtk.ResponseType.CANCEL} ]
] dialog = self._gtk.Dialog(self._screen, recoverybuttons, scroll, self.reset_confirm, program)
dialog = self._gtk.Dialog(self._screen, recoverybuttons, scroll, self.reset_confirm, program) return
else:
if info['version'] == info['remote_version']:
return return
else: label.set_markup("<b>" + _("Outdated by %d commits:") % len(info['commits_behind']) + "</b>\n")
if info['version'] == info['remote_version']: grid.attach(label, 0, i, 1, 1)
return i = i + 1
label.set_markup("<b>" + _("Outdated by %d commits:") % len(info['commits_behind']) + "</b>\n") date = ""
grid.attach(label, 0, i, 1, 1) for c in info['commits_behind']:
i = i + 1 ndate = datetime.fromtimestamp(int(c['date'])).strftime("%b %d")
date = "" if date != ndate:
for c in info['commits_behind']: date = ndate
ndate = datetime.fromtimestamp(int(c['date'])).strftime("%b %d")
if date != ndate:
date = ndate
label = Gtk.Label()
label.set_line_wrap(True)
label.set_markup("<b>%s</b>\n" % date)
label.set_halign(Gtk.Align.START)
grid.attach(label, 0, i, 1, 1)
i = i + 1
label = Gtk.Label() label = Gtk.Label()
label.set_line_wrap(True) label.set_line_wrap(True)
label.set_markup("<b>%s</b>\n<i>%s</i>\n" % (c['subject'], c['author'])) label.set_markup("<b>%s</b>\n" % date)
label.set_halign(Gtk.Align.START) label.set_halign(Gtk.Align.START)
grid.attach(label, 0, i, 1, 1) grid.attach(label, 0, i, 1, 1)
i = i + 1 i = i + 1
details = Gtk.Label(label=c['message']+"\n\n\n") label = Gtk.Label()
details.set_line_wrap(True) label.set_line_wrap(True)
details.set_halign(Gtk.Align.START) label.set_markup("<b>%s</b>\n<i>%s</i>\n" % (c['subject'], c['author']))
grid.attach(details, 0, i, 1, 1) label.set_halign(Gtk.Align.START)
i = i + 1 grid.attach(label, 0, i, 1, 1)
else: i = i + 1
label.set_markup("<b>" + _("%s will be updated to version") % program.capitalize() +
": %s</b>" % (info['remote_version'])) details = Gtk.Label(label=c['message']+"\n\n\n")
grid.attach(label, 0, i, 1, 1) details.set_line_wrap(True)
i = i + 1 details.set_halign(Gtk.Align.START)
grid.attach(details, 0, i, 1, 1)
i = i + 1
if "package_count" in info: if "package_count" in info:
label.set_markup("<b>" + _("%d Packages will be updated") % info['package_count'] + ":</b>\n") label.set_markup("<b>" + _("%d Packages will be updated") % info['package_count'] + ":</b>\n")
label.set_halign(Gtk.Align.CENTER) label.set_halign(Gtk.Align.CENTER)
@ -239,6 +233,11 @@ class SystemPanel(ScreenPanel):
j = j + 1 j = j + 1
if (pos == 2): if (pos == 2):
i = i + 1 i = i + 1
else:
label.set_markup("<b>" + _("%s will be updated to version") % program.capitalize() +
": %s</b>" % (info['remote_version']))
grid.attach(label, 0, i, 1, 1)
i = i + 1
scroll.add(grid) scroll.add(grid)
@ -359,7 +358,7 @@ class SystemPanel(ScreenPanel):
logging.info("%s: %s" % (p, info)) logging.info("%s: %s" % (p, info))
if p != "system": if p != "system":
if info['configured_type'] == 'git_repo': if 'configured_type' in info and info['configured_type'] == 'git_repo':
if info['is_valid'] and not info['is_dirty']: if info['is_valid'] and not info['is_dirty']:
if info['version'] == info['remote_version']: if info['version'] == info['remote_version']:
self.labels[p].set_markup("<b>%s</b>\n%s" % (p, info['version'])) self.labels[p].set_markup("<b>%s</b>\n%s" % (p, info['version']))
@ -378,7 +377,7 @@ class SystemPanel(ScreenPanel):
self.labels["%s_status" % p].get_style_context().add_class('invalid') self.labels["%s_status" % p].get_style_context().add_class('invalid')
self.labels["%s_status" % p].set_sensitive(True) self.labels["%s_status" % p].set_sensitive(True)
else: else:
if info['version'] == info['remote_version']: if 'version' in info and info['version'] == info['remote_version']:
self.labels[p].set_markup("<b>%s</b>\n%s" % (p, info['version'])) self.labels[p].set_markup("<b>%s</b>\n%s" % (p, info['version']))
self.labels["%s_status" % p].set_label(_("Up To Date")) self.labels["%s_status" % p].set_label(_("Up To Date"))
self.labels["%s_status" % p].get_style_context().remove_class('update') self.labels["%s_status" % p].get_style_context().remove_class('update')