diff --git a/README.rst b/README.rst index 35c1f301..513376c7 100644 --- a/README.rst +++ b/README.rst @@ -69,6 +69,7 @@ History - Added get_creator for user, group and organisms - Added omitEmptyOrganisms to get_users - Added support for group admins + - Added support for bulk group creation/deletion - Repaired GFF3/Fasta downloading - 3.0.4 - `Fixed bug `__ in deleteFeatures (Thanks `@NeillGibson `__) diff --git a/apollo/groups/__init__.py b/apollo/groups/__init__.py index e09a5ade..336f80a4 100644 --- a/apollo/groups/__init__.py +++ b/apollo/groups/__init__.py @@ -15,11 +15,14 @@ def create_group(self, name): Create a new group :type name: str - :param name: Group name + :param name: Group name (or a list of groups to create) :rtype: dict :return: Group information dictionary """ + if isinstance(name, list): + name = ','.join(name) + data = {'name': name} return self.post('createGroup', data) @@ -28,11 +31,14 @@ def delete_group(self, group): Delete a group :type group: str - :param group: Group name + :param group: Group name (or a list of groups to delete) :rtype: dict :return: an empty dictionary """ + if isinstance(group, list): + group = ','.join(group) + data = { 'name': group, } @@ -146,7 +152,7 @@ def update_organism_permissions(self, group, organism_name, response['permissions'] = json.loads(response['permissions']) return response - def update_membership(self, group_id, users=[]): + def update_membership(self, group_id=None, users=[], memberships=[]): """ Update the group's membership @@ -156,13 +162,25 @@ def update_membership(self, group_id, users=[]): :type users: list of str :param users: List of emails + :type memberships: list + :param memberships: Bulk memberships to update of the form: [ {groupId: ,users: ["user1", "user2", "user3"]}, {groupId:, users: ["user2", "user8"]} (users and groupId will be ignored) + :rtype: dict :return: dictionary of group information """ - data = { - 'groupId': group_id, - 'users': users, - } + + if not group_id and not memberships: + raise Exception("group_id+users or memberships is required") + elif len(memberships) > 0: + data = { + 'memberships': memberships + } + else: + data = { + 'groupId': group_id, + 'users': users, + } + return _fix_group(self.post('updateMembership', data)) def update_group_admin(self, group_id, users=[]): diff --git a/apollo/users/__init__.py b/apollo/users/__init__.py index cf635b6e..438d5201 100644 --- a/apollo/users/__init__.py +++ b/apollo/users/__init__.py @@ -2,6 +2,7 @@ Contains possible interactions with the Apollo Users Module """ import json +import time from apollo.client import Client from apollo.decorators import raise_error_decorator @@ -41,12 +42,14 @@ class UsersClient(Client): def _handle_empty(self, user, response): """Apollo likes to return empty user arrays, even when you REALLY want a user response back... like creating a user.""" - if len(response.keys()) == 0: + found_response = len(response.keys()) > 0 + retries = 0 + while not found_response and retries < 10: response = self.show_user(user) - - # And sometimes show_user can return nothing. Ask again... - if len(response) == 0: - response = self.show_user(user) + found_response = len(response) >= 0 and response != [] + if not found_response and retries > 1: + time.sleep(1) + retries += 1 return response def get_users(self, omit_empty_organisms=False): diff --git a/arrow/config.py b/arrow/config.py index 05f326f1..0b8245cf 100644 --- a/arrow/config.py +++ b/arrow/config.py @@ -23,4 +23,4 @@ def read_global_config(): return DEFAULT_CONFIG with open(config_path) as f: - return yaml.load(f, Loader=yaml.safe_load) + return yaml.safe_load(f)