Skip to content

Commit

Permalink
Do not delete invalid plugins at startup, just disable. Load JSON fun…
Browse files Browse the repository at this point in the history
…ction enhanced
  • Loading branch information
enesbcs committed Feb 22, 2020
1 parent 76fbfc6 commit 2aeed37
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 14 deletions.
13 changes: 7 additions & 6 deletions RPIEasy.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,8 +150,8 @@ def CPluginInit():
if (Settings.Controllers[y].enabled):
Settings.Tasks[x].controllercb[y] = Settings.Controllers[y].senddata # assign controller callback to plugins that sends data
except Exception as e:
Settings.Tasks[x] = False
misc.addLog(rpieGlobals.LOG_LEVEL_ERROR,"Task" +str(x+1)+ " is malformed, deleted! "+str(e))
Settings.Tasks[x].enabled = False
misc.addLog(rpieGlobals.LOG_LEVEL_ERROR,"Task " +str(x+1)+ " disabled! "+str(e))

for y in range(0,len(Settings.Controllers)):
if (Settings.Controllers[y]):
Expand All @@ -160,8 +160,8 @@ def CPluginInit():
Settings.Controllers[y].controller_init(None) # init controller at startup
Settings.Controllers[y].setonmsgcallback(Settings.callback_from_controllers) # set global msg callback for 2way comm
except Exception as e:
Settings.Controllers[y] = False
misc.addLog(rpieGlobals.LOG_LEVEL_ERROR,"Controller" +str(y+1)+ " is malformed, deleted! "+str(e))
Settings.Controllers[y].enabled = False
misc.addLog(rpieGlobals.LOG_LEVEL_ERROR,"Controller " +str(y+1)+ " disabled! "+str(e))

return 0

Expand Down Expand Up @@ -190,8 +190,9 @@ def NPluginInit():
try:
if (Settings.Notifiers[x].enabled): # device enabled
Settings.Notifiers[x].plugin_init(None) # init plugin at startup
except:
pass
except Exception as e:
Settings.Notifiers[x].enabled = False
misc.addLog(rpieGlobals.LOG_LEVEL_ERROR,"Notifier " +str(x+1)+ " disabled! "+str(e))

return 0

Expand Down
18 changes: 18 additions & 0 deletions Settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -258,3 +258,21 @@ def loadnotifiers():
# print("Critical Jsonpickle error:",str(e))
success = 0
return success

def getTaskValueIndex(taskname, valuename):
tid = -1
vid = -1
global Tasks
for x in range(0,len(Tasks)):
if (Tasks[x]) and type(Tasks[x]) is not bool:
try:
if Tasks[x].enabled:
if Tasks[x].gettaskname()==taskname:
tid = x+1
for u in range(0,Tasks[x].valuecount):
if Tasks[x].valuenames[u]==valuename:
vid = u+1
return tid, vid
except:
pass
return tid, vid
12 changes: 10 additions & 2 deletions commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@

def doCleanup():
rulesProcessing("System#Shutdown",rpieGlobals.RULE_SYSTEM)
Settings.savetasks()
if (len(Settings.Tasks)>1) or ( (len(Settings.Tasks)==1) and (Settings.Tasks[0] != False) ):
Settings.savetasks()
procarr = []
for x in range(0,len(Settings.Tasks)):
if (Settings.Tasks[x]) and type(Settings.Tasks[x]) is not bool: # device exists
Expand Down Expand Up @@ -120,6 +121,8 @@ def doExecuteCommand(cmdline,Parse=True):
except:
v = 1
#v=v-1
if s == -1:
s, v = Settings.getTaskValueIndex(cmdarr[1],cmdarr[2])
if s >0 and (s<=len(Settings.Tasks)):
s = s-1 # array is 0 based, tasks is 1 based
if (type(Settings.Tasks[s])!=bool) and (Settings.Tasks[s]):
Expand Down Expand Up @@ -147,6 +150,8 @@ def doExecuteCommand(cmdline,Parse=True):
except:
v = 1
#v=v-1
if s == -1:
s, v = Settings.getTaskValueIndex(cmdarr[1],cmdarr[2])
if s >0 and (s<=len(Settings.Tasks)):
s = s-1 # array is 0 based, tasks is 1 based
if (type(Settings.Tasks[s])!=bool) and (Settings.Tasks[s]):
Expand Down Expand Up @@ -432,7 +437,10 @@ def doExecuteCommand(cmdline,Parse=True):
commandfound = True
return commandfound
elif cmdarr[0] == "reset":
os.popen("rm -r data/*.json")
try:
os.popen("rm -r data/*.json")
except:
pass
Settings.Controllers = [False]
Settings.NetworkDevices = []
Settings.Pinout = []
Expand Down
2 changes: 1 addition & 1 deletion rpieGlobals.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
# Copyright (C) 2018-2020 by Alexander Nagy - https://bitekmindenhol.blog.hu/
#
PROGNAME = "RPIEasy"
BUILD = 20051
BUILD = 20053
PROGVER = str(BUILD)[:1]+"."+str(BUILD)[1:2]+"."+str(BUILD)[2:]

gpMenu = []
Expand Down
17 changes: 12 additions & 5 deletions webserver.py
Original file line number Diff line number Diff line change
Expand Up @@ -1895,7 +1895,7 @@ def handle_tools(self):
TXBuffer += '"'
TXBuffer += " href='/?cmd=reboot'>Reboot</a>"
TXBuffer += "<TD>"
TXBuffer += "Reboots Device"
TXBuffer += "Reboot System"

html_TR_TD_height(30)
TXBuffer += "<a class='button link wide' onclick="
Expand All @@ -1904,7 +1904,7 @@ def handle_tools(self):
TXBuffer += '"'
TXBuffer += " href='/?cmd=halt'>Halt</a>"
TXBuffer += "<TD>"
TXBuffer += "Halts Device"
TXBuffer += "Halt/Shutdown System"

html_TR_TD_height(30)
TXBuffer += "<a class='button link wide' onclick="
Expand Down Expand Up @@ -1970,7 +1970,7 @@ def handle_tools(self):
html_TR_TD_height(30)
TXBuffer += "<a class='button link wide red' onclick="
TXBuffer += '"'
TXBuffer += "return confirm('Do you really want to Reset all settings?')"
TXBuffer += "return confirm('Do you really want to Reset/Erase all settings?')"
TXBuffer += '"'
TXBuffer += " href='/?cmd=reset'>Reset device settings</a>"
TXBuffer += "<TD>"
Expand Down Expand Up @@ -2834,7 +2834,7 @@ def handle_upload(self):
TXBuffer += "<p>You can upload JSON settings files one by one or in a single .ZIP archive.<p>"
else:
TXBuffer += "<p>Upload selected files into remote directory: <b>"+str(upath)+"</b><p>"
TXBuffer += "<p>Please avoid using space in filenames."
TXBuffer += "<p>Please avoid using space in filenames, and restart RPIEasy to commit changes. Otherwise you will see empty structures..."
TXBuffer += "<p><form enctype='multipart/form-data' method='post'><p>Upload file:<br><input type='file' name='datafile' size='200'></p><div><input class='button link' type='submit' value='Upload'><input type='hidden' name='path' value='"
TXBuffer += upath + "'></div></form>"
sendHeadandTail("TmplStd",_TAIL)
Expand Down Expand Up @@ -2863,7 +2863,14 @@ def handle_upload_post(self):
if fname.lower().endswith(".zip"):
misc.addLog(rpieGlobals.LOG_LEVEL_DEBUG, "Unzipping...")
OS.extractzip(fname,"data/")
Settings.loadtasks()
try:
Settings.loadnetsettings()
Settings.loadpinout()
Settings.loadtasks()
Settings.loadcontrollers()
Settings.loadnotifiers()
except Exception as e:
print(e)
return self.redirect("/tools")
if upath:
if upath.startswith(current_dir)==False:
Expand Down

0 comments on commit 2aeed37

Please sign in to comment.