Simplified rpi detection
This commit is contained in:
parent
e9d203ae7b
commit
af655d20ee
1 changed files with 3 additions and 35 deletions
|
|
@ -1,7 +1,7 @@
|
||||||
from openflexure_microscope.api.views import MicroscopeView
|
from openflexure_microscope.api.views import MicroscopeView
|
||||||
|
|
||||||
import subprocess
|
import subprocess
|
||||||
import io
|
import os
|
||||||
from sys import platform
|
from sys import platform
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -9,41 +9,9 @@ def is_raspberrypi(raise_on_errors=False):
|
||||||
"""
|
"""
|
||||||
Checks if Raspberry Pi.
|
Checks if Raspberry Pi.
|
||||||
"""
|
"""
|
||||||
try:
|
# I mean, if it works, it works...
|
||||||
with io.open('/proc/cpuinfo', 'r') as cpuinfo:
|
return os.path.exists("/usr/bin/raspi-config")
|
||||||
found = False
|
|
||||||
for line in cpuinfo:
|
|
||||||
if line.startswith('Hardware'):
|
|
||||||
found = True
|
|
||||||
label, value = line.strip().split(':', 1)
|
|
||||||
value = value.strip()
|
|
||||||
if value not in (
|
|
||||||
'BCM2708',
|
|
||||||
'BCM2709',
|
|
||||||
'BCM2835',
|
|
||||||
'BCM2836'
|
|
||||||
):
|
|
||||||
if raise_on_errors:
|
|
||||||
raise ValueError(
|
|
||||||
'This system does not appear to be a '
|
|
||||||
'Raspberry Pi.'
|
|
||||||
)
|
|
||||||
else:
|
|
||||||
return False
|
|
||||||
if not found:
|
|
||||||
if raise_on_errors:
|
|
||||||
raise ValueError(
|
|
||||||
'Unable to determine if this system is a Raspberry Pi.'
|
|
||||||
)
|
|
||||||
else:
|
|
||||||
return False
|
|
||||||
except IOError:
|
|
||||||
if raise_on_errors:
|
|
||||||
raise ValueError('Unable to open `/proc/cpuinfo`.')
|
|
||||||
else:
|
|
||||||
return False
|
|
||||||
|
|
||||||
return True
|
|
||||||
|
|
||||||
class ShutdownAPI(MicroscopeView):
|
class ShutdownAPI(MicroscopeView):
|
||||||
"""
|
"""
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue