-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathcreate_user.py
More file actions
executable file
·51 lines (36 loc) · 1.79 KB
/
Copy pathcreate_user.py
File metadata and controls
executable file
·51 lines (36 loc) · 1.79 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#!/usr/bin/env python
# Script written by Lorena Escudero (Department of Radiology, University of Cambridge)
# to create new users in XNAT - June 2020
#
# Usage: edit xnathost/project and give as input a .txt file containing a line per user
# in the form 'user_id:firstName:lastName:email'
#
import xnat
import os
import getpass
# ---------------------------------------------------------------------------------------------------------------------
if __name__ == '__main__':
input_list = 'test_file.txt'
xnathost = 'XNATURL'
project_id = 'PROJECT'
admin = 'admin'
pwd = getpass.getpass("Password for user name : %s = " % user_id)
with xnat.connect(xnathost, user=user_id, password=pwd) as session:
with open(input_list, 'r') as fp:
line = fp.readline()
while line:
line = line.strip()
xnat_user_id = line.split(':')[0]
xnat_user_firstName = line.split(':')[1]
xnat_user_lastName = line.split(':')[2]
xnat_user_email = line.split(':')[3]
xnat_user_json = { "username" : xnat_user_uid, \
"firstName" : xnat_user_firstName, \
"lastName" : xnat_user_lastName, \
"email" : xnat_user_mail, \
"verified" : "true", \
"secured" : "true", \
"active" : "true", \
"enabled" : "true" }
session.post('/xapi/users/', json=xnat_user_json )
line = fp.readline()