Mercurial > repos > yating-l > gonramp_apollo_tools
comparison util/subtools.py @ 2:4be6fcac4bf2 draft default tip
planemo upload for repository https://github.com/Yating-L/suite_gonramp_apollo.git commit 5367a00befb467f162d1870edb91f9face72e894
| author | yating-l |
|---|---|
| date | Wed, 29 Nov 2017 15:39:32 -0500 |
| parents | 1da8b9042af4 |
| children |
comparison
equal
deleted
inserted
replaced
| 1:78af01d73add | 2:4be6fcac4bf2 |
|---|---|
| 113 p = _handleExceptionAndCheckCall(array_call) | 113 p = _handleExceptionAndCheckCall(array_call) |
| 114 j = json.loads(p) | 114 j = json.loads(p) |
| 115 if "userId" in j: | 115 if "userId" in j: |
| 116 return j['userId'] | 116 return j['userId'] |
| 117 elif "error" in j: | 117 elif "error" in j: |
| 118 logging.error("User %s already exist", user_email) | 118 logging.error("Got error message: %s", j['error']) |
| 119 raise Exception(j['error']) | 119 exit(-1) |
| 120 | 120 |
| 121 | 121 |
| 122 def arrow_delete_user(user_email): | 122 def arrow_delete_user(user_email): |
| 123 array_call = ['arrow', 'users', 'delete_user', user_email] | 123 array_call = ['arrow', 'users', 'delete_user', user_email] |
| 124 p = _handleExceptionAndCheckCall(array_call) | 124 p = _handleExceptionAndCheckCall(array_call) |
| 125 j = json.loads(p) | 125 j = json.loads(p) |
| 126 if "error" in j: | 126 if "error" in j: |
| 127 raise Exception(j['error']) | 127 logging.error("Got error message: %s", j['error']) |
| 128 exit(-1) | |
| 128 | 129 |
| 129 def arrow_add_to_group(groupname, user_email): | 130 def arrow_add_to_group(groupname, user_email): |
| 130 if not arrow_get_groups(groupname): | 131 if not arrow_get_groups(groupname): |
| 131 arrow_create_group(groupname) | 132 arrow_create_group(groupname) |
| 132 array_call = ['arrow', 'users', 'add_to_group', groupname, user_email] | 133 array_call = ['arrow', 'users', 'add_to_group', groupname, user_email] |
| 133 p = _handleExceptionAndCheckCall(array_call) | 134 p = _handleExceptionAndCheckCall(array_call) |
| 134 j = json.loads(p) | 135 j = json.loads(p) |
| 135 if j != dict(): | 136 if j != dict(): |
| 136 raise Exception("Error add user %s to group %s", user_email, groupname) | 137 logging.error("Error add user %s to group %s. The user doesn't exist", user_email, groupname) |
| 137 | 138 |
| 138 | 139 |
| 139 def arrow_remove_from_group(groupname, user_email): | 140 def arrow_remove_from_group(groupname, user_email): |
| 140 if arrow_get_groups(groupname): | 141 if arrow_get_groups(groupname): |
| 141 array_call = ['arrow', 'users', 'remove_from_group', groupname, user_email] | 142 array_call = ['arrow', 'users', 'remove_from_group', groupname, user_email] |
| 142 p = _handleExceptionAndCheckCall(array_call) | 143 p = _handleExceptionAndCheckCall(array_call) |
| 144 j = json.loads(p) | |
| 145 if j != dict(): | |
| 146 logging.error("Error remove user %s to group %s. The user doesn't exist", user_email, groupname) | |
| 143 else: | 147 else: |
| 144 raise Exception("Group %s doesn't exist. Check if you spell the name correctly", groupname) | 148 logging.error("Group %s doesn't exist. Check if you spell the name correctly", groupname) |
| 145 | 149 |
| 146 def arrow_create_group(groupname): | 150 def arrow_create_group(groupname): |
| 147 if arrow_get_groups(groupname): | 151 if arrow_get_groups(groupname): |
| 148 raise Exception("Group %s already exist. Create a group with another name.", groupname) | 152 logging.error("Group %s already exist. Create a group with another name.", groupname) |
| 149 array_call = ['arrow', 'groups', 'create_group', groupname] | 153 array_call = ['arrow', 'groups', 'create_group', groupname] |
| 150 p = _handleExceptionAndCheckCall(array_call) | 154 p = _handleExceptionAndCheckCall(array_call) |
| 151 | 155 |
| 152 def arrow_get_groups(groupname): | 156 def arrow_get_groups(groupname): |
| 153 array_call = ['arrow', 'groups', 'get_groups'] | 157 array_call = ['arrow', 'groups', 'get_groups'] |
| 177 | 181 |
| 178 def arrow_get_users(user_email): | 182 def arrow_get_users(user_email): |
| 179 array_call = ['arrow', 'users', 'get_users'] | 183 array_call = ['arrow', 'users', 'get_users'] |
| 180 p = _handleExceptionAndCheckCall(array_call) | 184 p = _handleExceptionAndCheckCall(array_call) |
| 181 all_users = json.loads(p) | 185 all_users = json.loads(p) |
| 182 for d in all_users: | 186 for d in all_users: |
| 183 if d['username'] == user_email: | 187 if d['username'] == user_email: |
| 184 return d['userId'] | 188 return d['userId'] |
| 185 logging.error("Cannot find user %s", user_email) | 189 logging.error("Cannot find user %s", user_email) |
| 186 | 190 |
| 187 def arrow_get_organism(organism_name): | 191 def arrow_get_organism(organism_name): |
| 188 array_call= ['arrow', 'organisms', 'get_organisms'] | 192 array_call= ['arrow', 'organisms', 'get_organisms', '--common_name', organism_name] |
| 189 p = _handleExceptionAndCheckCall(array_call) | 193 p = _handleExceptionAndCheckCall(array_call) |
| 190 all_organisms = json.loads(p) | 194 org = json.loads(p) |
| 191 for org in all_organisms: | 195 if 'error' not in org: |
| 192 if org['commonName'] == organism_name: | 196 return org[0]['id'] |
| 193 return org['id'] | 197 else: |
| 194 | 198 logging.debug("Got error msg %s when look for organism %s.", org['error'], organism_name) |
| 195 | 199 |
| 196 def arrow_delete_organism(organism_id): | 200 def arrow_delete_organism(organism_id): |
| 197 array_call = ['arrow', 'organisms', 'delete_organism', organism_id] | 201 array_call = ['arrow', 'organisms', 'delete_organism', str(organism_id)] |
| 198 p = _handleExceptionAndCheckCall(array_call) | 202 p = _handleExceptionAndCheckCall(array_call) |
| 199 return p | 203 return p |
| 200 | 204 |
| 201 def verify_user_login(username, password, apollo_host): | 205 def verify_user_login(username, password, apollo_host): |
| 202 user_info = {'username': username, 'password': password} | 206 user_info = {'username': username, 'password': password} |
