def remove_prefix(prefix): """Removes all objects beginning with prefix""" objects_iter = iterlist(prefix) while True: batched_objects = builtin_list(islice(objects_iter, 1000)) if not batched_objects: break remove(batched_objects)
def _split_query(cls, query_func, messages): """Split messages into chunks of size ``_queue_push_limit``. For each chunk, apply *query_func*.""" try: messages_iter = iter(messages) except TypeError: raise TypeError('messages must be an iterable') while True: batched_messages = builtin_list(islice(messages_iter, cls._queue_push_limit)) if not batched_messages: break query_func(batched_messages) return True
def remove(obj_paths, prefix=None): """Removes object(s) named ``effective_obj_paths`` from PiCloud bucket obj_paths can be a single object or a list of objects """ conn = _getcloudnetconnection() if not hasattr(obj_paths, '__iter__'): obj_paths = [obj_paths] obj_paths_iter = obj_paths.__iter__() removed = False while True: paths_to_remove = builtin_list(islice(obj_paths_iter, 1000)) if not paths_to_remove: break full_obj_paths =[ _get_effective_obj_path(obj_path, prefix) for obj_path in paths_to_remove] resp = conn.send_request(_bucket_remove_query, {'name': full_obj_paths}) removed = resp['removed'] return removed