def refresh(self): self._reset() self._is_json_protocol = self.name.endswith('.json') if self._is_json_protocol: # TODO Ian 2018-05-16 use protocol JSON schema to raise # warning/error here if the protocol_text doesn't follow the schema self._protocol = json.loads(self.protocol_text) version = 'JSON' else: parsed = ast.parse(self.protocol_text, filename=self.name) self.metadata = extract_metadata(parsed) self._protocol = compile(parsed, filename=self.name, mode='exec') version = infer_version(self.metadata, parsed) self.api_level = 2 if ff.use_protocol_api_v2() else 1 if ff.use_protocol_api_v2() and version == '1': raise RuntimeError( 'This protocol targets Protocol API V1, but the robot is set ' 'to Protocol API V2. If this is actually a V2 protocol, ' 'please set the \'apiLevel\' to \'2\' in the metadata. If you ' 'do not want to be on API V2, please disable the \'Use ' 'Protocol API version 2\' toggle in the robot\'s Advanced ' 'Settings and restart the robot.') log.info(f"Protocol API version: {version}") try: self._broker.set_logger(self._sim_logger) commands = self._simulate() except Exception: raise finally: self._broker.set_logger(self._default_logger) self.commands = tree.from_list(commands) self.containers = self.get_containers() self.instruments = self.get_instruments() self.modules = self.get_modules() self.startTime = None self.set_state('loaded') return self
def refresh(self): self._reset() try: self._broker.set_logger(self._sim_logger) commands = self._simulate() except Exception: raise finally: self._broker.set_logger(self._default_logger) self.commands = tree.from_list(commands) self.containers = self.get_containers() self.instruments = self.get_instruments() self.modules = self.get_modules() self.startTime = None self.set_state('loaded') return self
def refresh(self): self._reset() self._is_json_protocol = self.name.endswith('.json') if self._is_json_protocol: # TODO Ian 2018-05-16 use protocol JSON schema to raise # warning/error here if the protocol_text doesn't follow the schema self._protocol = json.loads(self.protocol_text) else: parsed = ast.parse(self.protocol_text) self._protocol = compile(parsed, filename=self.name, mode='exec') commands = self._simulate() self.commands = tree.from_list(commands) self.containers = self.get_containers() self.instruments = self.get_instruments() self.modules = self.get_modules() self.startTime = None self.set_state('loaded') return self
def refresh(self): self._reset() self.api_level = 2 if ff.use_protocol_api_v2() else 1 # self.metadata is exposed via jrpc if isinstance(self._protocol, PythonProtocol): self.metadata = self._protocol.metadata if ff.use_protocol_api_v2()\ and self._protocol.api_level == '1'\ and not ff.enable_back_compat(): raise RuntimeError( 'This protocol targets Protocol API V1, but the robot is ' 'set to Protocol API V2. If this is actually a V2 ' 'protocol, please set the \'apiLevel\' to \'2\' in the ' 'metadata. If you do not want to be on API V2, please ' 'disable the \'Use Protocol API version 2\' toggle in the ' 'robot\'s Advanced Settings and restart the robot.') log.info(f"Protocol API version: {self._protocol.api_level}") else: self.metadata = {} log.info(f"JSON protocol") try: self._broker.set_logger(self._sim_logger) commands = self._simulate() except Exception: raise finally: self._broker.set_logger(self._default_logger) self.commands = tree.from_list(commands) self.containers = self.get_containers() self.instruments = self.get_instruments() self.modules = self.get_modules() self.startTime = None self.set_state('loaded') return self
def test_command_tree(): commands = tree.from_list([{ 'level': 0, 'description': 'A', 'id': 0 }, { 'level': 0, 'description': 'B', 'id': 1 }, { 'level': 0, 'description': 'C', 'id': 2 }]) assert commands == [ { 'description': 'A', 'id': 0, 'children': [] }, { 'description': 'B', 'id': 1, 'children': [] }, { 'description': 'C', 'id': 2, 'children': [] }, ] commands = tree.from_list([ { 'level': 0, 'description': 'A', 'id': 0 }, { 'level': 1, 'description': 'B', 'id': 1 }, { 'level': 2, 'description': 'C', 'id': 2 }, { 'level': 0, 'description': 'D', 'id': 3 }, ]) assert commands == [{ 'description': 'A', 'id': 0, 'children': [{ 'description': 'B', 'id': 1, 'children': [{ 'description': 'C', 'id': 2, 'children': [] }] }] }, { 'description': 'D', 'id': 3, 'children': [] }]