| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293 |
- '''
- Created on 22 nov. 2016
- @author: olivier.massot
- '''
- import os
- import re
- import file
- # 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:
- ref_path = source_path.replace(source_dir, reference_dir)
- identical = compare_files(source_path, ref_path)
- if not identical:
- err_code += 1
- return err_code
- def compare_files(path1, path2):
- """ return True if files are identicals """
- linecount = 0
- with open(path1, "r") as file1:
- with open(path2, "r") as file2:
- for line in file1:
- linecount += 1
- if line != file2.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(path1, linecount))
- return False
- 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
|