summaryrefslogtreecommitdiff
path: root/scripts
diff options
context:
space:
mode:
authorteor (Tim Wilson-Brown) <teor2345@gmail.com>2016-06-22 11:04:54 +1000
committerteor (Tim Wilson-Brown) <teor2345@gmail.com>2016-06-22 11:56:31 +1000
commit40906122469e3be5421778ceded665fde40868d9 (patch)
treeab9935bf0b37c815216530cfc493cd0063f8b5d6 /scripts
parent6ce53668f4d043fbc4662ac381823adea8d0ab24 (diff)
downloadtor-40906122469e3be5421778ceded665fde40868d9.tar.gz
tor-40906122469e3be5421778ceded665fde40868d9.zip
Avoid errors in updateFallbackDirs.py when there are no fallbacks
Diffstat (limited to 'scripts')
-rwxr-xr-xscripts/maint/updateFallbackDirs.py12
1 files changed, 10 insertions, 2 deletions
diff --git a/scripts/maint/updateFallbackDirs.py b/scripts/maint/updateFallbackDirs.py
index 7fcb3658c4..d17e702b6f 100755
--- a/scripts/maint/updateFallbackDirs.py
+++ b/scripts/maint/updateFallbackDirs.py
@@ -1408,7 +1408,11 @@ class CandidateList(dict):
def calculate_measured_bandwidth(self):
self.sort_fallbacks_by_cw_to_bw_factor()
median_fallback = self.fallback_median(True)
- median_cw_to_bw_factor = median_fallback.cw_to_bw_factor()
+ if median_fallback is not None:
+ median_cw_to_bw_factor = median_fallback.cw_to_bw_factor()
+ else:
+ # this will never be used, because there are no fallbacks
+ median_cw_to_bw_factor = None
for f in self.fallbacks:
f.set_measured_bandwidth(median_cw_to_bw_factor)
@@ -1593,7 +1597,11 @@ class CandidateList(dict):
# return a string that describes a/b as a percentage
@staticmethod
def describe_percentage(a, b):
- return '%d/%d = %.0f%%'%(a, b, (a*100.0)/b)
+ if b != 0:
+ return '%d/%d = %.0f%%'%(a, b, (a*100.0)/b)
+ else:
+ # technically, 0/0 is undefined, but 0.0% is a sensible result
+ return '%d/%d = %.0f%%'%(a, b, 0.0)
# return a dictionary of lists of fallbacks by IPv4 netblock
# the dictionary is keyed by the fingerprint of an arbitrary fallback