summaryrefslogtreecommitdiffstats
path: root/src/ogProcess.py
blob: def76f1f6d2e792a8e289d6ccae2e1d51d74c26e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
import threading
import platform
import time
from src import ogRest

if platform.system() == 'Linux':
	from src.linux import ogOperations

class ogProcess():
	def processOperation(self, op, URI, sock):
		if ("poweroff" in URI):
			sock.send(bytes(ogRest.getResponse(ogRest.ogResponses.IN_PROGRESS), 'utf-8'))
			sock.close()
			self.process_poweroff()
			return 0
		elif ("reboot" in URI):
			sock.send(bytes(ogRest.getResponse(ogRest.ogResponses.IN_PROGRESS), 'utf-8'))
			sock.close()
			self.process_reboot()
			return 0
		elif ("probe" in URI):
			sock.send(bytes(ogRest.getResponse(ogRest.ogResponses.OK), 'utf-8'))
		else:
			sock.send(bytes(ogRest.getResponse(ogRest.ogResponses.BAD_REQUEST), 'utf-8'))

		return 1

	def process_reboot(self):
		# Rebooting thread
		def rebt():
			ogOperations.reboot()
		threading.Thread(target=rebt).start()

	def process_poweroff(self):
		# Powering off thread
		def pwoff():
			time.sleep(2)
			ogOperations.poweroff()
		threading.Thread(target=pwoff).start()