enabled xml file import
This commit is contained in:
parent
09d2b4b008
commit
c334e92f1b
2
XML
2
XML
@ -1 +1 @@
|
||||
Subproject commit 3d9feeec42ad009a0c1e998330f96b6fe4646924
|
||||
Subproject commit 143a75cdf0d5376f5753862c7bbe0e06a3bbb062
|
18
app.py
18
app.py
@ -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)}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user