openflexure-microscope-server/openflexure_microscope/api/v2/blueprints/actions/system.py

45 lines
844 B
Python

from openflexure_microscope.api.views import MicroscopeView
import subprocess
import os
from sys import platform
def is_raspberrypi():
if (platform != "linux"):
return False
else:
return (os.uname()[1] == 'raspberrypi')
class ShutdownAPI(MicroscopeView):
"""
Attempt to shutdown the device
"""
def post(self):
"""
Attempt to shutdown the device
.. :quickref: Actions; Shutdown
"""
subprocess.Popen(["sudo", "shutdown", "-h", "now"])
return "{}", 201
class RebootAPI(MicroscopeView):
"""
Attempt to reboot the device
"""
def post(self):
"""
Attempt to shutdown the device
.. :quickref: Actions; Shutdown
"""
subprocess.Popen(["sudo", "shutdown", "-r", "now"])
return "{}", 201