(username)
Make sure a given user exists
Make sure a given user exists
Make sure a given user exists
def ensure_user(username):
    """
    Make sure a given user exists
    """
    # Check if user exists
    try:
        pwd.getpwnam(username)
        # User exists, nothing to do!
        return
    except KeyError:
        # User doesn't exist, time to create!
        pass

    subprocess.check_call(["useradd", "--create-home", username])

    subprocess.check_call(["chmod", "o-rwx", expanduser(f"~{username}")])

    pm = get_plugin_manager()
    pm.hook.tljh_new_user_create(username=username)
def ensure_user ( username ) : # Check if user exists try : pwd . getpwnam ( username ) # User exists, nothing to do! return except KeyError : # User doesn't exist, time to create! pass subprocess . check_call ( [ "useradd" , "--create-home" , username ] ) subprocess . check_call ( [ "chmod" , "o-rwx" , expanduser ( f"~{username}" ) ] ) pm = get_plugin_manager ( ) pm . hook . tljh_new_user_create ( username = username )