Skip to content

Commit b1760aa

Browse files
LisaLisa
authored andcommitted
Delete Device changed to RESTful API
1 parent d71b3d5 commit b1760aa

46 files changed

Lines changed: 182 additions & 77 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

modules/unix/picoweb/__init__.py

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,7 @@ def _handle(self, reader, writer):
133133

134134
#print("================")
135135
#print(req, writer)
136+
#print(method, path, qs, proto)
136137
#print(req, (method, path, qs, proto), req.headers)
137138

138139
# Find which mounted subapp (if any) should handle this request
@@ -156,6 +157,17 @@ def _handle(self, reader, writer):
156157
if not app.inited:
157158
app.init()
158159

160+
# RESTful request?
161+
components = path.strip('/').split('/')
162+
#print(components)
163+
if len(components) >= 3:
164+
#reassemble path
165+
path = '/'+'/'.join(components[:3])
166+
qs = components[3:]
167+
restful = True
168+
else:
169+
restful = False
170+
159171
# Find handler to serve this request in app's url_map
160172
found = False
161173
for e in app.url_map:
@@ -228,8 +240,6 @@ def mount(self, url, app):
228240
self.mounts.append(app)
229241

230242
def route(self, url, **kwargs):
231-
print(url)
232-
print(kwargs)
233243
def _route(f):
234244
self.url_map.append((url, f, kwargs))
235245
return f
@@ -271,7 +281,6 @@ def sendfile(self, writer, fname, content_type=None, headers=None):
271281

272282
def handle_static(self, req, resp):
273283
path = req.url_match.group(1)
274-
print(path)
275284
if ".." in path:
276285
yield from http_error(resp, "403")
277286
return

src/R.py

100644100755
Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
R = {
2-
'static/favicon.ico': b'\x00\x00\x01\x00\x01\x00\x10\x10\x00\x00\x01\x00\x08\x00h\x05\x00\x00\x16\x00\x00\x00(\x00\x00\x00\x10\x00\x00\x00 \x00\x00\x00\x01\x00\x08\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00]]]\x00ppp\x00ttt\x00uuu\x00vvv\x00xxx\x00{{{\x00~~~\x00\x89\x89\x89\x00\x8c\x8c\x8c\x00\xa0\xa0\xa0\x00\xa1\xa1\xa1\x00\xa4\xa4\xa4\x00\xa5\xa5\xa5\x00\xa6\xa6\xa6\x00\xa8\xa8\xa8\x00\xa9\xa9\xa9\x00\xaa\xaa\xaa\x00\xaf\xaf\xaf\x00\xb8\xb8\xb8\x00\xbe\xbe\xbe\x00\xc0\xc0\xc0\x00\xc6\xc6\xc6\x00\xc9\xc9\xc9\x00\xca\xca\xca\x00\xcd\xcd\xcd\x00\xce\xce\xce\x00\xcf\xcf\xcf\x00\xd0\xd0\xd0\x00\xd2\xd2\xd2\x00\xd3\xd3\xd3\x00\xd6\xd6\xd6\x00\xd9\xd9\xd9\x00\xda\xda\xda\x00\xdd\xdd\xdd\x00\xdf\xdf\xdf\x00\xe5\xe5\xe5\x00\xed\xed\xed\x00\xef\xef\xef\x00\xf0\xf0\xf0\x00\xf1\xf1\xf1\x00\xf2\xf2\xf2\x00\xfa\xfa\xfa\x00\xfb\xfb\xfb\x00\xfc\xfc\xfc\x00\xfe\xfe\xfe\x00\xff\xff\xff\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x0e \x15\x01\x1a\x19\x19\x19\x19\x1a\x01\x16%\x0c\x00\x00"/,\x07//////\x08&\x0b\x1e\x00\x00\x1b/&\x03/-..-/\x06#\x07\x17\x00\x00\x1d/\'\x04//\x14\x14//\x04(/\x19\x00\x00\x1d/\'\x04//\r\r//\x04\'/\x19\x00\x00\x1d/\'\x04//\x11\x11//\x04\'/\x19\x00\x00\x1d/\'\x04//\x10\x10//\x04\'/\x19\x00\x00\x1d/\'\x04//\x10\x10//\x04\'/\x19\x00\x00\x1d/\'\x05//\x10\x10//\x05\'/\x19\x00\x00\x1d/\'\x02//\x10\x10//\x02\'/\x19\x00\x00\x1d/*\n./\x10\x10/.\n)/\x19\x00\x00\x1c/,.+/\x0f\x0f/+.+/\x18\x00\x00!/////\x13\x13/////\x1f\x00\x00\x12!\x1c\x1d\x1b$\t\t$\x1b\x1d\x1b"\x0f\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00',
32
'static/upyeasy.css': b'* {\r\n\tfont-family: sans-serif;\r\n\tfont-size: 12pt;\r\n}\r\n\r\nh1 {\r\n\tfont-size: 16pt;\r\n\tcolor: #07D;\r\n\tmargin: 8px 0;\r\n\tfont-weight: bold;\r\n}\r\n\r\nh2 {\r\n\tfont-size: 12pt;\r\n\tmargin: 0 -4px;\r\n\tpadding: 6px;\r\n\tbackground-color: #444;\r\n\tcolor: #FFF;\r\n\tfont-weight: bold;\r\n}\r\n\r\nh3 {\r\n\tfont-size: 12pt;\r\n\tmargin: 16px -4px 0 -4px;\r\n\tpadding: 4px;\r\n\tbackground-color: #EEE;\r\n\tcolor: #444;\r\n\tfont-weight: bold;\r\n}\r\n\r\nh6 {\r\n\tfont-size: 10pt;\r\n\tcolor: #07D;\r\n\tfont-weight: bold;\r\n}\r\n\r\n.button {\r\n\tmargin: 4px;\r\n\tpadding: 4px 16px;\r\n\tbackground-color: #07D;\r\n\tcolor: #FFF;\r\n\ttext-decoration: none;\r\n\tborder-radius: 4px\r\n}\r\n\r\n.button.link {}\r\n\r\n.button.help {\r\n\tpadding: 2px 4px;\r\n\tborder: solid 1px #FFF;\r\n\tborder-radius: 50%\r\n}\r\n\r\n.button:hover {\r\n\tbackground: #369;\r\n}\r\n\r\nth {\r\n\tpadding: 4px 7px;\r\n\tbackground-color: #444;\r\n\tcolor: #FFF;\r\n\tborder: solid 2px #FFF;\r\n\tborder-color: #FFF;\r\n\tfont-weight: bold;\r\n\ttext-align: center;\r\n}\r\n\r\ntd {\r\n\tpadding: 4px;\r\n}\r\n\r\ntr {\r\n\tpadding: 4px;\r\n}\r\n\r\ntable {\r\n\tcolor: #000;\r\n}\r\n\r\n.pin {\r\n\tcolor: red;\r\n\tfont-weight: bold;\r\n\ttext-align: left;\r\n}\r\n\r\n.headermenu {\r\n\tposition: fixed;\r\n\ttop: 0;\r\n\tleft: 0;\r\n\tright: 0;\r\n\theight: 64px;\r\n\tpadding: 8px 12px;\r\n\tbackground-color: #F8F8F8;\r\n\tborder-bottom: 1px solid #DDD;\r\n}\r\n\r\n.bodymenu {\r\n\tmargin-top: 96px;\r\n\tmargin-left: 8px;\r\n}\r\n\r\n.menubar {\r\n\tposition: inherit;\r\n\ttop: 44px;\r\n}\r\n\r\n.menu {\r\n\tfloat: left;\r\n\theight: 20px;\r\n\tpadding: 4px 16px 8px 16px;\r\n\tcolor: #444;\r\n\twhite-space: nowrap;\r\n\tborder: solid transparent;\r\n\tborder-width: 4px 1px 1px;\r\n\tborder-radius: 4px 4px 0 0;\r\n\ttext-decoration: none;\r\n}\r\n\r\n.menu.active {\r\n\tcolor: #000;\r\n\tbackground-color: #FFF;\r\n\tborder-color: #07D #DDD #FFF;\r\n}\r\n\r\n.menu:hover {\r\n\tcolor: #000;\r\n\tbackground: #DEF;\r\n}\r\n\r\n.on {\r\n\tcolor: green;\r\n}\r\n\r\n.off {\r\n\tcolor: red;\r\n}\r\n\r\n.div_l {\r\n\tfloat: left;\r\n}\r\n\r\n.div_r {\r\n\tfloat: right;\r\n\tmargin: 2px;\r\n\tpadding: 1px 10px;\r\n\tborder-radius: 4px;\r\n\tbackground-color: #080;\r\n\tcolor: white;\r\n}\r\n\r\n.div_br {\r\n\tclear: both;\r\n}',
4-
'static/upyeasy.js': b"function dept_onchange(frmselect) {frmselect.submit();}\r\n\r\njQuery(function () {\r\n\tjQuery('form').bind('submit', function () {\r\n\t\tjQuery(this).find(':disabled').removeProp('disabled');\r\n\t});\r\n});\r\n\r\n$(document).on('submit', 'form', function() {\r\n $(this).find('input[type=checkbox]').each(function() {\r\n var checkbox = $(this);\r\n\r\n // add a hidden field with the same name before the checkbox with value = 0\r\n if ( !checkbox.prop('checked') ) {\r\n checkbox.clone()\r\n .prop('type', 'hidden')\r\n .val('off')\r\n .insertBefore(checkbox);\r\n }\r\n });\r\n});",
3+
'static/upyeasy.js': b"function dept_onchange(frmselect) {frmselect.submit();}\r\n\r\njQuery(function () {\r\n\tjQuery('form').bind('submit', function () {\r\n\t\tjQuery(this).find(':disabled').removeProp('disabled');\r\n\t});\r\n});\r\n\r\n$(document).on('submit', 'form', function() {\r\n $(this).find('input[type=checkbox]').each(function() {\r\n var checkbox = $(this);\r\n\r\n // add a hidden field with the same name before the checkbox with value = 0\r\n if ( !checkbox.prop('checked') ) {\r\n checkbox.clone()\r\n .prop('type', 'hidden')\r\n .val('off')\r\n .insertBefore(checkbox);\r\n }\r\n });\r\n});\r\n",
54
}

src/pages.py

Lines changed: 98 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -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\nLocation: /password\r\nContent-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'])
705726
def 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\nLocation: /password\r\nContent-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'])
10971130
def post_devicesetting_page(request, response):
10981131
if not auth_page(request, response):

src/static/favicon.ico

-1.37 KB
Binary file not shown.

src/static/upyeasy.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,4 @@ $(document).on('submit', 'form', function() {
1818
.insertBefore(checkbox);
1919
}
2020
});
21-
});
21+
});

src/templates/advanced_html.py

100644100755
File mode changed.

src/templates/config_html.py

100644100755
File mode changed.

0 commit comments

Comments
 (0)