bzr branch
http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
5195.3.31
by Parth Malwankar
close review comments from jam. |
1 |
# Copyright (C) 2010 Canonical Ltd
|
5195.3.17
by Parth Malwankar
remote push now shows estimated work. |
2 |
#
|
3 |
# This program is free software; you can redistribute it and/or modify
|
|
4 |
# it under the terms of the GNU General Public License as published by
|
|
5 |
# the Free Software Foundation; either version 2 of the License, or
|
|
6 |
# (at your option) any later version.
|
|
7 |
#
|
|
8 |
# This program is distributed in the hope that it will be useful,
|
|
9 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
10 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
11 |
# GNU General Public License for more details.
|
|
12 |
#
|
|
13 |
# You should have received a copy of the GNU General Public License
|
|
14 |
# along with this program; if not, write to the Free Software
|
|
15 |
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
|
6379.6.3
by Jelmer Vernooij
Use absolute_import. |
16 |
|
6379.6.7
by Jelmer Vernooij
Move importing from future until after doc string, otherwise the doc string will disappear. |
17 |
"""Record counting support for showing progress of revision fetch."""
|
18 |
||
5195.3.31
by Parth Malwankar
close review comments from jam. |
19 |
|
5195.3.17
by Parth Malwankar
remote push now shows estimated work. |
20 |
class RecordCounter(object): |
5195.3.21
by Parth Malwankar
Documentation and cleanup for RecordCounter |
21 |
"""Container for maintains estimates of work requires for fetch. |
22 |
||
23 |
Instance of this class is used along with a progress bar to provide
|
|
24 |
the user an estimate of the amount of work pending for a fetch (push,
|
|
25 |
pull, branch, checkout) operation.
|
|
26 |
"""
|
|
7143.15.2
by Jelmer Vernooij
Run autopep8. |
27 |
|
5195.3.17
by Parth Malwankar
remote push now shows estimated work. |
28 |
def __init__(self): |
29 |
self.initialized = False |
|
30 |
self.current = 0 |
|
31 |
self.key_count = 0 |
|
32 |
self.max = 0 |
|
5195.3.33
by Parth Malwankar
added comments on choice of STEP value and estimate multiplies |
33 |
|
34 |
# Users of RecordCounter instance update progress bar every
|
|
35 |
# _STEP_ records. We choose are reasonably high number to keep
|
|
5289.1.1
by Parth Malwankar
reduced STEP in recordcounter to allow more frequent updates |
36 |
# display updates from being too frequent. This is an odd number
|
5195.3.33
by Parth Malwankar
added comments on choice of STEP value and estimate multiplies |
37 |
# to ensure that the last digit of the records fetched in
|
38 |
# fetches vs estimate ratio changes periodically.
|
|
5289.1.1
by Parth Malwankar
reduced STEP in recordcounter to allow more frequent updates |
39 |
self.STEP = 7 |
5195.3.17
by Parth Malwankar
remote push now shows estimated work. |
40 |
|
41 |
def is_initialized(self): |
|
42 |
return self.initialized |
|
43 |
||
5195.3.21
by Parth Malwankar
Documentation and cleanup for RecordCounter |
44 |
def _estimate_max(self, key_count): |
45 |
"""Estimate the maximum amount of 'inserting stream' work. |
|
46 |
||
47 |
This is just an estimate.
|
|
48 |
"""
|
|
49 |
# Note: The magic number below is based of empirical data
|
|
50 |
# based on 3 seperate projects. Estimatation can probably
|
|
51 |
# be improved but this should work well for most cases.
|
|
5195.3.33
by Parth Malwankar
added comments on choice of STEP value and estimate multiplies |
52 |
# The project used for the estimate (with approx. numbers) were:
|
53 |
# lp:bzr with records_fetched = 7 * revs_required
|
|
54 |
# lp:emacs with records_fetched = 8 * revs_required
|
|
55 |
# bzr-svn checkout of lp:parrot = 10.63 * revs_required
|
|
56 |
# Hence, 10.3 was chosen as for a realistic progress bar as:
|
|
57 |
# 1. If records fetched is is lower than 10.3x then we simply complete
|
|
58 |
# with 10.3x. Under promise, over deliver.
|
|
59 |
# 2. In case of remote fetch, when we start the count fetch vs estimate
|
|
60 |
# display with revs_required/estimate, having a multiplier with a
|
|
61 |
# decimal point produces a realistic looking _estimate_ number rather
|
|
62 |
# than using something like 3125/31250 (for 10x)
|
|
63 |
# 3. Based on the above data, the possibility of overshooting this
|
|
64 |
# factor is minimal, and in case of an overshoot the estimate value
|
|
65 |
# should not need to be corrected too many times.
|
|
5195.3.21
by Parth Malwankar
Documentation and cleanup for RecordCounter |
66 |
return int(key_count * 10.3) |
67 |
||
5195.3.24
by Parth Malwankar
progress indicator for local branch. |
68 |
def setup(self, key_count, current=0): |
5195.3.21
by Parth Malwankar
Documentation and cleanup for RecordCounter |
69 |
"""Setup RecordCounter with basic estimate of work pending. |
70 |
||
71 |
Setup self.max and self.current to reflect the amount of work
|
|
72 |
pending for a fetch.
|
|
73 |
"""
|
|
5195.3.17
by Parth Malwankar
remote push now shows estimated work. |
74 |
self.current = current |
75 |
self.key_count = key_count |
|
5195.3.21
by Parth Malwankar
Documentation and cleanup for RecordCounter |
76 |
self.max = self._estimate_max(key_count) |
5195.3.17
by Parth Malwankar
remote push now shows estimated work. |
77 |
self.initialized = True |
78 |
||
79 |
def increment(self, count): |
|
5195.3.21
by Parth Malwankar
Documentation and cleanup for RecordCounter |
80 |
"""Increment self.current by count. |
81 |
||
82 |
Apart from incrementing self.current by count, also ensure
|
|
83 |
that self.max > self.current.
|
|
84 |
"""
|
|
5195.3.17
by Parth Malwankar
remote push now shows estimated work. |
85 |
self.current += count |
86 |
if self.current > self.max: |
|
87 |
self.max += self.key_count |