通过p4 user -f username可以创建一个用户,可以看出User、Email、FullName是必须字段。
# A Perforce User Specification.
#
# User: The user's user name.
# Type: Either 'service', 'operator', or 'standard'.
# Default: 'standard'. Read only.
# Email: The user's email address; for email review.
# Update: The date this specification was last modified.
# Access: The date this user was last active. Read only.
# FullName: The user's real name.
# JobView: Selects jobs for inclusion during changelist creation.
# Password: If set, user must have matching $P4PASSWD on client.
# AuthMethod: 'perforce' if using standard authentication or 'ldap' if
# this user should use native LDAP authentication. The '+2fa'
# modifier can be added to the AuthMethod, requiring the user to
# perform multi factor authentication in addition to password
# authentication. For example: 'perforce+2fa'.
# Reviews: Listing of depot files to be reviewed by user.
User: amie6
Email: amie6@HIH-D-34384
FullName: amie6
使用p4python的save_user函数可以创建一个p4用户。
from P4 import P4, P4Exception
import sys
p4 = P4()
def add_user(user_name,password,email,fullname):
try:
user={
'User': user_name,
'Email': email,
'FullName': fullname,
}
ret=p4.save_user(user,"-f") #等效代码:p4.run('user', '-i','-f', input=user)
# print(ret)
p4.input = [password,password]#newpasswd re-enter-newpasswd
ret = p4.run_passwd(user_name)
# print(ret)
except P4Exception as e:
print("exception: "+str(e))
exit(1)
finally:
if p4.connected():
p4.disconnect()
def main():
try:
p4.exception_level = 1
p4.charset="utf8"#要设置为utf8,否则传入中文就报错dm-UpdateUserSpecF
p4.user = sys.argv[1]
p4.port = sys.argv[2]
p4.password = sys.argv[3]#password和ticket等效
# print(sys.argv[1],sys.argv[2],sys.argv[3])
# print(sys.argv[4],sys.argv[5],sys.argv[6],sys.argv[7])
ret=p4.connect()
# print(ret)
user_name=sys.argv[4]
password=sys.argv[5]
email=sys.argv[6]
fullname=sys.argv[7]
add_user(user_name,password,email, fullname)
except P4Exception as e:
print("exception: "+str(e))
exit(1)
if __name__ == "__main__":
main()
exit(0)