dweet fix again

This commit is contained in:
Senad Uka
2016-06-08 10:01:55 +02:00
parent e0e0f0d24c
commit 533135013b
49 changed files with 2885 additions and 2 deletions

View File

@@ -0,0 +1,39 @@
import config
from state.server import Server
from state.changer import Changer
from state.file import File
import commands
def safely_panic():
safe_state = {}
changer = Changer(safe_state,safe_state)
changer.stop_everything()
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)
print " everything ok, canceling shutdown "
commands.getoutput('/sbin/shutdown -c')
except:
print " panicking safely ! "
safely_panic()
print " rebooting "
commands.getoutput('/sbin/shutdown -r +3')