コード例 #1
0
 def parse(self, filename):
     with open(filename, 'r') as f:
         try:
             data = json.load(f)
         except json.decoder.JSONDecodeError:
             print("[ERROR] JSON file not valid, see exception below.")
             traceback.print_exc()
             exit(-1)
         for com in data["commands"]:
             command = Command()
             command.title = com.get("title")
             command.description = com.get("description")
             command.AT_read = com.get("AT_read")
             command.AT_write = com.get("AT_write")
             command.default = com.get("default", "")
             command.read_response = com.get("read_response", "")
             for choice in com["parameter"]:
                 param = Command.Param(value=choice["value"],
                                       description=choice["description"])
                 command.params.append(param)
             self.commands.append(command)
         return data