def save_simulator_file(self, filename: str): tag = self.simulator_config.save_to_xml(standalone=True) util.write_xml_to_file(tag, filename)
def save_project(self, simulator_config=None): if self.project_file is None or not os.path.isfile(self.project_file): return # Recreate file open(self.project_file, 'w').close() root = ET.Element("UniversalRadioHackerProject") tree = ET.ElementTree(root) tree.write(self.project_file) # self.write_labels(self.maincontroller.compare_frame_controller.proto_analyzer) self.write_modulators_to_project_file(tree=tree) tree = ET.parse(self.project_file) root = tree.getroot() root.append( self.__device_conf_dict_to_xml("device_conf", self.device_conf)) root.append(self.simulator_rx_conf_to_xml()) root.append(self.simulator_tx_conf_to_xml()) root.set("description", str(self.description).replace("\n", self.NEWLINE_CODE)) root.set( "collapse_project_tabs", str(int(not self.main_controller.ui.tabParticipants.isVisible()))) root.set("modulation_was_edited", str(int(self.modulation_was_edited))) root.set("broadcast_address_hex", str(self.broadcast_address_hex)) open_files = [] for i, sf in enumerate( self.main_controller.signal_tab_controller.signal_frames): self.write_signal_information_to_project_file(sf.signal, tree=tree) try: pf = self.main_controller.signal_protocol_dict[sf] filename = pf.filename if filename in FileOperator.archives.keys(): open_filename = FileOperator.archives[filename] else: open_filename = filename if not open_filename or open_filename in open_files: continue open_files.append(open_filename) file_tag = ET.SubElement(root, "open_file") file_tag.set("name", os.path.relpath(open_filename, self.project_path)) file_tag.set("position", str(i)) except Exception: pass for group_tag in root.findall("group"): root.remove(group_tag) cfc = self.main_controller.compare_frame_controller for i, group in enumerate(cfc.groups): group_tag = ET.SubElement(root, "group") group_tag.set("name", str(group.name)) group_tag.set("id", str(i)) for proto_frame in cfc.protocols[i]: if proto_frame.filename: proto_tag = ET.SubElement(group_tag, "cf_protocol") proto_tag.set( "filename", os.path.relpath(proto_frame.filename, self.project_path)) root.append( cfc.proto_analyzer.to_xml_tag( decodings=cfc.decodings, participants=self.participants, messages=[ msg for proto in cfc.full_protocol_list for msg in proto.messages ])) if simulator_config is not None: root.append(simulator_config.save_to_xml()) util.write_xml_to_file(root, self.project_file)
def save_project(self, simulator_config=None): if self.project_file is None or not os.path.isfile(self.project_file): return # Recreate file open(self.project_file, 'w').close() root = ET.Element("UniversalRadioHackerProject") tree = ET.ElementTree(root) tree.write(self.project_file) # self.write_labels(self.maincontroller.compare_frame_controller.proto_analyzer) self.write_modulators_to_project_file(tree=tree) tree = ET.parse(self.project_file) root = tree.getroot() root.append(self.__device_conf_dict_to_xml("device_conf", self.device_conf)) root.append(self.simulator_rx_conf_to_xml()) root.append(self.simulator_tx_conf_to_xml()) root.set("description", str(self.description).replace("\n", self.NEWLINE_CODE)) root.set("collapse_project_tabs", str(int(not self.main_controller.ui.tabParticipants.isVisible()))) root.set("modulation_was_edited", str(int(self.modulation_was_edited))) root.set("broadcast_address_hex", str(self.broadcast_address_hex)) open_files = [] for i, sf in enumerate(self.main_controller.signal_tab_controller.signal_frames): self.write_signal_information_to_project_file(sf.signal, tree=tree) try: pf = self.main_controller.signal_protocol_dict[sf] filename = pf.filename if filename in FileOperator.archives.keys(): open_filename = FileOperator.archives[filename] else: open_filename = filename if not open_filename or open_filename in open_files: continue open_files.append(open_filename) file_tag = ET.SubElement(root, "open_file") try: file_path = os.path.relpath(open_filename, self.project_path) except ValueError: file_path = open_filename file_tag.set("name", file_path) file_tag.set("position", str(i)) except Exception: pass for group_tag in root.findall("group"): root.remove(group_tag) cfc = self.main_controller.compare_frame_controller for i, group in enumerate(cfc.groups): group_tag = ET.SubElement(root, "group") group_tag.set("name", str(group.name)) group_tag.set("id", str(i)) for proto_frame in cfc.protocols[i]: if proto_frame.filename: proto_tag = ET.SubElement(group_tag, "cf_protocol") try: rel_file_name = os.path.relpath(proto_frame.filename, self.project_path) except ValueError: rel_file_name = proto_frame.filename proto_tag.set("filename", rel_file_name) root.append(cfc.proto_analyzer.to_xml_tag(decodings=cfc.decodings, participants=self.participants, messages=[msg for proto in cfc.full_protocol_list for msg in proto.messages])) if simulator_config is not None: root.append(simulator_config.save_to_xml()) util.write_xml_to_file(root, self.project_file)