def get_segment_type_by_segment_name(self, segment_type): """get the menu segment type by a given segment name. if not found, method will return the given segment type """ for rec in self.records: if MenuRecord.bin_list_to_ascii(rec.segment_name) == segment_type: segment_type = str(hex(int(rec.segment_type, 16))) break return segment_type
def get_parsed_data(self): """get dictionary of parsed segment data. """ dw_data = self.get_data() if len(dw_data) > cs.SEGMENTS_HEADER_SIZE_IN_DW: self._parsed_data['Error meg'] = MenuRecord.bin_list_to_ascii( dw_data[cs.ERROR_SEGMENT_ERROR_MSG_START:cs. ERROR_SEGMENT_ERROR_MSG_END]) return self._parsed_data
def get_parsed_data(self): """get dictionary of parsed segment data. """ dw_data = self.get_data() # self._parsed_data['Segment Type'] = "{0} ({1})".format("Notice Segment", str( # hex(int('{:0b}'.format(dw_data[0]).zfill(32)[16:32], 2)))) offset = cs.SEGMENTS_HEADER_SIZE_IN_DW if len(dw_data) > cs.SEGMENTS_HEADER_SIZE_IN_DW: # self._parsed_data['syndrome_id'] = str(hex(int('{:0b}'.format(dw_data[offset]).zfill(32)[16:32], 2))) self._parsed_data['notice msg'] = MenuRecord.bin_list_to_ascii(dw_data[cs.ERROR_SEGMENT_NOTICE_MSG_START: cs.ERROR_SEGMENT_NOTICE_MSG_END]) return self._parsed_data
def __init__(self, data): """Initialize the class by setting the class data. """ self.raw_data = data self.type = cs.RESOURCE_DUMP_SEGMENT_TYPE_MENU self.size = '{:0b}'.format(data[cs.SEGMENT_SIZE_DWORD_LOCATION]).zfill(32)[cs.SEGMENT_SIZE_START: cs. SEGMENT_SIZE_END] self.num_of_records = int('{:0b}'.format(data[cs.MENU_SEGMENT_NUM_OF_RECORDS_DWORD_LOCATION] ).zfill(32)[cs.MENU_SEGMENT_NUM_OF_RECORDS_START: cs. MENU_SEGMENT_NUM_OF_RECORDS_END], 2) self.records = [] for i in range(self.num_of_records): rec = MenuRecord(data[(2 + i * self.RECORD_DWORDS_SIZE): (2 + (i + 1) * self.RECORD_DWORDS_SIZE)]) self.records.append(rec)
def is_supported(self, **kwargs): """check if the arguments matches with the menu data. """ dump_type = kwargs["segment"] index1 = kwargs["index1"] index2 = kwargs["index2"] num_of_objs_1 = kwargs["numOfObj1"] num_of_objs_2 = kwargs["numOfObj2"] match_rec = None # Check whether dump type supported try: for rec in self.records: if rec.segment_type == dump_type or MenuRecord.bin_list_to_ascii( rec.segment_name) == dump_type: match_rec = rec break if not match_rec: raise DumpNotSupported( "Dump type: {0} is not supported".format(dump_type)) # Check index1 attribute if not index1 and index1 is not 0 and match_rec.must_have_index1: raise DumpNotSupported( "Dump type: {0} must have index1 attribute, and it wasn't provided" .format(dump_type)) if not index2 and index2 is not 0 and match_rec.must_have_index2: raise DumpNotSupported( "Dump type: {0} must have index2 attribute, and it wasn't provided" .format(dump_type)) if index1 and not match_rec.supports_index1: raise DumpNotSupported( "Dump type: {0} does not support index1 attribute, and it was provided" .format(dump_type)) if index2 and not match_rec.supports_index2: raise DumpNotSupported( "Dump type: {0} does not support index2 attribute, and it was provided" .format(dump_type)) if not num_of_objs_1 and match_rec.must_have_num_of_obj1: raise DumpNotSupported( "Dump type: {0} must have numOfObj1 attribute, and it wasn't provided" .format(dump_type)) if not num_of_objs_2 and match_rec.must_have_num_of_obj2: raise DumpNotSupported( "Dump type: {0} must have numOfObj2 attribute, and it wasn't provided" .format(dump_type)) if num_of_objs_1 is not None and not match_rec.supports_num_of_obj1: raise DumpNotSupported( "Dump type: {0} does not support numOfObj1 attribute, and it was provided" .format(dump_type)) if num_of_objs_2 is not None and not match_rec.supports_num_of_obj2: raise DumpNotSupported( "Dump type: {0} does not support numOfObj2 attribute, and it was provided" .format(dump_type)) if num_of_objs_1 == "all" and not match_rec.supports_all_num_of_obj1: raise DumpNotSupported( "Dump type: {0} does not support 'all' as numOfObj1 attribute" .format(dump_type)) if num_of_objs_2 == "all" and not match_rec.supports_all_num_of_obj2: raise DumpNotSupported( "Dump type: {0} does not support 'all' as numOfObj2 attribute" .format(dump_type)) if num_of_objs_1 == "active" and not match_rec.supports_active_num_of_obj1: raise DumpNotSupported( "Dump type: {0} does not support 'active' as numOfObj1 attribute" .format(dump_type)) if num_of_objs_2 == "active" and not match_rec.supports_active_num_of_obj2: raise DumpNotSupported( "Dump type: {0} does not support 'active' as numOfObj2 attribute" .format(dump_type)) except DumpNotSupported as e: print(e) return False return True