summaryrefslogtreecommitdiff
path: root/leapsecond.py
diff options
context:
space:
mode:
authorEric S. Raymond <esr@thyrsus.com>2013-11-27 06:08:56 -0500
committerEric S. Raymond <esr@thyrsus.com>2013-11-27 06:08:56 -0500
commit6b5e9b689223bc197386fcf97c55df417e8d25cc (patch)
treeb6018a218768d42a21a95c6c8bc17edfeff2c783 /leapsecond.py
parent7dc393307bf5a34d07fe48fccd3f38e3ca4a2ca0 (diff)
downloadgpsd-6b5e9b689223bc197386fcf97c55df417e8d25cc.tar.gz
Only fetch leapseconds when cache is older than last potential issue date.
Diffstat (limited to 'leapsecond.py')
-rwxr-xr-xleapsecond.py48
1 files changed, 29 insertions, 19 deletions
diff --git a/leapsecond.py b/leapsecond.py
index 947d8f09..07162bce 100755
--- a/leapsecond.py
+++ b/leapsecond.py
@@ -209,25 +209,35 @@ def make_leapsecond_include(infile):
""" % locals()
def conditional_leapsecond_fetch(outfile, timeout):
- "Fetch leapsecond data, with timeout in case of evil firewalls."
- def handler(signum, frame):
- raise IOError
- try:
- signal.signal(signal.SIGALRM, handler)
- except ValueError:
- # Parallel builds trigger this - signal only works in main thread
- sys.stdout.write("Signal set failed; ")
- return False
- signal.alarm(timeout)
- sys.stdout.write("Attempting leap-second fetch...")
- try:
- save_leapseconds(outfile)
- sys.stdout.write("succeeded.\n")
- except IOError:
- sys.stdout.write("failed; ")
- return False
- signal.alarm(0)
- return True
+ "Conditionally fetch leapsecond data, w. timeout in case of evil firewalls."
+ if not os.path.exists(outfile):
+ stale = True
+ else:
+ # If there can't have been a leapsecond insertion since the
+ # last time the cache was updated, we don't need to refresh.
+ # This test cuts way down on the frequency with which we fetch.
+ stale = last_insertion_time() > os.path.getmtime(outfile)
+ if not stale:
+ return True
+ else:
+ def handler(signum, frame):
+ raise IOError
+ try:
+ signal.signal(signal.SIGALRM, handler)
+ except ValueError:
+ # Parallel builds trigger this - signal only works in main thread
+ sys.stdout.write("Signal set failed; ")
+ return False
+ signal.alarm(timeout)
+ sys.stdout.write("Attempting leap-second fetch...")
+ try:
+ save_leapseconds(outfile)
+ sys.stdout.write("succeeded.\n")
+ except IOError:
+ sys.stdout.write("failed; ")
+ return False
+ signal.alarm(0)
+ return True
def leastsquares(tuples):
"Generate coefficients for a least-squares fit to the specified data."