<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def set_project_permission(project_id, usernames, read, write, share,**kwargs):
 """ Set permissions on a project to a list of users, identifed by their usernames. The read flag ('Y' or 'N') sets read access, the write flag sets write access. If the read flag is 'N', then there is automatically no write access or share access. """

    user_id = kwargs.get('user_id')

    proj_i = _get_project(project_id)

    #Is the sharing user allowed to share this project?
    proj_i.check_share_permission(user_id)

    #You cannot edit something you cannot see.
    if read == 'N':
        write = 'N'
        share = 'N'

    for username in usernames:
        user_i = _get_user(username)

        #The creator of a project must always have read and write access
        #to their project
        if proj_i.created_by == user_i.id:
            raise HydraError("Cannot set permissions on project %s"
                             " for user %s as this user is the creator." %
                             (project_id, username))

        proj_i.set_owner(user_i.id, read=read, write=write)

        for net_i in proj_i.networks:
            net_i.set_owner(user_i.id, read=read, write=write, share=share)
    db.DBSession.flush()