diff --git a/bin/weewx/station.py b/bin/weewx/station.py index 85e7843c..867119e9 100644 --- a/bin/weewx/station.py +++ b/bin/weewx/station.py @@ -4,21 +4,10 @@ # See the file LICENSE.txt for your full rights. # """Defines (mostly static) information about a station.""" - import time + import weeutil.weeutil import weewx.units -import os - -# For FreeBSD -import ctypes -from ctypes.util import find_library - -# For MacOS: -try: - from Quartz.QuartzCore import CACurrentMediaTime -except ImportError: - pass class StationInfo(object): """Readonly class with static station information. It has no formatting information. Just a POS. @@ -108,25 +97,28 @@ class Station(object): # Get the OS uptime. Because this is highly operating system dependent, several # different strategies may have to be tried: os_uptime_secs = None - try: # For Linux: os_uptime_secs = float(open("/proc/uptime").read().split()[0]) except (IOError, KeyError): try: - #for FreeBSD - libc = ctypes.CDLL(find_library('c')) - size = ctypes.c_size_t() - buf = ctypes.c_int() - size.value = ctypes.sizeof(buf) - libc.sysctlbyname("kern.boottime", ctypes.byref(buf), ctypes.byref(size), None, 0) - os_uptime_secs = time.time() - float(buf.value) - except (IOError, NameError): - try: # For MacOs: - os_uptime_secs = CACurrentMediaTime() - except NameError: - pass + from Quartz.QuartzCore import CACurrentMediaTime + os_uptime_secs = CACurrentMediaTime() + except ImportError: + try: + #for FreeBSD + import ctypes + from ctypes.util import find_library + + libc = ctypes.CDLL(find_library('c')) + size = ctypes.c_size_t() + buf = ctypes.c_int() + size.value = ctypes.sizeof(buf) + libc.sysctlbyname("kern.boottime", ctypes.byref(buf), ctypes.byref(size), None, 0) + os_uptime_secs = time.time() - float(buf.value) + except (IOError, NameError): + pass return weewx.units.ValueHelper(value_t=(os_uptime_secs, "second", "group_deltatime"), formatter=self.formatter, diff --git a/docs/changes.txt b/docs/changes.txt index caa9045f..a514cf61 100644 --- a/docs/changes.txt +++ b/docs/changes.txt @@ -49,6 +49,9 @@ Moved examples out of bin directory. Eliminated experimental directory. Reinforce the use of user directory, eliminate use of examples directory. Renamed xsearch.py to stats.py. +OS uptime now works for freeBSD. Thanks to user Bill Richter! +PR #188. + 3.6.2 11/08/2016