added ability for xml_reader to reload after upload
This commit is contained in:
parent
eb8ce9ee87
commit
3fdf60f866
15
app.py
15
app.py
@ -25,11 +25,11 @@ def api_root():
|
||||
}
|
||||
|
||||
@app.route('/XML/', methods=["GET","POST"])
|
||||
def xml_transfer(self):
|
||||
def xml_transfer():
|
||||
try:
|
||||
#return the current config.xml
|
||||
if request.method == "GET":
|
||||
return send_from_directory(str(dir + 'XML'), 'config.xml')
|
||||
return send_from_directory(str(dir + '/XML'), 'config.xml')
|
||||
|
||||
# set a new config.xml
|
||||
if request.method == "POST":
|
||||
@ -40,10 +40,11 @@ def xml_transfer(self):
|
||||
tmp_file.write(data)
|
||||
tmp_file.close()
|
||||
#check config.xml against the XSD file
|
||||
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)
|
||||
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'))
|
||||
xml_reader.set_root(str(dir + '/XML/config.xml'))
|
||||
interface_handler = Interface_handler(xml_reader)
|
||||
else:
|
||||
SyntaxError('the config.xml has invalid content')
|
||||
return {'error': ''}
|
||||
@ -51,7 +52,7 @@ def xml_transfer(self):
|
||||
return {'error' : str(e)}
|
||||
|
||||
@app.route('/device/<device_name>/', methods=["GET", "POST"])
|
||||
def api_leds_control(device_name):
|
||||
def api_devices(device_name):
|
||||
try:
|
||||
if request.method == "POST":
|
||||
response = interface_handler.write(device_name,request.data.get("output"))
|
||||
|
@ -15,6 +15,9 @@ class Xml_reader:
|
||||
#check the XML for validity using the XSD file
|
||||
if not self.validate(xml_path,xsd_path):
|
||||
raise SyntaxError('the XML config file has an invalid syntax')
|
||||
self.set_root(xml_path)
|
||||
|
||||
def set_root(self, xml_path: str):
|
||||
self.root = etree.parse(xml_path).getroot()
|
||||
|
||||
def validate(self, xml_path: str, xsd_path: str) -> bool:
|
||||
|
Loading…
x
Reference in New Issue
Block a user