summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEric S. Raymond <esr@thyrsus.com>2013-11-27 05:36:49 -0500
committerEric S. Raymond <esr@thyrsus.com>2013-11-27 05:38:26 -0500
commitfb10304635cfb71b6b8186792e973a169bbc80f2 (patch)
treedaa090663632d99e2a974b51dca84665ab1ef49f
parent04ce3b99cc51d7febbbfd51c08f2364a4ca71a4d (diff)
downloadgpsd-fb10304635cfb71b6b8186792e973a169bbc80f2.tar.gz
Refactor leap-second cache fetching. No logic changes yet.
-rw-r--r--SConstruct29
-rwxr-xr-xleapsecond.py23
-rw-r--r--leapseconds.cache34
3 files changed, 44 insertions, 42 deletions
diff --git a/SConstruct b/SConstruct
index 66944f8d..6983b625 100644
--- a/SConstruct
+++ b/SConstruct
@@ -67,7 +67,7 @@ tipwidget = "<script data-gittip-username='esr' \
EnsureSConsVersion(2,0,1)
-import copy, os, sys, glob, re, platform, time, signal
+import copy, os, sys, glob, re, platform, time
from distutils import sysconfig
from distutils.util import get_platform
import SCons
@@ -1151,32 +1151,13 @@ generated_sources = ['packet_names.h', 'timebase.h', 'gpsd.h', "ais_json.i",
# leapseconds.cache is a local cache for information on leapseconds issued
# by the U.S. Naval observatory. It gets kept in the repository so we can
# build without Internet access.
-from leapsecond import save_leapseconds
+from leapsecond import conditional_leapsecond_fetch
-def timed_save_leapseconds(outfile, env, timeout=15):
- "Fetch leapsecond data with timeout, in case outside web access is blocked."
+def leapseconds_cache_rebuild(target, source, env):
if not env["leapfetch"]:
sys.stdout.write("Leapsecond fetch suppressed by leapfetch=no.\n")
- 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; try building with leapfetch=no.\n")
- return
- 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; try building with leapfetch=no.\n")
- signal.alarm(0)
-
-def leapseconds_cache_rebuild(target, source, env):
- timed_save_leapseconds(target[0].abspath, env)
+ elif not conditional_leapsecond_fetch(target[0].abspath, timeout=15):
+ sys.stdout.write("try building with leapfetch=no.\n")
if 'dev' in gpsd_version or not os.path.exists('leapseconds.cache'):
leapseconds_cache = env.Command(target="leapseconds.cache",
source="leapsecond.py",
diff --git a/leapsecond.py b/leapsecond.py
index de24d1a3..87396ddc 100755
--- a/leapsecond.py
+++ b/leapsecond.py
@@ -50,7 +50,7 @@ BSD terms apply: see the file COPYING in the distribution root for details.
"""
-import os, urllib, re, random, time, calendar, math, sys
+import os, urllib, re, random, time, calendar, math, sys, signal
# Set a socket timeout for slow servers
import socket
@@ -253,6 +253,27 @@ def make_leapsecond_include(infile):
#define GPS_WEEK_NOW\t%(gps_week_now)d
""" % 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
+
def leastsquares(tuples):
"Generate coefficients for a least-squares fit to the specified data."
sum_x=0
diff --git a/leapseconds.cache b/leapseconds.cache
index f7f9f490..e95dca38 100644
--- a/leapseconds.cache
+++ b/leapseconds.cache
@@ -1,17 +1,17 @@
-315532800 # ('1979-12-31T23:59:60')
-362793599 # ('1981-06-30T23:59:59')
-394329599 # ('1982-06-30T23:59:59')
-425865599 # ('1983-06-30T23:59:59')
-489023999 # ('1985-06-30T23:59:59')
-567993600 # ('1987-12-31T23:59:60')
-631152000 # ('1989-12-31T23:59:60')
-662688000 # ('1990-12-31T23:59:60')
-709948799 # ('1992-06-30T23:59:59')
-741484799 # ('1993-06-30T23:59:59')
-773020799 # ('1994-06-30T23:59:59')
-820454400 # ('1995-12-31T23:59:60')
-867715199 # ('1997-06-30T23:59:59')
-915148800 # ('1998-12-31T23:59:60')
-1136073600 # ('2005-12-31T23:59:60')
-1230768000 # ('2008-12-31T23:59:60')
-1341100799 # ('2012-06-30T23:59:59')
+315532800 # 1979-12-31T23:59:60
+362793599 # 1981-06-30T23:59:59
+394329599 # 1982-06-30T23:59:59
+425865599 # 1983-06-30T23:59:59
+489023999 # 1985-06-30T23:59:59
+567993600 # 1987-12-31T23:59:60
+631152000 # 1989-12-31T23:59:60
+662688000 # 1990-12-31T23:59:60
+709948799 # 1992-06-30T23:59:59
+741484799 # 1993-06-30T23:59:59
+773020799 # 1994-06-30T23:59:59
+820454400 # 1995-12-31T23:59:60
+867715199 # 1997-06-30T23:59:59
+915148800 # 1998-12-31T23:59:60
+1136073600 # 2005-12-31T23:59:60
+1230768000 # 2008-12-31T23:59:60
+1341100799 # 2012-06-30T23:59:59