[5046] | 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 |
---|
[5118] | 19 | import os, sys, time, rpm |
---|
[5046] | 20 | |
---|
[5069] | 21 | UI_FILE = "ui/progress.ui" |
---|
[5046] | 22 | |
---|
| 23 | class ProgressDialog: |
---|
| 24 | def __init__(self, parent, ts): |
---|
| 25 | # Build user interface |
---|
| 26 | self.builder = Gtk.Builder() |
---|
[5093] | 27 | self.builder.set_translation_domain('rpminstall') |
---|
[5050] | 28 | self.builder.add_from_file(os.path.join (os.path.dirname(__file__), UI_FILE)) |
---|
[5046] | 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): |
---|
[5118] | 40 | TextBuffer = self.builder.get_object('textbuffer1') |
---|
[5046] | 41 | if reason == rpm.RPMCALLBACK_TRANS_START: |
---|
| 42 | self.total = total |
---|
| 43 | self.step = 0 |
---|
[5118] | 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() |
---|
[5046] | 49 | |
---|
| 50 | elif reason == rpm.RPMCALLBACK_TRANS_PROGRESS: |
---|
[5118] | 51 | TextBuffer.insert_at_cursor("Transaction progress " |
---|
| 52 | + str(amount) + " " + str(total) + " " + str(key) + "\n") |
---|
| 53 | Gtk.main_iteration() |
---|
[5046] | 54 | |
---|
| 55 | elif reason == rpm.RPMCALLBACK_TRANS_STOP: |
---|
[5118] | 56 | TextBuffer.insert_at_cursor("Transaction stop " |
---|
| 57 | + str(amount) + " " + str(total) + " " + str(key) + "\n") |
---|
| 58 | Gtk.main_iteration() |
---|
[5046] | 59 | |
---|
| 60 | elif reason == rpm.RPMCALLBACK_INST_OPEN_FILE: |
---|
[5118] | 61 | TextBuffer.insert_at_cursor( "Opening file. " + str(reason) + " " + str(amount) |
---|
| 62 | + " " + str(total) + " " + str(key) + " " + str(client_data) + "\n") |
---|
[5046] | 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: |
---|
[5118] | 70 | TextBuffer.insert_at_cursor("Install Start" + "\n") |
---|
| 71 | Gtk.main_iteration() |
---|
[5046] | 72 | |
---|
| 73 | elif reason == rpm.RPMCALLBACK_INST_CLOSE_FILE: |
---|
[5118] | 74 | TextBuffer.insert_at_cursor("Closing file. " + str(reason) + " " + str(amount) |
---|
| 75 | + " " + str(total) + " " + str(key) + " " + str(client_data) + "\n") |
---|
[5046] | 76 | os.close(self.rpmtsCallback_fd) |
---|
[5118] | 77 | Gtk.main_iteration() |
---|
| 78 | self.step += 1 |
---|
[5046] | 79 | progressbar2 = self.builder.get_object('progressbar2') |
---|
[5118] | 80 | progressbar2.set_fraction(float(self.step) / self.total) |
---|
[5046] | 81 | Gtk.main_iteration() |
---|
[5118] | 82 | label2 = self.builder.get_object('label2') |
---|
| 83 | label2.set_text( str(self.step) + '/' + str(self.total) ) |
---|
| 84 | Gtk.main_iteration() |
---|
[5046] | 85 | if self.step == self.total: |
---|
[5118] | 86 | time.sleep(5) |
---|
[5046] | 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: |
---|
[5118] | 95 | TextBuffer.insert_at_cursor("stop" + "\n") |
---|
| 96 | Gtk.main_iteration() |
---|
[5046] | 97 | |
---|
| 98 | elif reason == rpm.RPMCALLBACK_UNKNOWN: |
---|
[5118] | 99 | TextBuffer.insert_at_cursor("problem" + "\n") |
---|
[5046] | 100 | Gtk.main_iteration() |
---|
| 101 | |
---|
| 102 | elif reason == rpm.RPMCALLBACK_UNINST_PROGRESS: |
---|
[5118] | 103 | TextBuffer.insert_at_cursor("RPMCALLBACK_UNINST_PROGRESS" + "\n") |
---|
| 104 | Gtk.main_iteration() |
---|
[5046] | 105 | |
---|
| 106 | elif reason == rpm.RPMCALLBACK_UNINST_START: |
---|
[5118] | 107 | TextBuffer.insert_at_cursor("RPMCALLBACK_UNINST_START" + "\n") |
---|
| 108 | Gtk.main_iteration() |
---|
[5046] | 109 | |
---|
| 110 | elif reason == rpm.RPMCALLBACK_UNINST_STOP: |
---|
[5118] | 111 | TextBuffer.insert_at_cursor("RPMCALLBACK_UNINST_STOP" + "\n") |
---|
| 112 | Gtk.main_iteration() |
---|
[5046] | 113 | |
---|
| 114 | elif reason == rpm.RPMCALLBACK_REPACKAGE_PROGRESS: |
---|
[5118] | 115 | TextBuffer.insert_at_cursor("RPMCALLBACK_REPACKAGE_PROGRESS" + "\n") |
---|
| 116 | Gtk.main_iteration() |
---|
[5046] | 117 | |
---|
| 118 | elif reason == rpm.RPMCALLBACK_REPACKAGE_START: |
---|
[5118] | 119 | TextBuffer.insert_at_cursor("RPMCALLBACK_REPACKAGE_START" + "\n") |
---|
| 120 | Gtk.main_iteration() |
---|
[5046] | 121 | |
---|
| 122 | elif reason == rpm.RPMCALLBACK_REPACKAGE_STOP: |
---|
[5118] | 123 | TextBuffer.insert_at_cursor("RPMCALLBACK_REPACKAGE_STOP" + "\n") |
---|
| 124 | Gtk.main_iteration() |
---|
[5046] | 125 | |
---|
| 126 | elif reason == rpm.RPMCALLBACK_UNPACK_ERROR: |
---|
[5118] | 127 | TextBuffer.insert_at_cursor("RPMCALLBACK_UNPACK_ERROR" + "\n") |
---|
| 128 | Gtk.main_iteration() |
---|
[5046] | 129 | |
---|
| 130 | elif reason == rpm.RPMCALLBACK_CPIO_ERROR: |
---|
[5118] | 131 | TextBuffer.insert_at_cursor("RPMCALLBACK_CPIO_ERROR" + "\n") |
---|
| 132 | Gtk.main_iteration() |
---|
[5046] | 133 | |
---|
| 134 | else: |
---|
[5118] | 135 | TextBuffer.insert_at_cursor(str(reason)) |
---|
| 136 | Gtk.main_iteration() |
---|
[5046] | 137 | |
---|