1 | # progress-rpminstall.py |
---|
2 | # |
---|
3 | # Copyright (C) 2011 - Yasumichi Akahoshi |
---|
4 | # |
---|
5 | # This program is free software; you can redistribute it and/or modify |
---|
6 | # it under the terms of the GNU General Public License as published by |
---|
7 | # the Free Software Foundation; either version 2 of the License, or |
---|
8 | # (at your option) any later version. |
---|
9 | # |
---|
10 | # This program is distributed in the hope that it will be useful, |
---|
11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
13 | # GNU General Public License for more details. |
---|
14 | # |
---|
15 | # You should have received a copy of the GNU General Public License |
---|
16 | # along with this program. If not, see <http://www.gnu.org/licenses/>. |
---|
17 | |
---|
18 | from gi.repository import Gtk, GdkPixbuf, Gdk |
---|
19 | import os, sys, time, rpm |
---|
20 | |
---|
21 | UI_FILE = "ui/progress.ui" |
---|
22 | |
---|
23 | class ProgressDialog: |
---|
24 | def __init__(self, parent, ts): |
---|
25 | # Build user interface |
---|
26 | self.builder = Gtk.Builder() |
---|
27 | self.builder.set_translation_domain('rpminstall') |
---|
28 | self.builder.add_from_file(os.path.join (os.path.dirname(__file__), UI_FILE)) |
---|
29 | self.builder.connect_signals(self) |
---|
30 | |
---|
31 | self.dialog = self.builder.get_object('progress_dialog') |
---|
32 | self.ts = ts |
---|
33 | self.dialog.show() |
---|
34 | |
---|
35 | def run(self): |
---|
36 | self.ts.run (self.runCallback, None) |
---|
37 | return Gtk.ResponseType.OK |
---|
38 | |
---|
39 | def runCallback(self, reason, amount, total, key, client_data): |
---|
40 | TextBuffer = self.builder.get_object('textbuffer1') |
---|
41 | if reason == rpm.RPMCALLBACK_TRANS_START: |
---|
42 | self.total = total |
---|
43 | self.step = 0 |
---|
44 | label2 = self.builder.get_object('label2') |
---|
45 | label2.set_text( str(self.step) + '/' + str(self.total) ) |
---|
46 | TextBuffer.insert_at_cursor("Transaction start " |
---|
47 | + str(amount) + " " + str(total) + " " + str(key) + "\n") |
---|
48 | Gtk.main_iteration() |
---|
49 | |
---|
50 | elif reason == rpm.RPMCALLBACK_TRANS_PROGRESS: |
---|
51 | TextBuffer.insert_at_cursor("Transaction progress " |
---|
52 | + str(amount) + " " + str(total) + " " + str(key) + "\n") |
---|
53 | Gtk.main_iteration() |
---|
54 | |
---|
55 | elif reason == rpm.RPMCALLBACK_TRANS_STOP: |
---|
56 | TextBuffer.insert_at_cursor("Transaction stop " |
---|
57 | + str(amount) + " " + str(total) + " " + str(key) + "\n") |
---|
58 | Gtk.main_iteration() |
---|
59 | |
---|
60 | elif reason == rpm.RPMCALLBACK_INST_OPEN_FILE: |
---|
61 | TextBuffer.insert_at_cursor( "Opening file. " + str(reason) + " " + str(amount) |
---|
62 | + " " + str(total) + " " + str(key) + " " + str(client_data) + "\n") |
---|
63 | self.rpmtsCallback_fd = os.open(str(key), os.O_RDONLY) |
---|
64 | label1 = self.builder.get_object('label1') |
---|
65 | label1.set_text(_("Install ") + key) |
---|
66 | Gtk.main_iteration() |
---|
67 | return self.rpmtsCallback_fd |
---|
68 | |
---|
69 | elif reason == rpm.RPMCALLBACK_INST_START: |
---|
70 | TextBuffer.insert_at_cursor("Install Start" + "\n") |
---|
71 | Gtk.main_iteration() |
---|
72 | |
---|
73 | elif reason == rpm.RPMCALLBACK_INST_CLOSE_FILE: |
---|
74 | TextBuffer.insert_at_cursor("Closing file. " + str(reason) + " " + str(amount) |
---|
75 | + " " + str(total) + " " + str(key) + " " + str(client_data) + "\n") |
---|
76 | os.close(self.rpmtsCallback_fd) |
---|
77 | Gtk.main_iteration() |
---|
78 | self.step += 1 |
---|
79 | progressbar2 = self.builder.get_object('progressbar2') |
---|
80 | progressbar2.set_fraction(float(self.step) / self.total) |
---|
81 | Gtk.main_iteration() |
---|
82 | label2 = self.builder.get_object('label2') |
---|
83 | label2.set_text( str(self.step) + '/' + str(self.total) ) |
---|
84 | Gtk.main_iteration() |
---|
85 | if self.step == self.total: |
---|
86 | time.sleep(5) |
---|
87 | self.dialog.destroy() |
---|
88 | |
---|
89 | elif reason == rpm.rpm.RPMCALLBACK_INST_PROGRESS: |
---|
90 | progressbar1 = self.builder.get_object('progressbar1') |
---|
91 | progressbar1.set_fraction(float(amount) / total) |
---|
92 | Gtk.main_iteration() |
---|
93 | |
---|
94 | elif reason == rpm.RPMCALLBACK_TRANS_STOP: |
---|
95 | TextBuffer.insert_at_cursor("stop" + "\n") |
---|
96 | Gtk.main_iteration() |
---|
97 | |
---|
98 | elif reason == rpm.RPMCALLBACK_UNKNOWN: |
---|
99 | TextBuffer.insert_at_cursor("problem" + "\n") |
---|
100 | Gtk.main_iteration() |
---|
101 | |
---|
102 | elif reason == rpm.RPMCALLBACK_UNINST_PROGRESS: |
---|
103 | TextBuffer.insert_at_cursor("RPMCALLBACK_UNINST_PROGRESS" + "\n") |
---|
104 | Gtk.main_iteration() |
---|
105 | |
---|
106 | elif reason == rpm.RPMCALLBACK_UNINST_START: |
---|
107 | TextBuffer.insert_at_cursor("RPMCALLBACK_UNINST_START" + "\n") |
---|
108 | Gtk.main_iteration() |
---|
109 | |
---|
110 | elif reason == rpm.RPMCALLBACK_UNINST_STOP: |
---|
111 | TextBuffer.insert_at_cursor("RPMCALLBACK_UNINST_STOP" + "\n") |
---|
112 | Gtk.main_iteration() |
---|
113 | |
---|
114 | elif reason == rpm.RPMCALLBACK_REPACKAGE_PROGRESS: |
---|
115 | TextBuffer.insert_at_cursor("RPMCALLBACK_REPACKAGE_PROGRESS" + "\n") |
---|
116 | Gtk.main_iteration() |
---|
117 | |
---|
118 | elif reason == rpm.RPMCALLBACK_REPACKAGE_START: |
---|
119 | TextBuffer.insert_at_cursor("RPMCALLBACK_REPACKAGE_START" + "\n") |
---|
120 | Gtk.main_iteration() |
---|
121 | |
---|
122 | elif reason == rpm.RPMCALLBACK_REPACKAGE_STOP: |
---|
123 | TextBuffer.insert_at_cursor("RPMCALLBACK_REPACKAGE_STOP" + "\n") |
---|
124 | Gtk.main_iteration() |
---|
125 | |
---|
126 | elif reason == rpm.RPMCALLBACK_UNPACK_ERROR: |
---|
127 | TextBuffer.insert_at_cursor("RPMCALLBACK_UNPACK_ERROR" + "\n") |
---|
128 | Gtk.main_iteration() |
---|
129 | |
---|
130 | elif reason == rpm.RPMCALLBACK_CPIO_ERROR: |
---|
131 | TextBuffer.insert_at_cursor("RPMCALLBACK_CPIO_ERROR" + "\n") |
---|
132 | Gtk.main_iteration() |
---|
133 | |
---|
134 | else: |
---|
135 | TextBuffer.insert_at_cursor(str(reason)) |
---|
136 | Gtk.main_iteration() |
---|
137 | |
---|