-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathupdates.py
97 lines (76 loc) · 3.14 KB
/
updates.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
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# updates.py - SSC Update Viewer
#
# Copyright 2013 Ikey Doherty <[email protected]>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
# MA 02110-1301, USA.
#
#
import gi.repository
from gi.repository import Gtk, GObject, Gdk
import pisi.api
import comar
import threading
from widgets import PackageLabel
class UpdatesView(Gtk.VBox):
def __init__(self, packagedb, installdb, basket):
Gtk.VBox.__init__(self)
self.packagedb = packagedb
self.installdb = installdb
self.basket = basket
self.updates_list = Gtk.ListBox()
scroller = Gtk.ScrolledWindow(None, None)
scroller.add(self.updates_list)
self.placeholder = Gtk.Label("")
self.placeholder.set_markup("<big>No updates are available at this time</big>")
self.placeholder_box = Gtk.HBox()
self.placeholder_box.add(self.placeholder)
# Check again for updates
check_updates = Gtk.Button("Check for updates now")
self.placeholder_box.pack_end(check_updates, False, False, 0)
check_updates.connect("clicked", self.refresh_repos)
self.placeholder_box.set_border_width(50)
self.placeholder_box.show_all()
self.updates_list.set_placeholder(self.placeholder_box)
self.pack_start(scroller, True, True, 0)
self.refresh_repos()
def do_reset(self):
self.load_updates()
def refresh_repos(self, btn=None):
self.basket.update_repo(cb=lambda : self.load_updates())
def load_updates(self):
GObject.idle_add(self._load_updates)
def op_selected(self, package_label, operation, package, old_package):
if operation == 'UPDATE':
self.basket.update_package(old_package, package)
elif operation == 'FORGET':
self.basket.forget_package(package)
def _load_updates(self):
updates = pisi.api.list_upgradable()
for child in self.updates_list.get_children():
child.destroy()
for update in updates:
old_pkg = self.installdb.get_package(update)
new_pkg = self.packagedb.get_package(update)
panel = PackageLabel(new_pkg, old_pkg, interactive=True)
panel.sig_id = panel.connect('operation-selected', self.op_selected)
panel.mark_status(None)
self.updates_list.add(panel)
while (Gtk.events_pending()):
Gtk.main_iteration()
panel.show_all()