def parseFile(self, fName, emitter_collection): emitter = Emitter() emitter_mode = EmitterMode() generator = Generator() pri_sequence = Pri_Sequence() freq_sequence = Freq_Sequence() pri_segment = Pri_Segment freq_segment = Freq_Segment passNumber = 0 modePass = 0 generatorPass = 0 priSeqPass = 0 freqSeqPass = 0 priSegmentPass = 0 freqSegmentPass = 0 with open(fName) as f1: for cnt, line in enumerate(f1): if line.strip() == constant.EMITTER: currentEntity = constant.EMITTER if passNumber > 0: if modePass > 0: emitter.add_mode(emitter_mode) emitter_collection.append(emitter) modePass = 0 emitter = Emitter() passNumber += 1 elif line.strip() == constant.EMITTER_MODE: currentEntity = constant.EMITTER_MODE if modePass > 0: if generatorPass > 0: emitter_mode.add_generator(generator) emitter.add_mode(emitter_mode) generatorPass = 0 emitter_mode = EmitterMode() modePass += 1 elif line.strip() == constant.GENERATOR: currentEntity = constant.GENERATOR if generatorPass > 0: if priSeqPass > 0: generator.add_pri_sequence(pri_sequence) if freqSeqPass > 0: generator.add_freq_sequence(freq_sequence) emitter_mode.add_generator(generator) priSeqPass = 0 freqSeqPass = 0 generator = Generator() generatorPass += 1 elif line.strip() == constant.PRI_SEQUENCE: currentEntity = constant.PRI_SEQUENCE if priSeqPass > 0: if priSegmentPass > 0: pri_sequence.add_segment(pri_segment) generator.add_pri_sequence(pri_sequence) priSegmentPass = 0 pri_sequence = Pri_Sequence() pri_sequence.set_ordinal_pos(priSeqPass) priSeqPass += 1 elif line.strip() == constant.PRI_SEGMENT: currentEntity = constant.PRI_SEGMENT if priSegmentPass > 0: pri_sequence.add_segment(pri_segment) pri_segment = Pri_Segment() priSegmentPass += 1 elif line.strip() == constant.FREQ_SEQUENCE: currentEntity = constant.FREQ_SEQUENCE if freqSeqPass > 0: if freqSegmentPass > 0: freq_sequence.add_segment(freq_segment) generator.add_freq_sequence(freq_sequence) freqSegmentPass = 0 freq_sequence = Freq_Sequence() freq_sequence.set_ordinal_pos(freqSeqPass) freqSeqPass += 1 elif line.strip() == constant.FREQ_SEGMENT: currentEntity = constant.FREQ_SEGMENT if freqSegmentPass > 0: freq_sequence.add_segment(freq_segment) freq_segment = Freq_Segment() freqSegmentPass += 1 else: if line.strip().__contains__(constant.VALUE_SEPARATOR): line_kv = self.lineAsKeyValue(line.strip()) line_key = line_kv[0].strip() line_value = line_kv[1].strip() if currentEntity == constant.EMITTER: if line_key.strip() == constant.EMITTER_ELNOT: emitter.set_elnot(line_value) else: attrib = Attribute() attrib.set_name(line_key) attrib.set_value(line_value) emitter.add_attribute(attrib) elif currentEntity == constant.EMITTER_MODE: if line_key.strip() == constant.MODE_NAME: emitter_mode.set_mode_name(line_value) else: attrib = Attribute() attrib.set_name(line_key) attrib.set_value(line_value) emitter_mode.add_attribute(attrib) elif currentEntity == constant.GENERATOR: if line_key.strip() == constant.GENERATOR_NUMBER: generator.set_generator_number(line_value) else: attrib = Attribute() attrib.set_name(line_key) attrib.set_value(line_value) generator.add_attribute(attrib) elif currentEntity == constant.PRI_SEQUENCE: if line_key.strip() == constant.NUMBER_OF_SEGMENTS: pri_sequence.set_number_of_segments(line_value) else: attrib = Attribute() attrib.set_name(line_key) attrib.set_value(line_value) pri_sequence.add_attribute(attrib) elif currentEntity == constant.PRI_SEGMENT: if line_key.strip() == constant.PRI_SEGMENT_NUMBER: pri_segment.set_segment_number(line_value) else: attrib = Attribute() attrib.set_name(line_key) attrib.set_value(line_value) pri_segment.add_attribute(attrib) elif currentEntity == constant.FREQ_SEQUENCE: if line_key.strip() == constant.NUMBER_OF_SEGMENTS: freq_sequence.set_number_of_segments( line_value) else: attrib = Attribute() attrib.set_name(line_key) attrib.set_value(line_value) freq_sequence.add_attribute(attrib) elif currentEntity == constant.FREQ_SEGMENT: if line_key.strip( ) == constant.FREQ_SEGMENT_NUMBER: freq_segment.set_segment_number(line_value) else: attrib = Attribute() attrib.set_name(line_key) attrib.set_value(line_value) freq_segment.add_attribute(attrib) else: emitter_collection.append(emitter)
def parseFile(self, fName, isBase): emitter = Emitter() emitter_mode = EmitterMode() generator = Generator() pri_sequence = Sequence() freq_sequence = Sequence() pri_segment = Segment() freq_segment = Segment() passNumber = 0 modePass = 0 generatorPass = 0 priSeqPass = 0 freqSeqPass = 0 priSegmentPass = 0 freqSegmentPass = 0 emitter_collection = self.base_emitters with open(fName) as f1: for cnt, line in enumerate(f1): if line.strip() == constant.EMITTER: currentEntity = constant.EMITTER if passNumber > 0: if modePass > 0: emitter.add_mode(emitter_mode) modePass = 0 if isBase == False: baseEmitter = self.findBaseElnot( emitter.get_elnot()) if baseEmitter: localAttrDifferences = False localModeDifferences = False localDifferences = False baseEmitter.set_bfile(True) baseEmitter.set_cfile(True) emitter.set_bfile(True) emitter.set_cfile(True) localAttrDifferences = baseEmitter.sync_attributes( emitter) localModeDifferences = baseEmitter.sync_modes( emitter) if localAttrDifferences == True or localModeDifferences == True: localDifferences = True baseEmitter.set_hasDifferences( localDifferences) else: emitter.set_hasDifferences(True) emitter.set_cfile(True) self.base_emitters.append(emitter) else: self.base_emitters.append(emitter) emitter = Emitter() emitter.set_bfile( True) if isBase == True else emitter.set_cfile(True) passNumber += 1 elif line.strip() == constant.EMITTER_MODE: currentEntity = constant.EMITTER_MODE if modePass > 0: if generatorPass > 0: emitter_mode.add_generator(generator) emitter.add_mode(emitter_mode) generatorPass = 0 emitter_mode = EmitterMode() modePass += 1 elif line.strip() == constant.GENERATOR: currentEntity = constant.GENERATOR if generatorPass > 0: if priSeqPass > 0: generator.add_pri_sequence(pri_sequence) if freqSeqPass > 0: generator.add_freq_sequence(freq_sequence) emitter_mode.add_generator(generator) priSeqPass = 0 freqSeqPass = 0 generator = Generator() generatorPass += 1 elif line.strip() == constant.PRI_SEQUENCE: currentEntity = constant.PRI_SEQUENCE if priSeqPass > 0: if priSegmentPass > 0: pri_sequence.add_segment(pri_segment) generator.add_pri_sequence(pri_sequence) priSegmentPass = 0 pri_sequence = Sequence() pri_sequence.set_ordinal_pos(priSeqPass) priSeqPass += 1 elif line.strip() == constant.PRI_SEGMENT: currentEntity = constant.PRI_SEGMENT if priSegmentPass > 0: pri_sequence.add_segment(pri_segment) pri_segment = Segment() priSegmentPass += 1 elif line.strip() == constant.FREQ_SEQUENCE: currentEntity = constant.FREQ_SEQUENCE if freqSeqPass > 0: if freqSegmentPass > 0: freq_sequence.add_segment(freq_segment) generator.add_freq_sequence(freq_sequence) freqSegmentPass = 0 freq_sequence = Sequence() freq_sequence.set_ordinal_pos(freqSeqPass) freqSeqPass += 1 elif line.strip() == constant.FREQ_SEGMENT: currentEntity = constant.FREQ_SEGMENT if freqSegmentPass > 0: freq_sequence.add_segment(freq_segment) freq_segment = Segment() freqSegmentPass += 1 else: if line.strip().__contains__(constant.VALUE_SEPARATOR): line_kv = self.lineAsKeyValue(line.strip()) line_key = line_kv[0].strip() line_value = line_kv[1].strip() if currentEntity == constant.EMITTER: if line_key.strip() == constant.EMITTER_ELNOT: emitter.set_elnot(line_value) emitter.set_bfile( True ) if isBase == True else emitter.set_cfile( True) else: attrib = Attribute() attrib.set_name(line_key) attrib.set_value( line_value ) if isBase == True else attrib.set_cvalue( line_value) emitter.add_attribute(attrib) elif currentEntity == constant.EMITTER_MODE: if line_key.strip() == constant.MODE_NAME: emitter_mode.set_mode_name(line_value) emitter_mode.set_bfile( True ) if isBase == True else emitter_mode.set_cfile( True) else: attrib = Attribute() attrib.set_name(line_key) attrib.set_value( line_value ) if isBase == True else attrib.set_cvalue( line_value) emitter_mode.add_attribute(attrib) elif currentEntity == constant.GENERATOR: if line_key.strip() == constant.GENERATOR_NUMBER: generator.set_generator_number(line_value) generator.set_bfile( True ) if isBase == True else generator.set_cfile( True) else: attrib = Attribute() attrib.set_name(line_key) attrib.set_value( line_value ) if isBase == True else attrib.set_cvalue( line_value) generator.add_attribute(attrib) elif currentEntity == constant.PRI_SEQUENCE: pri_sequence.set_bfile( True ) if isBase == True else pri_sequence.set_cfile( True) attrib = Attribute() attrib.set_name(line_key) attrib.set_value( line_value ) if isBase == True else attrib.set_cvalue( line_value) pri_sequence.add_attribute(attrib) elif currentEntity == constant.PRI_SEGMENT: if line_key.strip() == constant.PRI_SEGMENT_NUMBER: pri_segment.set_segment_number(line_value) pri_segment.set_bfile( True ) if isBase == True else pri_segment.set_cfile( True) else: attrib = Attribute() attrib.set_name(line_key) attrib.set_value( line_value ) if isBase == True else attrib.set_cvalue( line_value) pri_segment.add_attribute(attrib) elif currentEntity == constant.FREQ_SEQUENCE: freq_sequence.set_bfile( True ) if isBase == True else freq_sequence.set_cfile( True) attrib = Attribute() attrib.set_name(line_key) attrib.set_value( line_value ) if isBase == True else attrib.set_cvalue( line_value) freq_sequence.add_attribute(attrib) elif currentEntity == constant.FREQ_SEGMENT: if line_key.strip( ) == constant.FREQ_SEGMENT_NUMBER: freq_segment.set_segment_number(line_value) freq_segment.set_bfile( True ) if isBase == True else freq_segment.set_cfile( True) else: attrib = Attribute() attrib.set_name(line_key) attrib.set_value( line_value ) if isBase == True else attrib.set_cvalue( line_value) freq_segment.add_attribute(attrib) else: if isBase == False: baseEmitter = self.findBaseElnot(emitter.get_elnot()) if baseEmitter: localAttrDifferences = False localModeDifferences = False localDifferences = False baseEmitter.set_bfile(True) baseEmitter.set_cfile(True) emitter.set_bfile(True) emitter.set_cfile(True) localAttrDifferences = baseEmitter.sync_attributes( emitter) localModeDifferences = baseEmitter.sync_modes(emitter) if localAttrDifferences == True or localModeDifferences == True: localDifferences = True baseEmitter.set_hasDifferences(localDifferences) else: emitter.set_hasDifferences(True) self.base_emitters.append(emitter)