@@ -454,16 +454,6 @@ def get_controller_setting_page(request, response):
454454 #Edit controller
455455 _log .debug ("Pages: Edit Controller: " + str (id ))
456456
457- #init ONLY!
458- try :
459- db .protocolTable .create_table ()
460- except OSError :
461- pass
462- try :
463- db .controllerTable .create_table ()
464- except OSError :
465- pass
466-
467457 info = {}
468458 info ['name' ] = _utils .get_upyeasy_name ()
469459 info ['copyright' ]= core .__copyright__
@@ -500,11 +490,6 @@ def get_controller_setting_page(request, response):
500490
501491 _log .debug ("Pages: Delete Controller: " + str (id ))
502492
503- try :
504- db .controllerTable .create_table ()
505- except OSError :
506- pass
507-
508493 # Get correct controller
509494 controllers = db .controllerTable .public ()
510495 for controller in controllers :
@@ -700,7 +685,43 @@ def post_controller_settingpage(request, response):
700685 yield from response .awrite ("Location: /controllers\r \n " )
701686 yield from response .awrite ("Content-Type: text/html\r \n " )
702687 yield from response .awrite ("<html><head><title>Moved</title></head><body><h1>Moved</h1></body></html>\r \n " )
703-
688+
689+ @app .route ("/api/v1.0/controller" , methods = ['DELETE' ])
690+ def del_controller_setting_page (request , response ):
691+ if not auth_page (request , response ):
692+ #send to password page
693+ yield from response .awrite ("HTTP/1.0 301 Moved Permanently\r \n Location: /password\r \n Content-Type: text/html\r \n <html><head><title>Moved</title></head><body><h1>Moved</h1></body></html>\r \n " )
694+ return
695+
696+ #Display controller settings page
697+ _log .debug ("Pages DELETE: Entering Controller Settings Page" )
698+
699+ _log .debug ('Parsed QS: {}' .format (request .qs ))
700+ id = int (request .qs [0 ])
701+ _log .debug ('id = {}' .format (id ))
702+
703+ # delete controller
704+ import os
705+
706+ _log .debug ("Pages: Delete Controller: " + str (id ))
707+
708+ # Get correct controller
709+ controllers = db .controllerTable .public ()
710+ for controller in controllers :
711+ if controller ['id' ] == id :
712+ if db .controllerTable .delete (controller ['timestamp' ]):
713+ _log .debug ("Pages: remove record file succeeded: " + db .controllerTable .fname (controller ['timestamp' ]))
714+ else :
715+ _log .error ("Pages: remove record file failed: " + db .controllerTable .fname (controller ['timestamp' ]))
716+ break
717+
718+ gc .collect ()
719+ #deleted, return to controllers page
720+ yield from response .awrite ("HTTP/1.0 303 Moved Permanently\r \n " )
721+ yield from response .awrite ("Location: /controllers\r \n " )
722+ yield from response .awrite ("Content-Type: text/html\r \n " )
723+ yield from response .awrite ("<html><head><title>Moved</title></head><body><h1>Moved</h1></body></html>\r \n " )
724+
704725@app .route ("/hardware" , methods = ['GET' ])
705726def get_hardware_page (request , response ):
706727 if not auth_page (request , response ):
@@ -1020,55 +1041,6 @@ def get_devicesetting_page(request, response):
10201041 yield from app .render_template (response , "plugin_footer.html" ,(info , plugindata ,))
10211042 yield from app .render_template (response , "footer.html" ,(info ,))
10221043
1023- elif id > 0 and oper == 'del' :
1024- # delete device
1025- import os
1026-
1027- _log .debug ("Pages: Delete Device: " + str (id ))
1028-
1029- try :
1030- db .deviceTable .create_table ()
1031- except OSError :
1032- pass
1033-
1034- # Get correct device
1035- devices = db .deviceTable .public ()
1036- for device in devices :
1037- if device ['id' ] == id :
1038- break
1039-
1040- # Get list of plugins
1041- plugins = db .pluginTable .public ()
1042- for plugin in plugins :
1043- if plugin ['id' ] == device ['pluginid' ]:
1044- break
1045-
1046- if db .deviceTable .delete (device ['timestamp' ]):
1047- _log .debug ("Pages: remove record file succeeded: " + db .deviceTable .fname (device ['timestamp' ]))
1048- else :
1049- _log .error ("Pages: remove record file failed: " + db .deviceTable .fname (device ['timestamp' ]))
1050-
1051- # Get dxpin config
1052- dxpin = db .dxpinTable .getrow ()
1053-
1054- # Convert pin settings
1055- dxpins = device ["dxpin" ].split (';' )
1056- for cnt in range (0 ,plugin ["pincnt" ]):
1057- _log .debug ("Pages: delete plugin, free pin: " + dxpins [cnt ])
1058- dxpin [dxpins [cnt ]] = ''
1059-
1060- # Updated deleted pins
1061- cid = db .dxpinTable .update ({"timestamp" :dxpin ['timestamp' ]},d0 = dxpin ['d0' ],d1 = dxpin ['d1' ],d2 = dxpin ['d2' ],d3 = dxpin ['d3' ],d4 = dxpin ['d4' ],d5 = dxpin ['d5' ],d6 = dxpin ['d6' ],d7 = dxpin ['d7' ],d8 = dxpin ['d8' ],d9 = dxpin ['d9' ],d10 = dxpin ['d10' ],d11 = dxpin ['d11' ],d12 = dxpin ['d12' ],d13 = dxpin ['d13' ],d14 = dxpin ['d14' ],d15 = dxpin ['d15' ],d16 = dxpin ['d16' ],d17 = dxpin ['d17' ],d18 = dxpin ['d18' ],d19 = dxpin ['d19' ],d20 = dxpin ['d20' ],d21 = dxpin ['d21' ],d22 = dxpin ['d22' ],d23 = dxpin ['d23' ],d24 = dxpin ['d24' ],d25 = dxpin ['d25' ],d26 = dxpin ['d26' ],d27 = dxpin ['d27' ],d28 = dxpin ['d28' ],d29 = dxpin ['d29' ],d30 = dxpin ['d30' ],d31 = dxpin ['d31' ],d32 = dxpin ['d32' ],d33 = dxpin ['d33' ],d34 = dxpin ['d34' ],d35 = dxpin ['d35' ],d36 = dxpin ['d36' ],d37 = dxpin ['d37' ],d38 = dxpin ['d38' ],d39 = dxpin ['d39' ])
1062-
1063- # clean up!
1064- gc .collect ()
1065-
1066- #deleted, return to controllers page
1067- yield from response .awrite ("HTTP/1.0 301 Moved Permanently\r \n " )
1068- yield from response .awrite ("Location: /devices\r \n " )
1069- yield from response .awrite ("Content-Type: text/html\r \n " )
1070- yield from response .awrite ("<html><head><title>Moved</title></head><body><h1>Moved</h1></body></html>\r \n " )
1071-
10721044 elif id == 0 :
10731045 #New device
10741046 _log .debug ("Pages: New Device, choose plugin" )
@@ -1093,6 +1065,67 @@ def get_devicesetting_page(request, response):
10931065 yield from app .render_template (response , "plugin.html" ,(info , plugins ,))
10941066 yield from app .render_template (response , "footer.html" ,(info ,))
10951067
1068+ @app .route ("/api/v1.0/device" , methods = ['DELETE' ])
1069+ def del_devicesetting_page (request , response ):
1070+ if not auth_page (request , response ):
1071+ #send to password page
1072+ yield from response .awrite ("HTTP/1.0 301 Moved Permanently\r \n Location: /password\r \n Content-Type: text/html\r \n <html><head><title>Moved</title></head><body><h1>Moved</h1></body></html>\r \n " )
1073+ return
1074+
1075+ #Display device settings page
1076+ _log .debug ("Pages DEL: Entering Device Settings Page" )
1077+ if request .qs != "" :
1078+ id = int (request .qs [0 ])
1079+ _log .debug ('id = {}' .format (id ))
1080+
1081+ # delete device
1082+ import os
1083+
1084+ _log .debug ("Pages: Delete Device: {}" .format (id ))
1085+
1086+ try :
1087+ db .deviceTable .create_table ()
1088+ except OSError :
1089+ pass
1090+
1091+ # Get correct device
1092+ devices = db .deviceTable .public ()
1093+ for device in devices :
1094+ if device ['id' ] == id :
1095+ break
1096+
1097+ # Get list of plugins
1098+ plugins = db .pluginTable .public ()
1099+ for plugin in plugins :
1100+ if plugin ['id' ] == device ['pluginid' ]:
1101+ break
1102+
1103+ if db .deviceTable .delete (device ['timestamp' ]):
1104+ _log .debug ("Pages: remove record file succeeded: " + db .deviceTable .fname (device ['timestamp' ]))
1105+ else :
1106+ _log .error ("Pages: remove record file failed: " + db .deviceTable .fname (device ['timestamp' ]))
1107+
1108+ # Get dxpin config
1109+ dxpin = db .dxpinTable .getrow ()
1110+
1111+ # Convert pin settings
1112+ dxpins = device ["dxpin" ].split (';' )
1113+ for cnt in range (0 ,plugin ["pincnt" ]):
1114+ _log .debug ("Pages: delete plugin, free pin: " + dxpins [cnt ])
1115+ dxpin [dxpins [cnt ]] = ''
1116+
1117+ # Updated deleted pins
1118+ cid = db .dxpinTable .update ({"timestamp" :dxpin ['timestamp' ]},d0 = dxpin ['d0' ],d1 = dxpin ['d1' ],d2 = dxpin ['d2' ],d3 = dxpin ['d3' ],d4 = dxpin ['d4' ],d5 = dxpin ['d5' ],d6 = dxpin ['d6' ],d7 = dxpin ['d7' ],d8 = dxpin ['d8' ],d9 = dxpin ['d9' ],d10 = dxpin ['d10' ],d11 = dxpin ['d11' ],d12 = dxpin ['d12' ],d13 = dxpin ['d13' ],d14 = dxpin ['d14' ],d15 = dxpin ['d15' ],d16 = dxpin ['d16' ],d17 = dxpin ['d17' ],d18 = dxpin ['d18' ],d19 = dxpin ['d19' ],d20 = dxpin ['d20' ],d21 = dxpin ['d21' ],d22 = dxpin ['d22' ],d23 = dxpin ['d23' ],d24 = dxpin ['d24' ],d25 = dxpin ['d25' ],d26 = dxpin ['d26' ],d27 = dxpin ['d27' ],d28 = dxpin ['d28' ],d29 = dxpin ['d29' ],d30 = dxpin ['d30' ],d31 = dxpin ['d31' ],d32 = dxpin ['d32' ],d33 = dxpin ['d33' ],d34 = dxpin ['d34' ],d35 = dxpin ['d35' ],d36 = dxpin ['d36' ],d37 = dxpin ['d37' ],d38 = dxpin ['d38' ],d39 = dxpin ['d39' ])
1119+
1120+ # clean up!
1121+ gc .collect ()
1122+
1123+ #deleted, return to controllers page
1124+ yield from response .awrite ("HTTP/1.0 303 Moved Permanently\r \n " )
1125+ yield from response .awrite ("Location: /devices\r \n " )
1126+ yield from response .awrite ("Content-Type: text/html\r \n " )
1127+ yield from response .awrite ("<html><head><title>Moved</title></head><body><h1>Moved</h1></body></html>\r \n " )
1128+
10961129@app .route ("/device_setting" , methods = ['POST' ])
10971130def post_devicesetting_page (request , response ):
10981131 if not auth_page (request , response ):
0 commit comments