def write_file(filename, text):
    """Write text to a file."""
    logging.debug(_('Writing file: %s'), filename)
    try:
        with open(filename, 'w') as writable:
            writable.write(text)
    except (PermissionError, NotADirectoryError):
        logging.error(_('Error writing file: %s'), filename)
        return False
    return True
Write text to a file.