Use LabThings decorators
This commit is contained in:
parent
3f25959150
commit
39866626dc
1 changed files with 10 additions and 7 deletions
|
|
@ -3,6 +3,11 @@ import subprocess
|
||||||
import os
|
import os
|
||||||
from sys import platform
|
from sys import platform
|
||||||
|
|
||||||
|
from openflexure_microscope.common.flask_labthings.decorators import (
|
||||||
|
ThingAction,
|
||||||
|
doc_response,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
def is_raspberrypi(raise_on_errors=False):
|
def is_raspberrypi(raise_on_errors=False):
|
||||||
"""
|
"""
|
||||||
|
|
@ -12,34 +17,32 @@ def is_raspberrypi(raise_on_errors=False):
|
||||||
return os.path.exists("/usr/bin/raspi-config")
|
return os.path.exists("/usr/bin/raspi-config")
|
||||||
|
|
||||||
|
|
||||||
|
@ThingAction
|
||||||
class ShutdownAPI(Resource):
|
class ShutdownAPI(Resource):
|
||||||
"""
|
"""
|
||||||
Attempt to shutdown the device
|
Attempt to shutdown the device
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
@doc_response(201)
|
||||||
def post(self):
|
def post(self):
|
||||||
"""
|
"""
|
||||||
Attempt to shutdown the device
|
Attempt to shutdown the device
|
||||||
|
|
||||||
.. :quickref: Actions; Shutdown
|
|
||||||
|
|
||||||
"""
|
"""
|
||||||
subprocess.Popen(["sudo", "shutdown", "-h", "now"])
|
subprocess.Popen(["sudo", "shutdown", "-h", "now"])
|
||||||
|
|
||||||
return "{}", 201
|
return "{}", 201
|
||||||
|
|
||||||
|
|
||||||
|
@ThingAction
|
||||||
class RebootAPI(Resource):
|
class RebootAPI(Resource):
|
||||||
"""
|
"""
|
||||||
Attempt to reboot the device
|
Attempt to reboot the device
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
@doc_response(201)
|
||||||
def post(self):
|
def post(self):
|
||||||
"""
|
"""
|
||||||
Attempt to shutdown the device
|
Attempt to reboot the device
|
||||||
|
|
||||||
.. :quickref: Actions; Shutdown
|
|
||||||
|
|
||||||
"""
|
"""
|
||||||
subprocess.Popen(["sudo", "shutdown", "-r", "now"])
|
subprocess.Popen(["sudo", "shutdown", "-r", "now"])
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue