]> git.rkrishnan.org Git - tahoe-lafs/tahoe-lafs.git/blob - src/allmydata/util/progress.py
Flesh out "tahoe magic-folder status" command
[tahoe-lafs/tahoe-lafs.git] / src / allmydata / util / progress.py
1 """
2 Utilities relating to computing progress information.
3
4 Ties in with the "consumer" module also
5 """
6
7 from allmydata.interfaces import IProgress
8 from zope.interface import implementer
9
10
11 @implementer(IProgress)
12 class PercentProgress(object):
13     """
14     Represents progress as a percentage, from 0.0 to 100.0
15     """
16
17     def __init__(self, total_size=None):
18         self._value = 0.0
19         self.set_progress_total(total_size)
20
21     def set_progress(self, value):
22         "IProgress API"
23         self._value = value
24
25     def set_progress_total(self, size):
26         "IProgress API"
27         if size is not None:
28             size = float(size)
29         self._total_size = size
30
31     @property
32     def progress(self):
33         if self._total_size is None:
34             return 0  # or 1.0?
35         if self._total_size <= 0.0:
36             return 0
37         return (self._value / self._total_size) * 100.0