python - How to compare the attributes start with $ in 2 functions and display match or mismatch -
my input file contain attributes
if(match($option_enabledetails, "1") or match($option_enabledetails_juniper, "1")) { details($junifilexferstatus,$junifilexfertimestamp,$junifilexferindex) } @extendedattr = nvp_add(@extendedattr, "junifilexferstatus", $junifilexferstatus, "junifilexfertimestamp", $junifilexfertimestamp, "junifilexferindex", $junifilexferindex)
i got lot of cases in input file, how can compare instances start $ in details , instances start $ in nvp_add here?
import re caselines_index = [] cases = [] readlines = [] def read(in_file): global cases global caselines_index global readlines open(in_file, 'r') file: line in file.readlines(): readlines.append(line.strip()) line in readlines: case_search = re.search("case\s\".+?\"\:\s", line) if case_search: caselines_index.append(readlines.index(line)) #print caselines_index caselines_index_iter = iter(caselines_index) int_line_index = int(next(caselines_index_iter)) int_next_index = int(next(caselines_index_iter)) while true: try: case_text = ' '.join(readlines[int_line_index:int_next_index]).strip() case = [readlines[int_line_index].strip(), case_text] cases.append(case) int_line_index = int_next_index int_next_index = int(next(caselines_index_iter)) except stopiteration: case_text = ' '.join(readlines[int_line_index:len(readlines) - 1]).strip() case = [readlines[int_line_index].strip(), case_text] cases.append(case) break def work(): match = 1 case_list in cases: details = [] nvp_add = [] caseline = case_list[0].strip() nvp = re.findall("details\(.+?\)", case_list[1].strip()) item in nvp: result_list = re.findall("(\$.+?)[\,\)]", item) result in result_list: if "$*" not in result: details.append(result) nvp = re.findall("nvp_add\(.+?\)", case_list[1].strip()) item in nvp: result_list = re.findall("(\$.+?)[\,\)]", item) result in result_list: if "$*" not in result: nvp_add.append(result) missing_from_details, missing_from_nvp_add = [], [] missing_from_details = [o o in nvp_add if o not in set(details)] missing_from_nvp_add = [o o in details if o not in set(nvp_add)] if missing_from_nvp_add or missing_from_details: match = 0 print caseline + " line - " + str(readlines.index(caseline) + 1) mismatch in missing_from_details: print "missing details:" print mismatch mismatch in missing_from_nvp_add: print "missing nvp_add:" print mismatch print "\n" if match == 1: print "match" else: print "mismatches" def main(): in_file = "target1.txt" read(in_file) work() if __name__=="__main__": main()
if understand correctly it
Comments
Post a Comment