def remove_source(obj): """ Remove file data from amazon. :param obj: content object. """ obj_fields = utils.getAWSFields(obj) for field, value in obj_fields: aws_utility = getUtility(IAWSFileClientUtility) if not aws_utility.active(): raise AWSSourceRemoveError("Could not delete remote source. " "To be able to delete object properly, " "please activate AWS storage") as3client = aws_utility.getFileClient() if hasattr(value, 'source_id') and value.source_id: try: as3client.delete(value.source_id) if IAWSImageField.providedBy(field): field.removeScales(obj) except FileClientRemoveError, e: raise AWSSourceRemoveError(e.message)
def clone_source(obj): """ Creates copy of file data on amazon. :param obj: content object. :param remove_origin: if set to true origin source will be removed. :type remove_origin: boolean """ def copy_source(aws_file, obj): old_sid = aws_file.source_id new_sid = utils.replace_source_uid(old_sid, obj.UID()) if old_sid == new_sid: # source already cloned return as3client = aws_utility.getFileClient() as3client.copy_source(old_sid, new_sid) aws_file.source_id = new_sid obj_fields = utils.getAWSFields(obj) for field, value in obj_fields: aws_utility = getUtility(IAWSFileClientUtility) if not aws_utility.active(): raise AWSSourceCopyError("Could not copy remote source. " "To be able to copy object properly, " "please activate AWS storage") if hasattr(value, 'source_id') and \ value.source_id: try: copy_source(value, obj) if IAWSImageField.providedBy(field): for n in field.getAvailableSizes(obj).keys(): copy_source(field.getScale(obj, scale=n), obj) except (FileClientCopyError, FileClientRemoveError), e: raise AWSSourceCopyError(e.message)