This file is indexed.

/usr/share/pyshared/smart/progress.py is in python-smartpm 1.4-2.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  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
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
#
# Copyright (c) 2004 Conectiva, Inc.
#
# Written by Gustavo Niemeyer <niemeyer@conectiva.com>
#
# This file is part of Smart Package Manager.
#
# Smart Package Manager 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.
#
# Smart Package Manager 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 Smart Package Manager; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
#
import thread
import time
import sys

INTERVAL = 0.1

class Progress(object):

    def __init__(self):
        self.__topic = ""
        self.__progress = (0, 0, {}) # (current, total, data)
        self.__lastshown = None
        self.__done = False
        self.__subtopic = {}
        self.__subprogress = {} # (subcurrent, subtotal, fragment, subdata)
        self.__sublastshown = {}
        self.__subdone = {}
        self.__lasttime = 0
        self.__lock = thread.allocate_lock()
        self.__hassub = False

    def lock(self):
        self.__lock.acquire()

    def unlock(self):
        self.__lock.release()

    def start(self):
        pass

    def stop(self):
        self.__topic = ""
        self.__progress = (0, 0, {})
        self.__lastshown = None
        self.__done = False
        self.__subtopic.clear()
        self.__subprogress.clear()
        self.__sublastshown.clear()
        self.__subdone.clear()
        self.__lasttime = 0
        self.__hassub = False

    def setHasSub(self, flag):
        self.__hassub = flag

    def getHasSub(self):
        return self.__hassub

    def getSubCount(self):
        return len(self.__subprogress)

    def show(self):
        now = time.time()
        if self.__lasttime > now-INTERVAL:
            return
        self.__lock.acquire()
        try:
            self.__lasttime = now
            current, total, data = self.__progress
            subexpose = []
            for subkey in self.__subprogress.keys():
                sub = self.__subprogress[subkey]
                subcurrent, subtotal, fragment, subdata = sub
                subpercent = int(100*float(subcurrent)/(subtotal or 1))
                if fragment:
                    current += int(fragment*float(subpercent)/100)
                subtopic = self.__subtopic.get(subkey)
                if (subkey not in self.__subdone and
                    sub == self.__sublastshown.get(subkey)):
                    continue
                self.__sublastshown[subkey] = sub
                subdone = False
                if subpercent == 100:
                    self.__subdone[subkey] = True
                    subdone = True
                    if fragment:
                        _current, _total, _data = self.__progress
                        self.__progress = (_current+fragment, _total, _data)
                        if _current == _total:
                            self.__lasttime = 0
                elif subkey in self.__subdone:
                    subdone = subkey in self.__subdone
                subexpose.append((subkey, subtopic, subpercent,
                                  subdata, subdone))
            topic = self.__topic
            percent = int(100*float(current)/(total or 1))
            if subexpose:
                for info in subexpose:
                    self.expose(topic, percent, *info)
                    if info[-1]:
                        subkey = info[0]
                        del self.__subprogress[subkey]
                        del self.__sublastshown[subkey]
                        del self.__subtopic[subkey]
                if percent == 100 and len(self.__subprogress) == 0:
                    self.__done = True
                self.expose(topic, percent, None, None, None, data,
                            self.__done)
            elif (topic, percent) != self.__lastshown:
                if percent == 100 and len(self.__subprogress) == 0:
                    self.__done = True
                self.expose(topic, percent, None, None, None, data,
                            self.__done)
        finally:
            self.__lock.release()

    def expose(self, topic, percent, subkey, subtopic, subpercent, data, done):
        pass

    def setTopic(self, topic):
        self.__topic = topic

    def get(self):
        return self.__progress

    def set(self, current, total, data={}):
        self.__lock.acquire()
        try:
            if self.__done:
                return
            if current > total:
                current = total
            self.__progress = (current, total, data)
            if current == total:
                self.__lasttime = 0
        finally:
            self.__lock.release()

    def add(self, value):
        self.__lock.acquire()
        try:
            if self.__done:
                return
            current, total, data = self.__progress
            current += value
            if current > total:
                current = total
            self.__progress = (current, total, data)
            if current == total:
                self.__lasttime = 0
        finally:
            self.__lock.release()

    def addTotal(self, value):
        self.__lock.acquire()
        try:
            if self.__done:
                return
            current, total, data = self.__progress
            self.__progress = (current, total+value, data)
        finally:
            self.__lock.release()

    def setSubTopic(self, subkey, subtopic):
        self.__lock.acquire()
        try:
            if subkey not in self.__subtopic:
                self.__lasttime = 0
            self.__subtopic[subkey] = subtopic
        finally:
            self.__lock.release()

    def getSub(self, subkey):
        return self.__subprogress.get(subkey)

    def getSubData(self, subkey, _none=[None]):
        return self.__subprogress.get(subkey, _none)[-1]

    def setSub(self, subkey, subcurrent, subtotal, fragment=0, subdata={}):
        self.__lock.acquire()
        try:
            if self.__done or subkey in self.__subdone:
                return
            if subkey not in self.__subtopic:
                self.__subtopic[subkey] = ""
                self.__lasttime = 0
            if subcurrent > subtotal:
                subcurrent = subtotal
            if subcurrent == subtotal:
                self.__lasttime = 0
            self.__subprogress[subkey] = (subcurrent, subtotal,
                                          fragment, subdata)
        finally:
            self.__lock.release()

    def addSub(self, subkey, value):
        self.__lock.acquire()
        try:
            if self.__done or subkey in self.__subdone:
                return
            (subcurrent, subtotal,
             fragment, subdata) = self.__subprogress[subkey]
            subcurrent += value
            if subcurrent > subtotal:
                subcurrent = subtotal
            self.__subprogress[subkey] = (subcurrent, subtotal,
                                          fragment, subdata)
            if subcurrent == subtotal:
                self.__lasttime = 0
        finally:
            self.__lock.release()

    def addSubTotal(self, subkey, value):
        self.__lock.acquire()
        try:
            if self.__done or subkey in self.__subdone:
                return
            (subcurrent, subtotal,
             fragment, subdata) = self.__subprogress[subkey]
            self.__subprogress[subkey] = (subcurrent, subtotal+value,
                                          fragment, subdata)
        finally:
            self.__lock.release()

    def setDone(self):
        self.__lock.acquire()
        try:
            current, total, data = self.__progress
            self.__progress = (total, total, data)
            self.__lasttime = 0
        finally:
            self.__lock.release()

    def setSubDone(self, subkey):
        self.__lock.acquire()
        try:
            if subkey in self.__subdone:
                return
            (subcurrent, subtotal,
             fragment, subdata) = self.__subprogress[subkey]
            if subcurrent != subtotal:
                self.__subprogress[subkey] = (subtotal, subtotal,
                                              fragment, subdata)
            self.__lasttime = 0
        finally:
            self.__lock.release()

    def setStopped(self):
        self.__lock.acquire()
        self.__done = True
        self.__lasttime = 0
        self.__lock.release()

    def setSubStopped(self, subkey):
        self.__lock.acquire()
        self.__subdone[subkey] = True
        self.__lasttime = 0
        self.__lock.release()

    def resetSub(self, subkey):
        self.__lock.acquire()
        try:
            if subkey in self.__subdone:
                del self.__subdone[subkey]
            if subkey in self.__subprogress:
                (subcurrent, subtotal,
                 fragment, subdata) = self.__subprogress[subkey]
                self.__subprogress[subkey] = (0, subtotal, fragment, {})
            self.__lasttime = 0
        finally:
            self.__lock.release()

# vim:ts=4:sw=4:et