Display and select commit in change versions page

This commit is contained in:
heliguy
2024-07-08 22:09:22 -04:00
parent 0a21625a8c
commit 4ecfa6b763
2 changed files with 52 additions and 21 deletions

View File

@@ -7,7 +7,7 @@ template $ChangeVersionPage : Adw.NavigationPage {
[top]
Adw.HeaderBar {
}
Adw.ToastOverlay {
Adw.ToastOverlay toast_overlay {
ScrolledWindow scrolled_window {
Adw.Clamp {
Box {

View File

@@ -1,4 +1,4 @@
from gi.repository import Adw, Gtk,GLib#, Gio, Pango
from gi.repository import Adw, Gtk,GLib, Gio
from .error_toast import ErrorToast
from .host_info import HostInfo
import subprocess, os
@@ -7,6 +7,7 @@ import subprocess, os
class ChangeVersionPage(Adw.NavigationPage):
__gtype_name__ = 'ChangeVersionPage'
gtc = Gtk.Template.Child
toast_overlay = gtc()
scrolled_window = gtc()
root_group_check_button = gtc()
mask_group = gtc()
@@ -14,7 +15,10 @@ class ChangeVersionPage(Adw.NavigationPage):
versions_group = gtc()
action_bar = gtc()
def get_commits(self):
selected_commit = None
failure = None
def get_commits(self, *args):
cmd = ['flatpak-spawn', '--host', 'sh', '-c']
script = f"LC_ALL=C flatpak remote-info --log {self.package.info['origin']} {self.package.info['ref']} "
installation = self.package.info["installation"]
@@ -28,25 +32,51 @@ class ChangeVersionPage(Adw.NavigationPage):
commits = []
changes = []
dates = []
output = subprocess.run(cmd, check=True, capture_output=True, text=True).stdout
lines = output.strip().split('\n')
for line in lines:
line = line.strip().split(": ", 1)
if len(line) < 2:
continue
elif line[0].startswith("Commit"):
commits.append(line[1])
elif line[0].startswith("Subject"):
changes.append(line[1])
elif line[0].startswith("Date"):
dates.append(line[1])
if not (len(commits) == len(changes) == len(dates)):
try:
output = subprocess.run(cmd, check=True, capture_output=True, text=True).stdout
lines = output.strip().split('\n')
for line in lines:
line = line.strip().split(": ", 1)
if len(line) < 2:
continue
elif line[0].startswith("Commit"):
commits.append(line[1])
elif line[0].startswith("Subject"):
changes.append(line[1])
elif line[0].startswith("Date"):
dates.append(line[1])
except subprocess.CalledProcessError as cpe:
self.failure = cpe.stderr
return
except Exception as e:
self.failure = str(e)
return
for index, element in enumerate(changes):
row = Adw.ActionRow(title=GLib.markup_escape_text(element), subtitle=GLib.markup_escape_text(dates[index]))
self.versions_group.add(row)
if not (len(commits) == len(changes) == len(dates)):
self.failure = "Commits, Changes, and Dates are not of equivalent length"
return
def idle(*args):
for index, commit in enumerate(commits):
row = Adw.ActionRow(title=GLib.markup_escape_text(changes[index]), subtitle=f"{GLib.markup_escape_text(commit)}\n{GLib.markup_escape_text(dates[index])}")
check = Gtk.CheckButton()
check.connect("activate", lambda *_, comm=commit: self.set_commit(comm))
check.set_group(self.root_group_check_button)
row.set_activatable_widget(check)
row.add_prefix(check)
self.versions_group.add(row)
GLib.idle_add(idle)
def set_commit(self, commit):
self.selected_commit = commit
def callback(self, *args):
if not self.failure is None:
self.toast_overlay.add_toast(ErrorToast(_("Could not get versions"), self.failure).toast)
else:
print("yay")
def __init__(self, main_window, package, **kwargs):
super().__init__(**kwargs)
@@ -58,7 +88,8 @@ class ChangeVersionPage(Adw.NavigationPage):
pkg_name = package.info["name"]
self.set_title(_("{} Versions").format(pkg_name))
self.mask_row.set_subtitle(_("Ensure that {} will never be updated to a newer version").format(pkg_name))
self.get_commits()
Gio.Task.new(None, None, self.callback).run_in_thread(self.get_commits)
# for i in range(10):
# row = Adw.ActionRow(title=f"Update to {i}.0", subtitle="Some dumb nerd shit I don't care about", activatable=True)