Skip to content
Snippets Groups Projects
Commit 6575853c authored by Giovanni La Mura's avatar Giovanni La Mura
Browse files

Merge branch 'script_devel' into 'master'

Report progress when running pycompare

See merge request giacomo.mulas/np_tmcode!42
parents b8a997c6 0b4fdcbd
No related branches found
No related tags found
No related merge requests found
...@@ -139,6 +139,8 @@ def compare_files(config): ...@@ -139,6 +139,8 @@ def compare_files(config):
fortran_file = open(config['fortran_file_name'], 'r') fortran_file = open(config['fortran_file_name'], 'r')
c_file = open(config['c_file_name'], 'r') c_file = open(config['c_file_name'], 'r')
num_read_lines = 0 num_read_lines = 0
num_filtered_lines = 0
last_progress = 0;
# LOG FILE INITIALIZATION # # LOG FILE INITIALIZATION #
if (config['log_html']): if (config['log_html']):
l_file = open(config['html_output'], 'w') l_file = open(config['html_output'], 'w')
...@@ -161,7 +163,10 @@ def compare_files(config): ...@@ -161,7 +163,10 @@ def compare_files(config):
num_len = 1 num_len = 1
if (line_count > 0): if (line_count > 0):
num_len = max(4, int(log10(line_count)) + 1) num_len = max(4, int(log10(line_count)) + 1)
print("INFO: checking file contents...") if (config['say_progress']):
print("INFO: checking file contents... 0", end='%', flush=True)
else:
print("INFO: checking file contents...")
while (line_loop): while (line_loop):
if (not config['linewise']): if (not config['linewise']):
line_loop = False line_loop = False
...@@ -172,6 +177,7 @@ def compare_files(config): ...@@ -172,6 +177,7 @@ def compare_files(config):
c_lines = [c_file.readline()] c_lines = [c_file.readline()]
num_read_lines += 1 num_read_lines += 1
num_read_lines += 1 num_read_lines += 1
num_filtered_lines += 1
# Start here the comparison loop # Start here the comparison loop
if (len(f_lines) == len(c_lines)): if (len(f_lines) == len(c_lines)):
for li in range(len(f_lines)): for li in range(len(f_lines)):
...@@ -180,24 +186,31 @@ def compare_files(config): ...@@ -180,24 +186,31 @@ def compare_files(config):
mismatch_count['warnings'] += line_result[1] mismatch_count['warnings'] += line_result[1]
mismatch_count['noisy'] += line_result[2] mismatch_count['noisy'] += line_result[2]
if (mismatch_count['errors'] > 0 and not config['check_all']): if (mismatch_count['errors'] > 0 and not config['check_all']):
print("INFO: mismatch found at line %d"%(num_read_lines)) print("\nINFO: mismatch found at line %d"%(num_read_lines))
line_loop = False line_loop = False
break break
else: else:
mismatch_count['errors'] = len(c_lines) mismatch_count['errors'] = len(c_lines)
print("ERROR: {0:s} and {1:s} have different numbers of lines!".format( print("\nERROR: {0:s} and {1:s} have different numbers of lines!".format(
config['fortran_file_name'], config['c_file_name'] config['fortran_file_name'], config['c_file_name']
)) ))
if (config['log_html']): if (config['log_html']):
print("Different file sizes. No log produced.") print("Different file sizes. No log produced.")
config['log_html'] = False config['log_html'] = False
if (num_read_lines >= line_count): if (num_filtered_lines >= line_count):
line_loop = False line_loop = False
if (config['say_progress']):
progress = int(100 * num_filtered_lines / line_count)
if (progress > last_progress):
print("\b\b\b\b%3d"%progress, end="%", flush=True)
last_progress = progress
#End line loop #End line loop
if l_file is not None: if l_file is not None:
l_file.write(" </body>\n") l_file.write(" </body>\n")
l_file.write("</html>\n") l_file.write("</html>\n")
l_file.close() l_file.close()
if (config['say_progress']):
print("")
return mismatch_count return mismatch_count
## \brief Perform the comparison of two file lines. ## \brief Perform the comparison of two file lines.
...@@ -438,6 +451,7 @@ def parse_arguments(): ...@@ -438,6 +451,7 @@ def parse_arguments():
'linewise': True, 'linewise': True,
'log_html': False, 'log_html': False,
'html_output': 'pycompare.html', 'html_output': 'pycompare.html',
'say_progress': True,
'warning_threshold': 0.005, 'warning_threshold': 0.005,
'help_mode': False, 'help_mode': False,
'check_all': True, 'check_all': True,
...@@ -460,6 +474,8 @@ def parse_arguments(): ...@@ -460,6 +474,8 @@ def parse_arguments():
config['help_mode'] = True config['help_mode'] = True
elif (arg.startswith("--linewise")): elif (arg.startswith("--linewise")):
config['linewise'] = True config['linewise'] = True
elif (arg.startswith("--no-progress")):
config['say_progress'] = False
elif (arg.startswith("--quick")): elif (arg.startswith("--quick")):
config['check_all'] = False config['check_all'] = False
else: else:
...@@ -482,6 +498,7 @@ def print_help(): ...@@ -482,6 +498,7 @@ def print_help():
print("--help Print this help and exit.") print("--help Print this help and exit.")
print("--html[=OPT_OUTPUT_NAME] Enable logging to HTML file (default logs to \"pycompare.html\").") print("--html[=OPT_OUTPUT_NAME] Enable logging to HTML file (default logs to \"pycompare.html\").")
print("--linewise Load only one line at a time. Useful to compare big files (True by default).") print("--linewise Load only one line at a time. Useful to compare big files (True by default).")
print("--no-progress Disable progress logging.")
print("--quick Stop on first mismatch (default is to perform a full check).") print("--quick Stop on first mismatch (default is to perform a full check).")
print("--warn Set a fractional threshold for numeric warning (default = 0.005).") print("--warn Set a fractional threshold for numeric warning (default = 0.005).")
print(" ") print(" ")
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment