import md5
import os
import errno

def _get_file_chk(f):
    chk = None
    try:
        chk = md5.md5(f.read())
    except AttributeError as e:
        try:
            with open(f, 'rb') as fo:
                chk = _get_file_chk(fo)
        except (OSError, IOError) as e:
            chk = None
    return chk

def compare_files(fst, snd):
    chk_fst = _get_file_chk(fst)
    chk_snd = _get_file_chk(snd)
    return chk_fst and chk_fst == chk_snd

def make_dir(path, ignore_exists = True):
    try:
        os.makedirs(path)
    except OSError as err:
        if ignore_exists and err.errno == errno.EEXIST and os.path.isdir(path): 
            pass
        else:
            raise
