-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
61 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,3 +3,4 @@ | |
from .logs import * | ||
from .preferences import * | ||
from .wifi import * | ||
from .system import * |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
from flask import Blueprint, request, jsonify, current_app | ||
from ..services import SystemManager | ||
import logging | ||
|
||
system_bp = Blueprint('system', __name__) | ||
|
||
@system_bp.route('/system/restart', methods=['POST']) | ||
def restart(): | ||
system_manager: SystemManager = current_app.config['system_manager'] | ||
system_manager.restart_system() | ||
return jsonify({}) | ||
|
||
@system_bp.route('/system/restart', methods=['SHUTDOWN']) | ||
def shutdown(): | ||
system_manager: SystemManager = current_app.config['system_manager'] | ||
system_manager.shutdown_system() | ||
return jsonify({}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,3 +2,4 @@ | |
from .lights import * | ||
from .preferences import * | ||
from .wifi import * | ||
from .system import * |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
from .system_manager import * |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import os | ||
import logging | ||
|
||
class SystemManager: | ||
''' | ||
Simple class to manage the restarting and shutting down of the system | ||
''' | ||
|
||
REBOOT_COMMAND = 'reboot now' | ||
SHUTDOWN_COMMAND = 'shutdown now' | ||
|
||
def __init__(self) -> None: | ||
pass | ||
|
||
def restart_system(self): | ||
logging.info('Restarting system') | ||
os.system(self.REBOOT_COMMAND) | ||
|
||
def shutdown_system(self): | ||
logging.info('Shutting down system') | ||
os.system(self.SHUTDOWN_COMMAND) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import { BACKEND_API_URL, postRequest } from "../../utils/utils"; | ||
|
||
export async function restartMachine() { | ||
const url = `${BACKEND_API_URL}/system/restart`; | ||
const response = await postRequest(url); | ||
return await response.json(); | ||
} | ||
|
||
export async function shutdownMachine() { | ||
const url = `${BACKEND_API_URL}/system/shutdown`; | ||
const response = await postRequest(url); | ||
return await response.json(); | ||
} |