'''
Created on 22 nov. 2016

@author: olivier.massot
'''
from ffile import flist
import sys


_, source_dir, reference_dir = sys.argv

print("** Compare {} to {} **".format(source_dir, reference_dir))

list_source_dir = flist(source_dir, recursive=True, listdirs=False, listfiles=True, complete_paths=True)

list_reference_dir = 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")
    sys.exit(1)

exit_code = 0
for source_path in list_source_dir:
    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:
            
            if source_file.read() != ref_file.read():
                print(">> {} do not match to ref".format(source_path))
                exit_code = 2
            
sys.exit(exit_code)