diff options
author | Alvaro Neira Ayuso <aneira@soleta.eu> | 2019-12-27 17:59:00 +0100 |
---|---|---|
committer | Alvaro Neira Ayuso <alvaroneay@gmail.com> | 2020-01-19 19:50:44 +0100 |
commit | 59a28237f15ae8760043a08fd4c6fd007e0a6ac7 (patch) | |
tree | 9e6c14f5a3c50904af2c9a4be4785d204b6738c8 /src/ogRest.py | |
parent | d065e1998d4ff5cb5b5b79489032989b98936245 (diff) |
Create ogThread class to move all thread functions
Right now, all the thread functions are declared inside the processor function.
Those functions were created for execute specific commands in the machine
(poweroff, reboot, etc). Creating this new class we are cleaning up the code.
Diffstat (limited to 'src/ogRest.py')
-rw-r--r-- | src/ogRest.py | 33 |
1 files changed, 17 insertions, 16 deletions
diff --git a/src/ogRest.py b/src/ogRest.py index 60a33b0..f470f0b 100644 --- a/src/ogRest.py +++ b/src/ogRest.py @@ -8,6 +8,20 @@ import queue if platform.system() == 'Linux': from src.linux import ogOperations +class ogThread(): + # Executing cmd thread + def execcmd(msgqueue, cmd): + msgqueue.put(ogOperations.execCMD(cmd)) + + # Powering off thread + def pwoff(): + time.sleep(2) + ogOperations.poweroff() + + # Rebooting thread + def rebt(): + ogOperations.reboot() + class ogResponses(Enum): BAD_REQUEST=0 IN_PROGRESS=1 @@ -64,37 +78,24 @@ class ogRest(): return 0 def process_reboot(self, client): - # Rebooting thread - def rebt(): - ogOperations.reboot() - client.send(self.getResponse(ogResponses.IN_PROGRESS)) client.disconnect() - threading.Thread(target=rebt).start() + threading.Thread(target=ogThread.rebt).start() def process_poweroff(self, client): - # Powering off thread - def pwoff(): - time.sleep(2) - ogOperations.poweroff() - client.send(self.getResponse(ogResponses.IN_PROGRESS)) client.disconnect() - threading.Thread(target=pwoff).start() + threading.Thread(target=ogThread.pwoff).start() def process_probe(self, client): client.send(self.getResponse(ogResponses.OK)) def process_shellrun(self, client, cmd): - # Executing cmd thread - def execcmd(msgqueue): - msgqueue.put(ogOperations.execCMD(cmd)) - if cmd == None: client.send(self.getResponse(ogResponses.BAD_REQUEST)) return - threading.Thread(target=execcmd, args=(self.msgqueue,)).start() + threading.Thread(target=ogThread.execcmd, args=(self.msgqueue, cmd,)).start() client.send(self.getResponse(ogResponses.IN_PROGRESS)) def process_shellout(self, client): |