From 04d58e9caceaaa225dbc3b9b355c766dda5c99dc Mon Sep 17 00:00:00 2001 From: "Johann C. Rocholl" Date: Mon, 8 Mar 2010 14:43:25 -0800 Subject: [PATCH] Added constants BISECT_BLOCK_SIZE and BISECT_LIMIT. --- tools/update_dns.py | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/tools/update_dns.py b/tools/update_dns.py index f15e719..52621f0 100755 --- a/tools/update_dns.py +++ b/tools/update_dns.py @@ -35,6 +35,9 @@ logfile.setLevel(logging.WARNING) logging.getLogger().addHandler(logfile) +BISECT_BLOCK_SIZE = 30 +BISECT_LIMIT = BISECT_BLOCK_SIZE / 2 +PASSWORD_FILENAME = '.passwd' NAMESERVERS = """ 208.67.222.222 208.67.220.220 @@ -56,8 +59,6 @@ 205.171.3.65 """.split() -PASSWORD_FILENAME = '.passwd' - def auth_func(): if os.path.exists(PASSWORD_FILENAME): @@ -289,20 +290,26 @@ def count_existing(names): def bisect(names): # Check the end of the list. - if count_existing(names[-20:]) > 5: + count = count_existing(names[-BISECT_BLOCK_SIZE:]) + if count > BISECT_LIMIT: + print "bisect end count=%d" % count return [] # Check the beginning of the list. - if count_existing(names[:20]) <= 5: + count = count_existing(names[:BISECT_BLOCK_SIZE]) + if count <= BISECT_LIMIT: + print "bisect start count=%d" % count return names # Bisect the list to find the crash point. left = 0 right = len(names) - 1 - while right - left > 20: + while right - left > BISECT_BLOCK_SIZE: middle = (left + right) / 2 - count = count_existing(names[middle:middle + 20]) + start = middle - BISECT_BLOCK_SIZE / 2 + stop = start + BISECT_BLOCK_SIZE + count = count_existing(names[start:stop]) print "bisect left=%s right=%s middle=%s count=%d" % ( names[left], names[right], names[middle], count) - if count <= 5: + if count <= BISECT_LIMIT: right = middle else: left = middle