Example #1
0
def _delete_objects(bucket: str,
                    keys: List[str],
                    boto3_session: boto3.Session,
                    attempt: int = 1) -> None:
    client_s3: boto3.client = _utils.client(service_name="s3",
                                            session=boto3_session)
    _logger.debug("len(keys): %s", len(keys))
    batch: List[Dict[str, str]] = [{"Key": key} for key in keys]
    res = client_s3.delete_objects(Bucket=bucket, Delete={"Objects": batch})
    deleted: List[Dict[str, Any]] = res.get("Deleted", [])
    for obj in deleted:
        _logger.debug("s3://%s/%s has been deleted.", bucket, obj.get("Key"))
    errors: List[Dict[str, Any]] = res.get("Errors", [])
    internal_errors: List[str] = []
    for error in errors:
        _logger.debug("error: %s", error)
        if "Code" not in error or error["Code"] != "InternalError":
            raise exceptions.ServiceApiError(errors)
        internal_errors.append(_unquote_plus(error["Key"]))
    if len(internal_errors) > 0:
        if attempt > 5:  # Maximum of 5 attempts (Total of 15 seconds)
            raise exceptions.ServiceApiError(errors)
        time.sleep(attempt)  # Incremental delay (linear)
        _delete_objects(bucket=bucket,
                        keys=internal_errors,
                        boto3_session=boto3_session,
                        attempt=(attempt + 1))
Example #2
0
 def _parse_argv(self):
     try:
         check_from = sys.argv[1]
     except IndexError:
         check_from = ''
     if check_from == 'fromsettings':
         self.FROMSETTINGS = True
         self.TITLE = ''
         self.MESSAGE = ''
         return
     self.FROMSETTINGS = False
     try:
         params = dict(arg.split("=") for arg in sys.argv[2].split("&"))
     except IndexError:
         params = {}
     except Exception as e:
         self.LW.log(['no arguments found: %s' % e])
         params = {}
     self.TITLE = _unquote_plus(params.get('title', ''))
     self.MESSAGE = _unquote_plus(params.get('message', ''))
Example #3
0
def unquote_plus(arg):
    return _unquote_plus(arg)