| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677 |
- '''
- Created on 22 nov. 2016
- @author: olivier.massot
- '''
- import os
- import file
- def compare_dirs(source_dir, reference_dir):
- print("** Compare {} to {} **".format(source_dir, reference_dir))
- err_code = 0
- list_source_dir = file.flist(source_dir, recursive=True, listdirs=False, listfiles=True, complete_paths=True)
-
- list_reference_dir = file.flist(reference_dir, recursive=True, listdirs=False, listfiles=True, complete_paths=True)
-
- if len(list_source_dir) != len(list_reference_dir):
- print(">> number of dirs / files does not match")
- print("Diff:")
- lst_source_names = [f.replace(source_dir, "") for f in list_source_dir]
- lst_ref_names = [f.replace(reference_dir, "") for f in list_reference_dir]
-
- for name in list( set(lst_source_names) - set(lst_ref_names) ):
- print("+ "+name)
- err_code += 1
- for name in list( set(lst_ref_names) - set(lst_source_names) ):
- print("- "+name)
- err_code += 1
-
-
- for source_path in list_source_dir:
- linecount = 0
- with open(source_path, "rb") as source_file:
-
- ref_path = source_path.replace(source_dir, reference_dir)
- with open(ref_path, "rb") as ref_file:
-
- for line in source_file:
- linecount += 1
-
- if line != ref_file.readline():
- print("> {} : source and ref differ at line {}".format(source_path, linecount))
- err_code += 1
- continue
-
- return err_code
-
- def clean_sources(sources_path):
- print("Clean the sources")
- # remove the source code of test module and macros
- for file_path in ("modules\\test_methods.bas",
- "macros\\test_export.bas",
- "macros\\test_import.bas"):
- sources_path = os.path.abspath(sources_path)
- try:
- os.remove( file.fjoin(sources_path, file_path) )
- except FileNotFoundError:
- pass
-
- def verify_log(log_path):
- error_count = 0
- critical_found = False
- with open(os.path.abspath(log_path), "r") as log_file:
- for line in log_file:
- if "ERROR" in line:
- error_count += 1
- if "CRITICAL" in line:
- critical_found = True
- print("CRITICAL ERROR found in the log file ({})".format(log_path))
- break
- if error_count > 0:
- print("Warning: ERRORS found in the log file ({})".format(log_path))
-
- return 0 if not critical_found else 1
-
|