minor fixes

This commit is contained in:
p.loedige 2021-01-02 21:34:48 +01:00
parent 0bf7191739
commit eb8ce9ee87

13
app.py
View File

@ -25,11 +25,11 @@ def api_root():
}
@app.route('/XML/', methods=["GET","POST"])
def xml_transfer():
def xml_transfer(self):
try:
#return the current config.xml
if request.method == "GET":
return send_from_directory('XML','config.xml')
return send_from_directory(str(dir + 'XML'), 'config.xml')
# set a new config.xml
if request.method == "POST":
@ -40,9 +40,10 @@ def xml_transfer():
tmp_file.write(data)
tmp_file.close()
#check config.xml against the XSD file
if xml_reader.validate('/tmp/aped_device/config.xml','XML/config.xsd'):
shutil.move('XML/config.xml','XML/config_old.xml')
shutil.move('/tmp/aped_device/config.xml','XML/config.xml')
if xml_reader.validate('/tmp/aped_device/config.xml',str(dir + 'XML/config.xsd')):
shutil.move(str(dir + 'XML/config.xml'),str(dir + 'XML/config_old.xml'))
shutil.move('/tmp/aped_device/config.xml',str(dir + 'XML/config.xml'))
self.interface_handler = Interface_handler(self.xml_reader)
else:
SyntaxError('the config.xml has invalid content')
return {'error': ''}
@ -54,7 +55,7 @@ def api_leds_control(device_name):
try:
if request.method == "POST":
response = interface_handler.write(device_name,request.data.get("output"))
return {'output': response}
return {'output': str(response)}
return {'state': interface_handler.read(device_name)}
except Exception as e:
return {'error': str(e)}