Commit 39866626 authored by Joel Collins's avatar Joel Collins
Browse files

Use LabThings decorators

parent 3f259591
Loading
Loading
Loading
Loading
+10 −7
Original line number Diff line number Diff line
@@ -3,6 +3,11 @@ import subprocess
import os
from sys import platform

from openflexure_microscope.common.flask_labthings.decorators import (
    ThingAction,
    doc_response,
)


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")


@ThingAction
class ShutdownAPI(Resource):
    """
    Attempt to shutdown the device 
    """

    @doc_response(201)
    def post(self):
        """
        Attempt to shutdown the device

        .. :quickref: Actions; Shutdown

        """
        subprocess.Popen(["sudo", "shutdown", "-h", "now"])

        return "{}", 201


@ThingAction
class RebootAPI(Resource):
    """
    Attempt to reboot the device 
    """

    @doc_response(201)
    def post(self):
        """
        Attempt to shutdown the device

        .. :quickref: Actions; Shutdown

        Attempt to reboot the device
        """
        subprocess.Popen(["sudo", "shutdown", "-r", "now"])