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-01-24 09:15:14 +01:00
|
|
|
|
|
|
|
|
def sync():
|
2016-01-24 09:18:14 +01:00
|
|
|
server = Server(config.API_BASE_URL, config.CONTROLLER_ID)
|
|
|
|
|
local = File(config.STATE_FILE)
|
2016-01-24 09:15:14 +01:00
|
|
|
server_state = server.get_state()
|
|
|
|
|
|
2016-01-24 09:37:02 +01:00
|
|
|
|
|
|
|
|
|
2016-01-24 09:15:14 +01:00
|
|
|
if local.present():
|
|
|
|
|
local.load()
|
2016-01-24 09:40:39 +01:00
|
|
|
print "local present: " + repr(local.data)
|
2016-01-24 09:15:14 +01:00
|
|
|
else:
|
|
|
|
|
local.data = server_state
|
2016-01-24 09:40:39 +01:00
|
|
|
print "local not present, server: " + repr(local.data)
|
2016-01-24 09:15:14 +01:00
|
|
|
local.save()
|
|
|
|
|
|
2016-01-24 09:37:02 +01:00
|
|
|
|
2016-01-24 09:15:14 +01:00
|
|
|
local_state = local.data
|
|
|
|
|
|
2016-01-24 09:25:55 +01:00
|
|
|
changer = Changer(local_state, server_state)
|
2016-01-24 09:15:14 +01:00
|
|
|
current_state = changer.process_change()
|
|
|
|
|
|
|
|
|
|
server.post_state(current_state)
|