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