Source code for cgl.plugins.perforce.utils.user
import os
from cgl.core.utils.general import cgl_execute
[docs]
def check_for_user(username):
"""
Function to check if a perforce user exists
Args:
username: Name of the user
Returns: True if user exists, False if user doesnt exist
"""
command = "p4 users"
output = cgl_execute(command=command, return_output=True, print_output=False)
if output['printout']:
for user in output['printout']:
if username == user.split(" ")[0]:
return True
return False
[docs]
def create_user(user_name, super_user, email=None):
"""
Create a perforce user using the computer's current user
Returns:
True if successful, False if failed
"""
#TODO Design a way to store the super user name in configs or always default it to a user named "super"
os.system(f"p4 set P4USER=kylem")
command = f"(echo User: {user_name} & echo Email: {email} & echo FullName: {user_name}) | p4 user -f -i"
os.system(command)
if check_for_user(username=user_name):
return True
else:
return False