summaryrefslogtreecommitdiffstats
path: root/iw/progress.py
blob: 04e584eb600a6fdad85d259d1edec441b8b0fe32 (plain)
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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
from gtk import *
from iw import *
import string
import rpm
import time
from threading import *

class DoInstall (Thread):
    def __init__ (self, icw, todo):
        self.todo = todo
        self.icw = icw
        Thread.__init__ (self)

    def run (self):
        self.todo.doInstall ()
        threads_enter ()
        self.icw.nextClicked ()
        threads_leave ()
                
class InstallProgressWindow (InstallWindow):

    def __init__ (self, ics):
	InstallWindow.__init__ (self, ics)

        ics.setTitle ("Installing Packages")
        ics.setPrevEnabled (0)

        self.todo = ics.getToDo ()
	self.numComplete = 0
	self.sizeComplete = 0
        
    def setPackageScale (self, amount, total):
        threads_enter ()
	self.progress.update (float (amount) / total)
        threads_leave ()

    def completePackage(self, header):
        def formatTime(amt):
            hours = amt / 60 / 60
            amt = amt % (60 * 60)
            min = amt / 60
            amt = amt % 60
            secs = amt

            return "%01d:%02d.%02d" % (int(hours) ,int(min), int(secs))

        threads_enter ()
        self.numComplete = self.numComplete + 1
        apply (self.clist.set_text, self.status["completed"]["packages"] + ("%d" % self.numComplete,))

	self.sizeComplete = self.sizeComplete + header[rpm.RPMTAG_SIZE]
        apply (self.clist.set_text, self.status["completed"]["size"] +
                                    ("%d M" % (self.sizeComplete / (1024 * 1024)),))

        apply (self.clist.set_text, self.status["remaining"]["packages"] +
                                    ("%d" % (self.numTotal - self.numComplete),))

        apply (self.clist.set_text, self.status["remaining"]["size"] +
                                    ("%d M" % ((self.totalSize - self.sizeComplete) / (1024 * 1024)),))

	elapsedTime = time.time() - self.timeStarted 
        apply (self.clist.set_text, self.status["completed"]["time"] + ("%s" % formatTime(elapsedTime),))

	finishTime = (float (self.totalSize) / self.sizeComplete) * elapsedTime
        apply (self.clist.set_text, self.status["total"]["time"] + ("%s" % formatTime(finishTime),))

	remainingTime = finishTime - elapsedTime
        apply (self.clist.set_text, self.status["remaining"]["time"] + ("%s" % formatTime(remainingTime),))

        threads_leave ()
        
        return

#        self.clist.set_text ("%d" % self.numComplete,
#                             status["completed"]["packages"]["row"],
#                             status["completed"]["packages"]["


	self.timeCompleteW.setText("%12s" % formatTime(elapsedTime))

	self.timeTotalW.setText("%12s" % formatTime(finishTime))

    def setPackage(self, header):
        threads_enter ()
        self.name.set_text (header[rpm.RPMTAG_NAME])
        self.size.set_text ("%.1f KBytes" % (header[rpm.RPMTAG_SIZE] / 1024.0))
        self.summary.set_text (header[rpm.RPMTAG_SUMMARY])
        threads_leave ()

    def setSizes (self, total, totalSize):
        threads_enter ()
        self.numTotal = total
        self.totalSize = totalSize
        self.timeStarted = time.time ()

        apply (self.clist.set_text, self.status["total"]["packages"] + ("%d" % total,))
        
        apply (self.clist.set_text, self.status["total"]["size"] +
                                    ("%d M" % (totalSize / (1024 * 1024)),))
        threads_leave ()

    def getScreen (self):
	table = GtkTable (3, 3)
	label = GtkLabel ("Package")
        label.set_alignment (0.0, 0.0)
	table.attach (label, 0, 1, 0, 1, FILL, 0)
	label = GtkLabel (":")
	table.attach (label, 1, 2, 0, 1, 0, 0, 5)
	label = GtkLabel (":")
	table.attach (label, 1, 2, 1, 2, 0, 0, 5)
	label = GtkLabel (":")
	label.set_alignment (0.0, 0.0)
	table.attach (label, 1, 2, 2, 3, 0, FILL | EXPAND, 5)
	label = GtkLabel ("Size")
        label.set_alignment (0.0, 0.0)
	table.attach (label, 0, 1, 1, 2, FILL, 0)
	label = GtkLabel ("Summary")
        label.set_alignment (0.0, 0.0)
	table.attach (label, 0, 1, 2, 3, FILL, FILL | EXPAND)

	self.name = GtkLabel();
        self.name.set_alignment (0.0, 0.0)
	self.size = GtkLabel();
        self.size.set_alignment (0.0, 0.0)
	self.summary = GtkLabel();
        self.summary.set_alignment (0.0, 0.0)
        self.summary.set_line_wrap (TRUE)
	self.summary.set_text ("\n\n")
	table.attach(self.name, 2, 3, 0, 1, FILL | EXPAND, 0)
	table.attach(self.size, 2, 3, 1, 2, FILL | EXPAND, 0)
	table.attach(self.summary, 2, 3, 2, 3, FILL | EXPAND, FILL | EXPAND)

        vbox = GtkVBox (FALSE, 10)
        vbox.pack_start (table, FALSE)

	self.progress = GtkProgressBar()
        vbox.pack_start (self.progress, FALSE)

        self.status =  {
            "total" :     { "packages" : (0, 1),
                            "size"     : (0, 2),
                            "time"     : (0, 3) },
            "completed" : { "packages" : (1, 1),
                            "size"     : (1, 2),
                            "time"     : (1, 3) },
            "remaining" : { "packages" : (2, 1),
                            "size"     : (2, 2),
                            "time"     : (2, 3) }
            }

        clist = GtkCList (4, ("Status", "Packages", "Size", "Time"))
        clist.set_column_justification (0, JUSTIFY_LEFT)
        clist.set_column_justification (1, JUSTIFY_RIGHT)
        clist.set_column_justification (2, JUSTIFY_RIGHT)
        clist.set_column_justification (3, JUSTIFY_RIGHT)
        clist.append (("Total", "0", "0", "0:00.00"))
        clist.append (("Completed", "0", "0", "0:00.00"))
        clist.append (("Remaining", "0", "0", "0:00.00"))
#        clist.set_column_auto_resize (0, TRUE)
	clist.columns_autosize ()
        self.clist = clist
        vbox.pack_start (clist, TRUE)

	self.ics.getInstallInterface ().setPackageProgressWindow (self)
        ii = self.ics.getInstallInterface ()
        icw = ii.icw
        worker = DoInstall (icw, self.todo)
        worker.start ()
	return vbox