Loading scripts/parse_commands.py +42 −46 Original line number Diff line number Diff line Loading @@ -2,7 +2,6 @@ import argparse import re import json from os import path from pathlib import Path import glob Loading @@ -22,22 +21,35 @@ if __name__ == '__main__': here = Path(__file__).parent.resolve() with open(input,'r') as infile: report = infile.read() cmds_enc=[] cmds_dec=[] cmds_rend=[] cmds_isar_post_rend=[] # Depending on pytest-html version, the data may be in a json-blob. If so, the code below should handle this format. if path.isdir(input): input = Path(input).rglob('*.html') else: input = [input] for html_report in input: with open(html_report,'r') as infile: for line in infile.readlines(): cmds_enc.extend(re.findall(r"DUT encoder command:\\n\\t(.*?)\\n", line)) cmds_dec.extend(re.findall(r"DUT decoder command:\\n\\t(.*?)\\n", line)) cmds_rend.extend(re.findall(r"Running command\\n(.*?)\\n", line)) cmds_isar_post_rend.extend(re.findall(r"Running ISAR post renderer command\\n(.*?)\\n", line)) # If pytest-html < v4 is used, the parsing will fail and render empty lists. This is a work-around in case that happens. if all(not x for x in [cmds_enc, cmds_dec, cmds_rend, cmds_isar_post_rend]): lines = re.split(r'\\n', report) for html_report in input: with open(html_report,'r') as infile: enc_cmd = False dec_cmd = False rend_cmd = False isar_post_rend_cmd = False for line in lines: line = line.split("<br/>")[0].replace('\\t','') # Remove trailing html tags for line in infile.readlines(): line = line.split("<br/>")[0] # Remove trailing html tags if enc_cmd: cmds_enc.append(line) enc_cmd = False Loading @@ -51,31 +63,15 @@ if __name__ == '__main__': cmds_isar_post_rend.append(line) isar_post_rend_cmd = False else: if "REF encoder command" in line: if "DUT encoder command" in line: enc_cmd = True elif "REF decoder command" in line: elif "DUT decoder command" in line: dec_cmd = True elif "Running command" in line: rend_cmd = True elif "Running ISAR post renderer command" in line: isar_post_rend_cmd = True # If the above reading failed, try this variant instead. if all(not x for x in [cmds_enc, cmds_dec, cmds_rend, cmds_isar_post_rend]): with open(input,'r') as infile: for line in infile.readlines(): cmds_enc.extend(re.findall(r"DUT encoder command:\\n\\t(.*?)\\n", line)) cmds_dec.extend(re.findall(r"DUT decoder command:\\n\\t(.*?)\\n", line)) cmds_rend.extend(re.findall(r"Running command\\n(.*?)\\n", line)) cmds_isar_post_rend.extend(re.findall(r"Running ISAR post renderer command\\n(.*?)\\n", line)) # Remove trailing HTML tags, if any cmds_rend = [x.split('<')[0] for x in cmds_rend] cmds_isar_post_rend = [x.split('<')[0] for x in cmds_isar_post_rend] # Sort lists to keep deterministic order between runs cmds_enc.sort() cmds_dec.sort() Loading Loading
scripts/parse_commands.py +42 −46 Original line number Diff line number Diff line Loading @@ -2,7 +2,6 @@ import argparse import re import json from os import path from pathlib import Path import glob Loading @@ -22,22 +21,35 @@ if __name__ == '__main__': here = Path(__file__).parent.resolve() with open(input,'r') as infile: report = infile.read() cmds_enc=[] cmds_dec=[] cmds_rend=[] cmds_isar_post_rend=[] # Depending on pytest-html version, the data may be in a json-blob. If so, the code below should handle this format. if path.isdir(input): input = Path(input).rglob('*.html') else: input = [input] for html_report in input: with open(html_report,'r') as infile: for line in infile.readlines(): cmds_enc.extend(re.findall(r"DUT encoder command:\\n\\t(.*?)\\n", line)) cmds_dec.extend(re.findall(r"DUT decoder command:\\n\\t(.*?)\\n", line)) cmds_rend.extend(re.findall(r"Running command\\n(.*?)\\n", line)) cmds_isar_post_rend.extend(re.findall(r"Running ISAR post renderer command\\n(.*?)\\n", line)) # If pytest-html < v4 is used, the parsing will fail and render empty lists. This is a work-around in case that happens. if all(not x for x in [cmds_enc, cmds_dec, cmds_rend, cmds_isar_post_rend]): lines = re.split(r'\\n', report) for html_report in input: with open(html_report,'r') as infile: enc_cmd = False dec_cmd = False rend_cmd = False isar_post_rend_cmd = False for line in lines: line = line.split("<br/>")[0].replace('\\t','') # Remove trailing html tags for line in infile.readlines(): line = line.split("<br/>")[0] # Remove trailing html tags if enc_cmd: cmds_enc.append(line) enc_cmd = False Loading @@ -51,31 +63,15 @@ if __name__ == '__main__': cmds_isar_post_rend.append(line) isar_post_rend_cmd = False else: if "REF encoder command" in line: if "DUT encoder command" in line: enc_cmd = True elif "REF decoder command" in line: elif "DUT decoder command" in line: dec_cmd = True elif "Running command" in line: rend_cmd = True elif "Running ISAR post renderer command" in line: isar_post_rend_cmd = True # If the above reading failed, try this variant instead. if all(not x for x in [cmds_enc, cmds_dec, cmds_rend, cmds_isar_post_rend]): with open(input,'r') as infile: for line in infile.readlines(): cmds_enc.extend(re.findall(r"DUT encoder command:\\n\\t(.*?)\\n", line)) cmds_dec.extend(re.findall(r"DUT decoder command:\\n\\t(.*?)\\n", line)) cmds_rend.extend(re.findall(r"Running command\\n(.*?)\\n", line)) cmds_isar_post_rend.extend(re.findall(r"Running ISAR post renderer command\\n(.*?)\\n", line)) # Remove trailing HTML tags, if any cmds_rend = [x.split('<')[0] for x in cmds_rend] cmds_isar_post_rend = [x.split('<')[0] for x in cmds_isar_post_rend] # Sort lists to keep deterministic order between runs cmds_enc.sort() cmds_dec.sort() Loading