enabled xml file import

This commit is contained in:
p.loedige
2020-12-31 02:50:56 +01:00
parent 09d2b4b008
commit c334e92f1b
2 changed files with 11 additions and 9 deletions

2
XML

Submodule XML updated: 3d9feeec42...143a75cdf0

18
app.py
View File

@@ -3,6 +3,7 @@
from flask import request, send_from_directory
from flask_api import FlaskAPI
import RPi.GPIO as GPIO
import shutil
import os
from xml_reader import Xml_reader
@@ -31,18 +32,19 @@ def xml_transfer():
# set a new config.xml
if request.method == "POST":
if 'config.xml' not in request.files:
raise ReferenceError("no file part")
file = request.files["config.xml"]
if file.filename != 'config.xml':
raise NameError("the file recieved does not have the filename config.xml")
file.save('/tmp/aped_device/config.xml')
if not os.path.exists('/tmp/aped_device'):
os.mkdir("/tmp/aped_device")
tmp_file = open("/tmp/aped_device/config.xml","w")
data = request.get_data(as_text=True)
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'):
os.replace('XML/config.xml','XML/config_old.xml')
os.replace('/tmp/aped_device/config.xml','XML/config.xml')
shutil.move('XML/config.xml','XML/config_old.xml')
shutil.move('/tmp/aped_device/config.xml','XML/config.xml')
else:
SyntaxError('the config.xml has invalid content')
return {'error': ''}
except Exception as e:
return {'error' : str(e)}