comparison apollo/ApolloUser.py @ 0:ce4f91831680 draft default tip

planemo upload for repository https://github.com/Yating-L/suite_gonramp_apollo.git commit 5367a00befb467f162d1870edb91f9face72e894
author yating-l
date Fri, 16 Feb 2018 10:57:13 -0500
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:ce4f91831680
1 #!/usr/bin/python
2
3
4 import os
5 import sys
6 import json
7 import logging
8 from util import subtools
9
10 class ApolloUser(object):
11 """
12 This class is to manage Apollo users, such as create, delete, add users to a group or delete users from a group
13
14 """
15
16 def __init__(self, users_list):
17 self.users_list = users_list
18 self.logger = logging.getLogger(__name__)
19
20
21 def createApolloUser(self):
22 for user in self.users_list:
23 if user['batch'] == "false":
24 subtools.arrow_create_user(user['useremail'], user['firstname'], user['lastname'], user['password'])
25 elif user['batch'] == "true":
26 users = self.parseUserInfoFile(user['format'], user['false_path'])
27 for u in users:
28 if not 'useremail' in u:
29 self.logger.error("Cannot find useremail in the text file, make sure you use the correct header, see README file for examples.")
30 if not 'firstname' in u:
31 self.logger.error("Cannot find firstname in the text file, make sure you use the correct header, see README file for examples.")
32 if not 'lastname' in u:
33 self.logger.error("Cannot find lastname in the text file, make sure you use the correct header, see README file for examples.")
34 if not 'password' in u:
35 self.logger.error("Cannot find password in the text file, make sure you use the correct header, see README file for examples.")
36 subtools.arrow_create_user(u['useremail'], u['firstname'], u['lastname'], u['password'])
37
38
39 def parseUserInfoFile(self, file_format, filename):
40 if file_format == "tab":
41 delimiter = '\t'
42 elif file_format == "csv":
43 delimiter = ','
44 else:
45 self.logger.error("The %s format is not supported!", file_format)
46 with open(filename, 'r') as f:
47 lines = f.readlines()
48 headers = lines[0].split(delimiter)
49 users = []
50 lines = lines[1:]
51 for l in lines:
52 l = l.split(delimiter)
53 info = dict()
54 fields = len(l)
55 for i in range(fields):
56 title = headers[i].rstrip()
57 info[title] = l[i].rstrip()
58 users.append(info)
59 return users
60
61 def deleteApolloUser(self):
62 for user in self.users_list:
63 if user['batch'] == "false":
64 subtools.arrow_delete_user(user['useremail'])
65 elif user['batch'] == "true":
66 users = self.parseUserInfoFile(user['format'], user['false_path'])
67 for u in users:
68 if not 'useremail' in u:
69 self.logger.error("Cannot find useremail in the text file, make sure you use the correct header, see README file for examples.")
70 subtools.arrow_delete_user(u['useremail'])
71
72 def addApolloUserToGroup(self):
73 for user in self.users_list:
74 if user['batch'] == "false":
75 subtools.arrow_add_to_group(user['group'], user['useremail'])
76 elif user['batch'] == "true":
77 users = self.parseUserInfoFile(user['format'], user['false_path'])
78 for u in users:
79 if not 'useremail' in u:
80 self.logger.error("Cannot find useremail in the text file, make sure you use the correct header, see README file for examples.")
81 if not 'group' in u:
82 self.logger.error("Cannot find group in the text file, make sure you use the correct header, see README file for examples.")
83 subtools.arrow_add_to_group(u['group'], u['useremail'])
84
85 def removeApolloUserFromeGroup(self):
86 for user in self.users_list:
87 if user['batch'] == "false":
88 subtools.arrow_remove_from_group(user['group'], user['useremail'])
89 elif user['batch'] == "true":
90 users = self.parseUserInfoFile(user['format'], user['false_path'])
91 for u in users:
92 if not 'useremail' in u:
93 self.logger.error("Cannot find useremail in the text file, make sure you use the correct header, see README file for examples.")
94 if not 'group' in u:
95 self.logger.error("Cannot find group in the text file, make sure you use the correct header, see README file for examples.")
96 subtools.arrow_remove_from_group(u['group'], u['useremail'])
97
98