gpsd-05-fix-leapsecond-script-python2.5.patch 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. the json module was added with python2.6, so a regular python 2.5
  2. machine will lack this module and won't probably have the simplejson
  3. module imported by the leapsecond.py script.
  4. Since the only function used is the isotime function, which is
  5. self-contained and quite trivial, only copy this function into the
  6. leapsecond script to avoid the import of the gps.misc module, which
  7. needs simplejson.
  8. Signed-off-by: Maxime Ripard <maxime.ripard@free-electrons.com>
  9. ---
  10. leapsecond.py | 27 ++++++++++++++++++++++++---
  11. 1 file changed, 24 insertions(+), 3 deletions(-)
  12. diff --git a/leapsecond.py b/leapsecond.py
  13. index 2059f6c..cdacdb4 100755
  14. --- a/leapsecond.py
  15. +++ b/leapsecond.py
  16. @@ -24,7 +24,6 @@
  17. # BSD terms apply: see the file COPYING in the distribution root for details.
  18. #
  19. import os, urllib, re, random, time, calendar, math, sys
  20. -import gps.misc
  21. __locations = [
  22. (
  23. @@ -48,6 +47,28 @@ __locations = [
  24. # between times it might change, in seconds since Unix epoch GMT.
  25. __cachepath = "/var/run/leapsecond"
  26. +def isotime(s):
  27. + "Convert timestamps in ISO8661 format to and from Unix time."
  28. + if type(s) == type(1):
  29. + return time.strftime("%Y-%m-%dT%H:%M:%S", time.gmtime(s))
  30. + elif type(s) == type(1.0):
  31. + date = int(s)
  32. + msec = s - date
  33. + date = time.strftime("%Y-%m-%dT%H:%M:%S", time.gmtime(s))
  34. + return date + "." + repr(msec)[3:]
  35. + elif type(s) == type("") or type(s) == type(u""):
  36. + if s[-1] == "Z":
  37. + s = s[:-1]
  38. + if "." in s:
  39. + (date, msec) = s.split(".")
  40. + else:
  41. + date = s
  42. + msec = "0"
  43. + # Note: no leap-second correction!
  44. + return calendar.timegm(time.strptime(date, "%Y-%m-%dT%H:%M:%S")) + float("0." + msec)
  45. + else:
  46. + raise TypeError
  47. +
  48. def retrieve():
  49. "Retrieve current leap-second from Web sources."
  50. random.shuffle(__locations) # To spread the load
  51. @@ -261,10 +282,10 @@ if __name__ == '__main__':
  52. print unix_to_rfc822(float(val))
  53. raise SystemExit, 0
  54. elif (switch == '-I'): # Compute Unix time from ISO8601 date
  55. - print gps.misc.isotime(val)
  56. + print isotime(val)
  57. raise SystemExit, 0
  58. elif (switch == '-O'): # Compute ISO8601 date from Unix time
  59. - print gps.misc.isotime(float(val))
  60. + print isotime(float(val))
  61. raise SystemExit, 0
  62. print "Current leap second:", retrieve()
  63. --
  64. 1.7.9.5