Skip to content

Commit

Permalink
Merge pull request #249 from NiceProjectPoland/Bug-fix-for-Issue-#240
Browse files Browse the repository at this point in the history
Bug fix for Issue #240 - Manager cannot handle corrupted scenario files.
  • Loading branch information
damies13 authored Jun 8, 2024
2 parents 51c3da2 + 860064d commit 6f5349b
Showing 1 changed file with 15 additions and 18 deletions.
33 changes: 15 additions & 18 deletions rfswarm_manager/rfswarm.py
Original file line number Diff line number Diff line change
Expand Up @@ -2643,8 +2643,7 @@ def OpenFile(self, ScenarioFile):

rowcount = 0
for i in range(scriptcount):
ii = i + 1
istr = str(ii)
istr = str(i + 1)
if istr in filedata:
base.debugmsg(5, "filedata[", istr, "]:", filedata[istr])
rowcount += 1
Expand All @@ -2653,42 +2652,39 @@ def OpenFile(self, ScenarioFile):
# base.scriptlist.append({})
# base.scriptlist[ii]["Index"] = ii
if not base.args.nogui:
if ii + 1 > base.gui.scriptgrid.grid_size()[1]: # grid_size tupple: (cols, rows)
if rowcount + 1 > base.gui.scriptgrid.grid_size()[1]: # grid_size tupple: (cols, rows)
base.addScriptRow()
else:
base.addScriptRow()

# users = 13
if "robots" in filedata[istr] or "users" in filedata[istr]:
if "robots" in filedata[istr]:
base.debugmsg(8, "filedata[", istr, "][robots]:", filedata[istr]["robots"])
self.sr_users_validate(rowcount, int(filedata[istr]["robots"]))
else:
base.debugmsg(8, "filedata[", istr, "][users]:", filedata[istr]["users"])
# base.scriptlist[ii]["users"] = filedata[istr]["users"]
self.sr_users_validate(rowcount, int(filedata[istr]["users"]))
# delay = 0
else:
base.debugmsg(3, "robots missing [", istr, "]")
fileok = False
if "delay" in filedata[istr]:
base.debugmsg(8, "filedata[", istr, "][delay]:", filedata[istr]["delay"])
# base.scriptlist[ii]["delay"] = filedata[istr]["delay"]
self.sr_delay_validate(rowcount, int(filedata[istr]["delay"]))
# rampup = 60
else:
base.debugmsg(3, "delay missing [", istr, "]")
fileok = False
if "rampup" in filedata[istr]:
base.debugmsg(8, "filedata[", istr, "][rampup]:", filedata[istr]["rampup"])
# base.scriptlist[ii]["rampup"] = filedata[istr]["rampup"]
self.sr_rampup_validate(rowcount, int(filedata[istr]["rampup"]))
# run = 600
else:
base.debugmsg(3, "rampup missing [", istr, "]")
fileok = False
if "run" in filedata[istr]:
base.debugmsg(8, "filedata[", istr, "][run]:", filedata[istr]["run"])
# base.scriptlist[ii]["run"] = filedata[istr]["run"]
self.sr_run_validate(rowcount, int(filedata[istr]["run"]))
# script = /Users/dave/Documents/GitHub/rfswarm/robots/OC_Demo_2.robot
else:
Expand All @@ -2714,47 +2710,48 @@ def OpenFile(self, ScenarioFile):
fileok = False
if "test" in filedata[istr]:
base.debugmsg(8, "filedata[", istr, "][test]:", filedata[istr]["test"])
# base.scriptlist[ii]["test"] = filedata[istr]["test"]
self.sr_test_validate("row{}".format(rowcount), filedata[istr]["test"])
else:
base.debugmsg(3, "test missing [", istr, "]")
fileok = False

if "excludelibraries" in filedata[istr]:
base.scriptlist[ii]["excludelibraries"] = filedata[istr]["excludelibraries"]
base.debugmsg(8, "excludelibraries:", filedata[istr]["excludelibraries"])
base.scriptlist[rowcount]["excludelibraries"] = filedata[istr]["excludelibraries"]

if "robotoptions" in filedata[istr]:
base.scriptlist[ii]["robotoptions"] = filedata[istr]["robotoptions"]
base.debugmsg(8, "robotoptions:", filedata[istr]["robotoptions"])
base.scriptlist[rowcount]["robotoptions"] = filedata[istr]["robotoptions"]

# testrepeater = True
if "testrepeater" in filedata[istr]:
base.scriptlist[ii]["testrepeater"] = base.str2bool(filedata[istr]["testrepeater"])
base.scriptlist[rowcount]["testrepeater"] = base.str2bool(filedata[istr]["testrepeater"])
# injectsleepenabled = True
if "injectsleepenabled" in filedata[istr]:
base.scriptlist[ii]["injectsleepenabled"] = base.str2bool(filedata[istr]["injectsleepenabled"])
base.scriptlist[rowcount]["injectsleepenabled"] = base.str2bool(filedata[istr]["injectsleepenabled"])
# injectsleepminimum = 18
if "injectsleepminimum" in filedata[istr] and len(filedata[istr]["injectsleepminimum"]) > 0:
base.scriptlist[ii]["injectsleepminimum"] = int(filedata[istr]["injectsleepminimum"])
base.scriptlist[rowcount]["injectsleepminimum"] = int(filedata[istr]["injectsleepminimum"])
# injectsleepmaximum = 33
if "injectsleepmaximum" in filedata[istr] and len(filedata[istr]["injectsleepmaximum"]) > 0:
base.scriptlist[ii]["injectsleepmaximum"] = int(filedata[istr]["injectsleepmaximum"])
base.scriptlist[rowcount]["injectsleepmaximum"] = int(filedata[istr]["injectsleepmaximum"])
# disableloglog
if "disableloglog" in filedata[istr]:
base.scriptlist[ii]["disableloglog"] = base.str2bool(filedata[istr]["disableloglog"])
base.scriptlist[rowcount]["disableloglog"] = base.str2bool(filedata[istr]["disableloglog"])
# disablelogreport
if "disablelogreport" in filedata[istr]:
base.scriptlist[ii]["disablelogreport"] = base.str2bool(filedata[istr]["disablelogreport"])
base.scriptlist[rowcount]["disablelogreport"] = base.str2bool(filedata[istr]["disablelogreport"])
# disablelogoutput
if "disablelogoutput" in filedata[istr]:
base.scriptlist[ii]["disablelogoutput"] = base.str2bool(filedata[istr]["disablelogoutput"])
base.scriptlist[rowcount]["disablelogoutput"] = base.str2bool(filedata[istr]["disablelogoutput"])

if "filters" in filedata[istr]:
base.debugmsg(9, "filedata[istr][filters]:", filedata[istr]["filters"], type(filedata[istr]["filters"]))
filtr = filedata[istr]["filters"].replace("'", '"')
base.debugmsg(9, "filtr:", filtr, type(filtr))
filtrs = json.loads(filtr)
base.debugmsg(9, "filtrs:", filtrs, type(filtrs))
base.scriptlist[ii]["filters"] = filtrs
base.scriptlist[rowcount]["filters"] = filtrs

if not fileok:
base.debugmsg(1, "Scenario file is damaged:", ScenarioFile)
Expand Down

0 comments on commit 6f5349b

Please sign in to comment.