Files
old-tfm/controller/state/__init__.py

38 lines
996 B
Python
Raw Normal View History

2016-01-24 09:18:14 +01:00
import config
2016-01-24 09:24:05 +01:00
from state.server import Server
from state.changer import Changer
from state.file import File
2016-06-08 09:16:44 +02:00
import commands
2016-01-24 09:15:14 +01:00
2016-06-08 08:24:43 +02:00
def safely_panic():
safe_state = {}
changer = Changer(safe_state,safe_state)
2016-06-08 08:31:42 +02:00
changer.stop_everything()
2016-01-24 09:15:14 +01:00
2016-01-24 09:37:02 +01:00
2016-06-08 08:24:43 +02:00
def sync():
try:
server = Server(config.API_BASE_URL, config.CONTROLLER_ID)
local = File(config.STATE_FILE)
server_state = server.get_state()
if local.present():
local.load()
print "local present: " + repr(local.data)
else:
local.data = server_state
print "local not present, server: " + repr(local.data)
local.save()
local_state = local.data
changer = Changer(local_state, server_state)
current_state = changer.process_change()
server.post_state(current_state)
except:
2016-06-08 08:31:42 +02:00
print " panicking safely ! "
2016-06-08 08:31:58 +02:00
safely_panic()
2016-06-08 09:16:44 +02:00
print " rebooting "
commands.getoutput('/sbin/shutdown -r now')