comparison create_account.py @ 0:cd595b5d890a draft

planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/apollo commit f745b23c84a615bf434d717c8c0e553a012f0268
author gga
date Mon, 11 Sep 2017 05:46:00 -0400
parents
children aee984715db1
comparison
equal deleted inserted replaced
-1:000000000000 0:cd595b5d890a
1 #!/usr/bin/env python
2 from __future__ import print_function
3
4 import argparse
5 import random
6 import time
7
8 from builtins import range, str
9
10 from webapollo import WAAuth, WebApolloInstance
11
12
13 def pwgen(length):
14 chars = list('qwrtpsdfghjklzxcvbnm')
15 return ''.join(random.choice(chars) for _ in range(length))
16
17
18 if __name__ == '__main__':
19 parser = argparse.ArgumentParser(description='Sample script to add an account via web services')
20 WAAuth(parser)
21
22 parser.add_argument('email', help='User Email')
23 parser.add_argument('--first', help='First Name', default='Jane')
24 parser.add_argument('--last', help='Last Name', default='Aggie')
25 args = parser.parse_args()
26
27 wa = WebApolloInstance(args.apollo, args.username, args.password)
28
29 password = pwgen(12)
30 time.sleep(1)
31 users = wa.users.loadUsers()
32 user = [u for u in users
33 if u.username == args.email]
34
35 if len(user) == 1:
36 # Update name, regen password if the user ran it again
37 userObj = user[0]
38 returnData = wa.users.updateUser(userObj, args.email, args.first, args.last, password)
39 print('Updated User\nUsername: %s\nPassword: %s' % (args.email, password))
40 else:
41 returnData = wa.users.createUser(args.email, args.first, args.last, password, role='user')
42 print('Created User\nUsername: %s\nPassword: %s' % (args.email, password))
43
44 print("Return data: " + str(returnData))