kopia lustrzana https://github.com/jbruce12000/kiln-controller
basic overwrite check, still buggy
rodzic
774d09ef3f
commit
d84af06c36
|
@ -78,8 +78,15 @@ def handle_storage():
|
|||
elif msgdict.get("cmd") == "PUT":
|
||||
log.info("PUT command received")
|
||||
profile_obj = msgdict.get('profile')
|
||||
force = msgdict.get('force',False)
|
||||
if profile_obj:
|
||||
save_profile(profile_obj)
|
||||
#del msgdict["cmd"]
|
||||
if save_profile(profile_obj,force):
|
||||
msgdict["resp"]="OK"
|
||||
else:
|
||||
msgdict["resp"]="FAIL"
|
||||
print "sending:" +str(msgdict)
|
||||
wsock.send(json.dumps(msgdict))
|
||||
except WebSocketError:
|
||||
break
|
||||
log.info("websocket (storage) closed")
|
||||
|
@ -111,14 +118,19 @@ def get_profiles():
|
|||
profiles.append(json.load(f))
|
||||
return json.dumps(profiles)
|
||||
|
||||
def save_profile(profile):
|
||||
def save_profile(profile, force=False):
|
||||
profile_json = json.dumps(profile)
|
||||
filename = profile['name']+".json"
|
||||
filepath = os.path.join(profile_path,filename)
|
||||
if not force and os.path.exists(filepath):
|
||||
print "Didnt write"
|
||||
return False
|
||||
with open(filepath, 'w+') as f:
|
||||
print filepath
|
||||
f.write(profile_json)
|
||||
f.close()
|
||||
print "Did write"
|
||||
return True
|
||||
|
||||
def main():
|
||||
ip = "0.0.0.0"
|
||||
|
|
|
@ -150,8 +150,8 @@ function enterEditMode() {
|
|||
graph.series[0].options.draggableX=true;
|
||||
graph.series[0].options.draggableY=true;
|
||||
graph.render();
|
||||
}
|
||||
|
||||
}
|
||||
function leaveEditMode() {
|
||||
state="IDLE";
|
||||
$('#saveas').hide();
|
||||
|
@ -240,11 +240,31 @@ ws_storage.onopen = function()
|
|||
ws_storage.onmessage = function(e)
|
||||
{
|
||||
console.log('Storage MSG:' + e.data);
|
||||
|
||||
message = JSON.parse(e.data);
|
||||
|
||||
profiles = JSON.parse(e.data);
|
||||
|
||||
console.log("Parsed profile:" + profiles);
|
||||
|
||||
console.log("Parsed message:" + message);
|
||||
|
||||
if(message.resp)
|
||||
{
|
||||
console.log("RESP");
|
||||
if(message.resp == "FAIL")
|
||||
{
|
||||
console.log("FAIL");
|
||||
if (confirm('Overwrite?')) {
|
||||
//message.cmd="PUT";
|
||||
message.force=true;
|
||||
console.log("Sending: " + JSON.stringify(message));
|
||||
ws_storage.send(JSON.stringify(message));
|
||||
} else {
|
||||
ws_storage.send("GET");
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
//the message is an array of profiles
|
||||
//FIXME: this should be better, maybe a {"profiles": ...} container?
|
||||
profiles = message;
|
||||
//delete old options in select
|
||||
$('#e2')
|
||||
.find('option')
|
||||
|
|
Ładowanie…
Reference in New Issue