def remove_provision_config(src, dstpath, backup_ext='_aminator'):
    dst = os.path.join(dstpath.rstrip('/'), src.lstrip('/'))
    backup = '{0}{1}'.format(dst, backup_ext)
    try:
        if os.path.isfile(dst) or os.path.islink(dst) or os.path.isdir(dst):
            try:
                if os.path.isdir(dst):
                    log.debug('Removing {0}'.format(dst))
                    shutil.rmtree(dst)
                    log.debug('Provision config {0} removed'.format(dst))
            except Exception:
                errstr = 'Error encountered while removing {0}'.format(dst)
                log.critical(errstr)
                log.debug(errstr, exc_info=True)
                return False

        if os.path.isfile(backup) or os.path.islink(backup) or os.path.isdir(backup):
            log.debug('Restoring {0} to {1}'.format(backup, dst))
            if os.path.isdir(backup) or os.path.islink(backup):
                os.rename(backup, dst)
            elif os.path.isfile(backup):
                shutil.copy(backup, dst)
            log.debug('Restoration of {0} to {1} successful'.format(backup, dst))
        else:
            log.warn('No backup file {0} was found'.format(backup))
    except Exception:
        errstr = 'Error encountered while restoring {0} to {1}'.format(backup, dst)
        log.critical(errstr)
        log.debug(errstr, exc_info=True)
        return False
    return True
dataset/ETHPy150Open Netflix/aminator/aminator/util/linux.py/remove_provision_config/original