Fixed problem on MacOS. Added comment in change file

This commit is contained in:
Tom Keffer
2016-12-14 16:58:50 -08:00
parent e735f3401e
commit 42e403b43b
2 changed files with 20 additions and 25 deletions

View File

@@ -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,

View File

@@ -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