| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788 |
- '''
- Created on 22 nov. 2016
- @author: olivier.massot
- '''
- import os
- import file
- import re
- # regex for ignoring lines in file comparison
- CMP_IGNORE_LINES = ["<dataroot xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" generated=\"\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}\"/?>"]
- 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, "r") as source_file:
-
- ref_path = source_path.replace(source_dir, reference_dir)
- with open(ref_path, "r") as ref_file:
-
- for line in source_file:
- linecount += 1
-
- if line != ref_file.readline():
- ignore = False
- try:
- for ignore_regex in CMP_IGNORE_LINES:
- if re.match(ignore_regex, line) != None:
- ignore = True
- except:
- pass
- if not ignore:
- 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
-
|