-
Notifications
You must be signed in to change notification settings - Fork 0
/
pepupgtk.py
executable file
·124 lines (98 loc) · 4.22 KB
/
pepupgtk.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
#!/usr/bin/env python3
import gi
import subprocess as s
gi.require_version("Gtk", "3.0")
import threading
from gi.repository import GLib, Gtk
class PepUpWindow(Gtk.Window):
"""Window update class."""
def __init__(self):
super().__init__(title="Peppermint Update (GTK)")
self.set_border_width(10)
self.set_default_size(640, 200)
self.set_position(Gtk.WindowPosition.CENTER)
self.set_resizable(True)
frame1 = Gtk.Frame(label="Peppermint Update")
grid1 = Gtk.Grid(row_spacing=10, column_spacing=10, column_homogeneous=True)
self.label1 = Gtk.Label(label="Updates: Ready...")
self.label1.set_hexpand(True)
self.spinner = Gtk.Spinner()
self.spinner.set_hexpand(True)
self.spinner.set_vexpand(True)
button_updates = Gtk.Button(label="Check for updates")
button_updates.set_hexpand(True)
button_updates.connect("clicked", self.on_button_updates_clicked)
button_updates.set_tooltip_text("apt update")
self.button_upgrade = Gtk.Button(label="Install Updates")
self.button_upgrade.set_hexpand(True)
self.button_upgrade.set_sensitive(False)
self.button_upgrade.connect("clicked", self.on_button_upgrade_clicked)
self.button_upgrade.set_tooltip_text("apt upgrade")
button_q = Gtk.Button(label="Quit")
button_q.set_hexpand(True)
button_q.connect("clicked", Gtk.main_quit)
button_q.set_tooltip_text("Quit")
grid1.attach(self.label1, 0, 2, 3, 2)
grid1.attach(self.spinner, 0, 4, 3, 2)
grid1.attach(button_updates, 0, 8, 1, 1)
grid1.attach(self.button_upgrade, 1, 8, 1, 1)
grid1.attach(button_q, 2, 8, 1, 1)
self.add(frame1)
frame1.add(grid1)
def on_button_updates_clicked(self, widget):
"""Button to check for updates"""
self.spinner.start()
self.label1.set_text("Updates: Checking...")
threading.Thread(target=self.run_update_check).start()
def run_update_check(self):
update_process = s.run("apt-get -q update", shell=True)
if update_process.returncode != 0:
GLib.idle_add(self.show_error, "Unable to check for updates")
return
updates_process = s.run(
"apt-get -q -y --ignore-hold --allow-change-held-packages --allow-unauthenticated -s dist-upgrade | /bin/grep ^Inst | wc -l",
shell=True,
stdout=s.PIPE,
)
if updates_process.returncode != 0:
GLib.idle_add(self.show_error, "Unable to count updates")
return
updates = updates_process.stdout.decode("utf-8").strip()
try:
updates = int(updates)
except ValueError:
GLib.idle_add(self.show_error, "Unable to parse update count")
return
GLib.idle_add(self.update_results, updates)
def show_error(self, message):
self.label1.set_text(f"Error: {message}")
self.spinner.stop()
def update_results(self, updates):
if updates == 0:
self.label1.set_text("Updates: Your system is up-to-date.")
self.button_upgrade.set_sensitive(False)
elif updates == 1:
self.label1.set_text("Updates: There is one update available.")
self.button_upgrade.set_sensitive(True)
else:
self.label1.set_text(f"Updates: There are {updates} updates available.")
self.button_upgrade.set_sensitive(True)
self.spinner.stop()
def on_button_upgrade_clicked(self, widget):
"""Button for upgrade. Unlocked only when updates are available."""
self.spinner.start()
self.label1.set_text("Updates: Updating...")
threading.Thread(target=self.run_upgrade).start()
def run_upgrade(self):
upgrade_process = s.run("nala upgrade -y", shell=True)
if upgrade_process.returncode != 0:
GLib.idle_add(self.show_error, "Unable to perform upgrade")
return
GLib.idle_add(self.update_after_upgrade)
def update_after_upgrade(self):
self.label1.set_text("Updates: Update Complete!")
self.spinner.stop()
win1 = PepUpWindow()
win1.connect("destroy", Gtk.main_quit)
win1.show_all()
Gtk.main()