From 02afe066557d3d935b6ffdd22f0b1c12529b94f4 Mon Sep 17 00:00:00 2001 From: jtc42 Date: Wed, 27 Nov 2019 19:24:03 +0000 Subject: [PATCH] Disable shutdown/reboot unless on Raspberry Pi --- .../api/v2/blueprints/actions/__init__.py | 5 ++--- .../api/v2/blueprints/actions/system.py | 8 ++++++++ 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/openflexure_microscope/api/v2/blueprints/actions/__init__.py b/openflexure_microscope/api/v2/blueprints/actions/__init__.py index 32f2c061..fbf376fe 100644 --- a/openflexure_microscope/api/v2/blueprints/actions/__init__.py +++ b/openflexure_microscope/api/v2/blueprints/actions/__init__.py @@ -3,7 +3,6 @@ Top-level representation of enabled actions """ from flask import Blueprint, url_for, jsonify -from sys import platform from openflexure_microscope.api.utilities import blueprint_for_module from openflexure_microscope.utilities import get_docstring, description_from_view @@ -41,12 +40,12 @@ _actions = { "shutdown": { "rule": "/system/shutdown/", "view_class": system.ShutdownAPI, - "conditions": (platform == "linux"), + "conditions": system.is_raspberrypi(), }, "reboot": { "rule": "/system/reboot/", "view_class": system.RebootAPI, - "conditions": (platform == "linux"), + "conditions": system.is_raspberrypi(), }, } diff --git a/openflexure_microscope/api/v2/blueprints/actions/system.py b/openflexure_microscope/api/v2/blueprints/actions/system.py index 950af9fb..f3c9de79 100644 --- a/openflexure_microscope/api/v2/blueprints/actions/system.py +++ b/openflexure_microscope/api/v2/blueprints/actions/system.py @@ -1,8 +1,16 @@ 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