powerapi/killswitch.py

22 lines
691 B
Python

import os
import platform
from timber import axe
class KillSwitch:
def __init__(self,DRYRUN=True):
self.dryrun = DRYRUN
if platform.system() == "Windows":
self.shutdown_command = 'shutdown /s /t 1'
else:
self.shutdown_command = 'sudo shutdown now'
def power_down(self):
if self.dryrun is True:
axe.critical('DRYRUN: Power Loss Detected. System Should Shutdown Now!')
else:
try:
axe.critical('Power Loss Detected, Initiating Shutdown!')
os.system(self.shutdown_command)
except Exception as e:
axe.critical(f"An error occurred: {e}")