1 |
# |
2 |
# progress_text.py: text mode install/upgrade progress dialog |
3 |
# |
4 |
# Copyright 2001-2002 Red Hat, Inc. |
5 |
# |
6 |
# This software may be freely redistributed under the terms of the GNU |
7 |
# library public license. |
8 |
# |
9 |
# You should have received a copy of the GNU Library Public License |
10 |
# along with this program; if not, write to the Free Software |
11 |
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
12 |
# |
13 |
import rpm |
14 |
from constants import * |
15 |
from snack import * |
16 |
from constants_text import * |
17 |
from rhpl.translate import _ |
18 |
|
19 |
from rhpl.log import log |
20 |
|
21 |
class InstallProgressWindow: |
22 |
def completePackage(self, header, timer): |
23 |
def formatTime(amt): |
24 |
hours = amt / 60 / 60 |
25 |
amt = amt % (60 * 60) |
26 |
min = amt / 60 |
27 |
amt = amt % 60 |
28 |
secs = amt |
29 |
|
30 |
return "%01d:%02d:%02d" % (int(hours) ,int(min), int(secs)) |
31 |
|
32 |
self.numComplete = self.numComplete + 1 |
33 |
self.sizeComplete = self.sizeComplete + (header[rpm.RPMTAG_SIZE] / 1024) |
34 |
self.numCompleteW.setText("%12d" % self.numComplete) |
35 |
self.sizeCompleteW.setText("%10dM" % (self.sizeComplete/1024)) |
36 |
self.numRemainingW.setText("%12d" % (self.numTotal - self.numComplete)) |
37 |
self.sizeRemainingW.setText("%10dM" % (self.sizeTotal/1024 - self.sizeComplete/1024)) |
38 |
self.total.set(self.sizeComplete) |
39 |
|
40 |
elapsedTime = timer.elapsed() |
41 |
if not elapsedTime: |
42 |
elapsedTime = 1 |
43 |
self.timeCompleteW.setText("%12s" % formatTime(elapsedTime)) |
44 |
if self.sizeComplete != 0: |
45 |
finishTime = (float (self.sizeTotal) / (self.sizeComplete)) * elapsedTime; |
46 |
else: |
47 |
finishTime = (float (self.sizeTotal) / (self.sizeComplete+1)) * elapsedTime; |
48 |
self.timeTotalW.setText("%12s" % formatTime(finishTime)) |
49 |
remainingTime = finishTime - elapsedTime; |
50 |
self.timeRemainingW.setText("%12s" % formatTime(remainingTime)) |
51 |
|
52 |
self.g.draw() |
53 |
self.screen.refresh() |
54 |
|
55 |
def setPackageScale(self, amount, total): |
56 |
self.s.set(int(((amount * 1.0)/ total) * 100)) |
57 |
self.g.draw() |
58 |
self.screen.refresh() |
59 |
|
60 |
def setPackageStatus(self, state, amount): |
61 |
if self.pkgstatus is None: |
62 |
return |
63 |
|
64 |
if state == "downloading": |
65 |
msgstr = _("Downloading - %s") % (amount,) |
66 |
else: |
67 |
msgstr = state |
68 |
self.pkgstatus.setText(msgstr) |
69 |
self.g.draw() |
70 |
self.screen.refresh() |
71 |
|
72 |
def setPackage(self, header): |
73 |
self.name.setText("%s-%s-%s-%s" % (header[rpm.RPMTAG_NAME], |
74 |
header[rpm.RPMTAG_VERSION], |
75 |
header[rpm.RPMTAG_RELEASE], |
76 |
header[rpm.RPMTAG_ARCH])) |
77 |
self.size.setText("%dk" % (header[rpm.RPMTAG_SIZE] / 1024)) |
78 |
summary = header[rpm.RPMTAG_SUMMARY] |
79 |
if (summary != None): |
80 |
self.summ.setText(summary) |
81 |
else: |
82 |
self.summ.setText("(none)") |
83 |
|
84 |
self.g.draw() |
85 |
self.screen.refresh() |
86 |
|
87 |
def processEvents(self): |
88 |
pass |
89 |
|
90 |
def setSizes(self, total, totalSize, totalFiles): |
91 |
screen = self.screen |
92 |
|
93 |
if self.showdownload: |
94 |
totlen = 7 |
95 |
else: |
96 |
totlen = 6 |
97 |
|
98 |
toplevel = GridForm(self.screen, _("Package Installation"), 1, totlen) |
99 |
|
100 |
name = _(" Name : ") |
101 |
size = _(" Size : ") |
102 |
sum = _(" Summary: ") |
103 |
|
104 |
currow = 0 |
105 |
|
106 |
width = 60 + max (len (name), len (size), len (sum)) |
107 |
self.name = Label(" " * 59) |
108 |
self.size = Label(" ") |
109 |
detail = Grid(2, 2) |
110 |
detail.setField(Label(name), 0, 0, anchorLeft = 1) |
111 |
detail.setField(Label(size), 0, 1, anchorLeft = 1) |
112 |
detail.setField(self.name, 1, 0, anchorLeft = 1) |
113 |
detail.setField(self.size, 1, 1, anchorLeft = 1) |
114 |
toplevel.add(detail, 0, currow) |
115 |
currow += 1 |
116 |
|
117 |
summary = Grid(2, 1) |
118 |
summlabel = Label(sum) |
119 |
self.summ = Textbox(48, 2, "", wrap = 1) |
120 |
summary.setField(summlabel, 0, 0) |
121 |
summary.setField(self.summ, 1, 0) |
122 |
toplevel.add(summary, 0, currow) |
123 |
currow += 1 |
124 |
|
125 |
if self.showdownload: |
126 |
toplevel.add(Label(""), 0, currow) |
127 |
currow += 1 |
128 |
|
129 |
pkgstatgrid = Grid(2, 1) |
130 |
pkgstatlabel = Label(_("Status: ")) |
131 |
self.pkgstatus = Label(" " * 48) |
132 |
pkgstatgrid.setField(pkgstatlabel, 0, 0) |
133 |
pkgstatgrid.setField(self.pkgstatus, 1, 0) |
134 |
toplevel.add(pkgstatgrid, 0, currow) |
135 |
currow += 1 |
136 |
else: |
137 |
self.pkgstatus = None |
138 |
|
139 |
self.s = Scale (width, 100) |
140 |
toplevel.add (self.s, 0, currow, (0, 1, 0, 1)) |
141 |
currow += 1 |
142 |
|
143 |
overall = Grid(4, 4) |
144 |
# don't ask me why, but if this spacer isn"t here then the |
145 |
# grid code gets unhappy |
146 |
overall.setField (Label (" " * 19), 0, 0, anchorLeft = 1) |
147 |
overall.setField (Label (_(" Packages")), 1, 0, anchorLeft = 1) |
148 |
overall.setField (Label (_(" Bytes")), 2, 0, anchorLeft = 1) |
149 |
overall.setField (Label (_(" Time")), 3, 0, anchorLeft = 1) |
150 |
|
151 |
overall.setField (Label (_("Total :")), 0, 1, anchorLeft = 1) |
152 |
overall.setField (Label ("%12d" % total), 1, 1, anchorLeft = 1) |
153 |
overall.setField (Label ("%10dM" % (totalSize/1024)), |
154 |
2, 1, anchorLeft = 1) |
155 |
self.timeTotalW = Label("") |
156 |
overall.setField(self.timeTotalW, 3, 1, anchorLeft = 1) |
157 |
|
158 |
overall.setField (Label (_("Completed: ")), 0, 2, anchorLeft = 1) |
159 |
self.numComplete = 0 |
160 |
self.numCompleteW = Label("%12d" % self.numComplete) |
161 |
overall.setField(self.numCompleteW, 1, 2, anchorLeft = 1) |
162 |
self.sizeComplete = 0 |
163 |
self.sizeCompleteW = Label("%10dM" % (self.sizeComplete)) |
164 |
overall.setField(self.sizeCompleteW, 2, 2, anchorLeft = 1) |
165 |
self.timeCompleteW = Label("") |
166 |
overall.setField(self.timeCompleteW, 3, 2, anchorLeft = 1) |
167 |
|
168 |
overall.setField (Label (_("Remaining: ")), 0, 3, anchorLeft = 1) |
169 |
self.numRemainingW = Label("%12d" % total) |
170 |
self.sizeRemainingW = Label("%10dM" % (totalSize/1024)) |
171 |
overall.setField(self.numRemainingW, 1, 3, anchorLeft = 1) |
172 |
overall.setField(self.sizeRemainingW, 2, 3, anchorLeft = 1) |
173 |
self.timeRemainingW = Label("") |
174 |
overall.setField(self.timeRemainingW, 3, 3, anchorLeft = 1) |
175 |
|
176 |
toplevel.add(overall, 0, currow) |
177 |
currow += 1 |
178 |
|
179 |
self.numTotal = total |
180 |
self.sizeTotal = totalSize |
181 |
self.total = Scale (width, totalSize) |
182 |
toplevel.add(self.total, 0, currow, (0, 1, 0, 0)) |
183 |
currow += 1 |
184 |
|
185 |
self.timeStarted = -1 |
186 |
|
187 |
toplevel.draw() |
188 |
self.g = toplevel |
189 |
screen.refresh() |
190 |
self.drawn = 1 |
191 |
|
192 |
def __init__(self, screen, showdownload=0): |
193 |
self.screen = screen |
194 |
self.showdownload = showdownload |
195 |
self.drawn = 0 |
196 |
|
197 |
def __del__ (self): |
198 |
if self.drawn: self.screen.popWindow () |
199 |
|
200 |
class setupForInstall: |
201 |
|
202 |
def __call__(self, screen, dir, intf, id): |
203 |
if dir == DISPATCH_BACK: |
204 |
id.setInstallProgressClass(None) |
205 |
return INSTALL_BACK |
206 |
else: |
207 |
flag = 0 |
208 |
for m in ['http://', 'ftp://']: |
209 |
if id.methodstr.startswith(m): |
210 |
flag = 1 |
211 |
break |
212 |
|
213 |
log("id.methodstr = %s %s", id.methodstr, flag) |
214 |
id.setInstallProgressClass(InstallProgressWindow(screen, showdownload=flag)) |
215 |
|
216 |
return INSTALL_OK |