Commit 5f89ea7b authored by Giovanni La Mura's avatar Giovanni La Mura
Browse files

Add progress log to pycompare

parent 1d1e85a4
Loading
Loading
Loading
Loading
+21 −4
Original line number Diff line number Diff line
@@ -139,6 +139,8 @@ def compare_files(config):
        fortran_file = open(config['fortran_file_name'], 'r')
        c_file = open(config['c_file_name'], 'r')
    num_read_lines = 0
    num_filtered_lines = 0
    last_progress = 0;
    # LOG FILE INITIALIZATION #
    if (config['log_html']):
        l_file = open(config['html_output'], 'w')
@@ -161,6 +163,9 @@ def compare_files(config):
    num_len = 1
    if (line_count > 0):
        num_len = max(4, int(log10(line_count)) + 1)
    if (config['say_progress']):
        print("INFO: checking file contents...   0", end='%', flush=True)
    else:
        print("INFO: checking file contents...")
    while (line_loop):
        if (not config['linewise']):
@@ -172,6 +177,7 @@ def compare_files(config):
                c_lines = [c_file.readline()]
                num_read_lines += 1
            num_read_lines += 1
            num_filtered_lines += 1
        # Start here the comparison loop
        if (len(f_lines) == len(c_lines)):
            for li in range(len(f_lines)):
@@ -180,24 +186,31 @@ def compare_files(config):
                mismatch_count['warnings'] += line_result[1]
                mismatch_count['noisy'] += line_result[2]
                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
                    break
        else:
            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']
            ))
            if (config['log_html']):
                print("Different file sizes. No log produced.")
                config['log_html'] = False
        if (num_read_lines >= line_count):
        if (num_filtered_lines >= line_count):
            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
    if l_file is not None:
        l_file.write("  </body>\n")
        l_file.write("</html>\n")
        l_file.close()
    if (config['say_progress']):
        print("")
    return mismatch_count

## \brief Perform the comparison of two file lines.
@@ -438,6 +451,7 @@ def parse_arguments():
        'linewise': True,
        'log_html': False,
        'html_output': 'pycompare.html',
        'say_progress': True,
        'warning_threshold': 0.005,
        'help_mode': False,
        'check_all': True,
@@ -460,6 +474,8 @@ def parse_arguments():
            config['help_mode'] = True
        elif (arg.startswith("--linewise")):
            config['linewise'] = True
        elif (arg.startswith("--no-progress")):
            config['say_progress'] = False
        elif (arg.startswith("--quick")):
            config['check_all'] = False
        else:
@@ -482,6 +498,7 @@ def print_help():
    print("--help                    Print this help and exit.")
    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("--no-progress             Disable progress logging.")
    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("                                            ")