o ckF[D@sddlZddlmZddlmZddlmZmZmZddl m Z ddl m Z m Z ddlZdZdeZd eZd ZGd d d eZdS) N)UploadArchiveErrorJob)compute_hashes_from_fileobjresume_file_uploadWriter)ConcurrentUploader)minimum_part_sizeDEFAULT_PART_SIZEiii@i'c@seZdZeZdeZdZd&ddZddZ dd Z d&d d Z d d Z edfddZ  d'ddZeddZ  d(ddZddZ  d(ddZ    d)ddZddZddZd d!Zd(d"d#Zd$d%ZdS)*Vaultd)) VaultNamenameN)VaultARNarnN) CreationDate creation_dateN)LastInventoryDatelast_inventory_dateN) SizeInBytessizer)NumberOfArchivesnumber_of_archivesrNcCsV||_|r|jD]\}}}||}t|||qdS|jD] \}}}t|||qdSN)layer1ResponseDataElementssetattr)selfr response_data response_name attr_namedefaultvaluer#4/usr/lib/python3/dist-packages/boto/glacier/vault.py__init__5szVault.__init__cCs d|jS)Nz Vault("%s"))rrr#r#r$__repr__?s zVault.__repr__cCs|j|jdS)z/ Delete's this vault. WARNING! N)r delete_vaultrr&r#r#r$deleteBsz Vault.deletecCs,tj||jkr|j||dS|||S)ar Adds an archive to a vault. For archives greater than 100MB the multipart upload will be used. :type file: str :param file: A filename to upload :type description: str :param description: An optional description for the archive. :rtype: str :return: The archive id of the newly created archive ) description)ospathgetsizeSingleOperationThresholdcreate_archive_from_file _upload_archive_single_operation)rfilenamer*r#r#r$upload_archiveHs zVault.upload_archivecCsdt|d!}t|\}}|d|j|j||||}Wd|dS1s)wY|dS)ai Adds an archive to a vault in a single operation. It's recommended for archives less than 100MB :type file: str :param file: A filename to upload :type description: str :param description: A description for the archive. :rtype: str :return: The archive id of the newly created archive rbrN ArchiveId)openrseekrr2r)rr1r*fileobj linear_hash tree_hashresponser#r#r$r0Zs     z&Vault._upload_archive_single_operationcCs$|j|j||}t||d|dS)a Create a new archive and begin a multi-part upload to it. Returns a file-like object to which the data for the archive can be written. Once all the data is written the file-like object should be closed, you can then call the get_archive_id method on it to get the ID of the created archive. :type part_size: int :param part_size: The part size for the multipart upload. :type description: str :param description: An optional description for the archive. :rtype: :class:`boto.glacier.writer.Writer` :return: A Writer object that to which the archive data should be written. UploadId) part_size)rinitiate_multipart_uploadrr)rr<r*r:r#r#r$create_archive_writerps zVault.create_archive_writerc Cs|j}|s#tj|}zt||}Wn tytdwt|d}|j||d}|r1||j  | |}|s:n| |q2| | S)a Create a new archive and upload the data from the given file or file-like object. :type filename: str :param filename: A filename to upload :type file_obj: file :param file_obj: A file-like object to upload :type description: str :param description: An optional description for the archive. :type upload_id_callback: function :param upload_id_callback: if set, call with the upload_id as the only parameter when it becomes known, to enable future calls to resume_archive_from_file in case resume is needed. :rtype: str :return: The archive id of the newly created archive zAFile size of %s bytes exceeds 40,000 GB archive limit of Glacier.r3)r*r<)DefaultPartSizer+r,r-r ValueErrorrr5r> upload_idreadwritecloseget_archive_id) rr1file_objr*upload_id_callbackr< file_sizewriterdatar#r#r$r/s.      zVault.create_archive_from_filecCstdd|dD\}}|d}||}||dkr&|d8}|d8}|d8}||r.Jd||ks6Jd||S)NcSsg|]}t|qSr#)int).0r"r#r#r$ sz5Vault._range_string_to_part_index..-z0upload part start byte is not on a part boundaryz$upload part is bigger than part size)split) range_stringr<start inside_endendlengthr#r#r$_range_string_to_part_indexs  z!Vault._range_string_to_part_indexc Csj||}|d}i}|dD]}||d|}t|dd} | ||<q|s-t|d}t|||||S)a'Resume upload of a file already part-uploaded to Glacier. The resumption of an upload where the part-uploaded section is empty is a valid degenerate case that this function can handle. One and only one of filename or file_obj must be specified. :type upload_id: str :param upload_id: existing Glacier upload id of upload being resumed. :type filename: str :param filename: file to open for resume :type fobj: file :param fobj: file-like object containing local data to resume. This must read from the start of the entire upload, not just from the point being resumed. Use fobj.seek(0) to achieve this if necessary. :rtype: str :return: The archive id of the newly created archive PartSizeInBytesParts RangeInBytesSHA256TreeHash hex_codecr3)list_all_partsrVcodecsdecoder5r) rrAr1rFpart_list_responser< part_hash_map part_desc part_indexpart_tree_hashr#r#r$resume_archive_from_files     zVault.resume_archive_from_filecKs&t|j|jfi|}|||}|S)a Create a new archive from a file and upload the given file. This is a convenience method around the :class:`boto.glacier.concurrent.ConcurrentUploader` class. This method will perform a multipart upload and upload the parts of the file concurrently. :type filename: str :param filename: A filename to upload :param kwargs: Additional kwargs to pass through to :py:class:`boto.glacier.concurrent.ConcurrentUploader`. You can pass any argument besides the ``api`` and ``vault_name`` param (these arguments are already passed to the ``ConcurrentUploader`` for you). :raises: `boto.glacier.exception.UploadArchiveError` is an error occurs during the upload process. :rtype: str :return: The archive id of the newly created archive )rrrupload)rr1r*kwargsuploader archive_idr#r#r$#concurrent_create_archive_from_files z)Vault.concurrent_create_archive_from_filecCsHd|d}|dur ||d<|dur||d<|j|j|}||dS)a Initiate a archive retrieval job to download the data from an archive. You will need to wait for the notification from Amazon (via SNS) before you can actually download the data, this takes around 4 hours. :type archive_id: str :param archive_id: The id of the archive :type description: str :param description: An optional description for the job. :type sns_topic: str :param sns_topic: The Amazon SNS topic ARN where Amazon Glacier sends notification when the job is completed and the output is ready for you to download. :rtype: :class:`boto.glacier.job.Job` :return: A Job object representing the retrieval job. zarchive-retrieval)Typer4NSNSTopic DescriptionJobId)r initiate_jobrget_job)rrh sns_topicr*job_datar:r#r#r$retrieve_archive szVault.retrieve_archivec Csddi}|dur ||d<|dur||d<|dur||d<|dus(|dus(|durLi}|dur5|d|d<|dur@|d|d <|durH||d <||d <|j|j|} | d S) a Initiate a inventory retrieval job to list the items in the vault. You will need to wait for the notification from Amazon (via SNS) before you can actually download the data, this takes around 4 hours. :type description: str :param description: An optional description for the job. :type sns_topic: str :param sns_topic: The Amazon SNS topic ARN where Amazon Glacier sends notification when the job is completed and the output is ready for you to download. :type byte_range: str :param byte_range: Range of bytes to retrieve. :type start_date: DateTime :param start_date: Beginning of the date range to query. :type end_date: DateTime :param end_date: End of the date range to query. :type limit: int :param limit: Limits the number of results returned. :rtype: str :return: The ID of the job rjzinventory-retrievalNrkrlRetrievalByteRangez%Y-%m-%dT%H:%M:%S%Z StartDateEndDateLimitInventoryRetrievalParametersrm)strftimerrnr) rrpr* byte_range start_dateend_datelimitrqrparamsr:r#r#r$retrieve_inventory-s$!zVault.retrieve_inventorycKs|jdi|}||S)a Identical to ``retrieve_inventory``, but returns a ``Job`` instance instead of just the job ID. :type description: str :param description: An optional description for the job. :type sns_topic: str :param sns_topic: The Amazon SNS topic ARN where Amazon Glacier sends notification when the job is completed and the output is ready for you to download. :type byte_range: str :param byte_range: Range of bytes to retrieve. :type start_date: DateTime :param start_date: Beginning of the date range to query. :type end_date: DateTime :param end_date: End of the date range to query. :type limit: int :param limit: Limits the number of results returned. :rtype: :class:`boto.glacier.job.Job` :return: A Job object representing the retrieval job. Nr#)r~ro)rrfjob_idr#r#r$retrieve_inventory_jobds zVault.retrieve_inventory_jobcCs|j|j|S)z This operation deletes an archive from the vault. :type archive_id: str :param archive_id: The ID for the archive to be deleted. )rdelete_archiver)rrhr#r#r$rszVault.delete_archivecCs|j|j|}t||S)z Get an object representing a job in progress. :type job_id: str :param job_id: The ID of the job :rtype: :class:`boto.glacier.job.Job` :return: A Job object representing the job. )r describe_jobrr)rrrr#r#r$ros z Vault.get_jobcs(jj||}fdd|dDS)a Return a list of Job objects related to this vault. :type completed: boolean :param completed: Specifies the state of the jobs to return. If a value of True is passed, only completed jobs will be returned. If a value of False is passed, only uncompleted jobs will be returned. If no value is passed, all jobs will be returned. :type status_code: string :param status_code: Specifies the type of job status to return. Valid values are: InProgress|Succeeded|Failed. If not specified, jobs with all status codes are returned. :rtype: list of :class:`boto.glacier.job.Job` :return: A list of Job objects related to this vault. csg|]}t|qSr#r)rLjdr&r#r$rMsz#Vault.list_jobs..JobList)r list_jobsr)r completed status_coderr#r&r$rs zVault.list_jobscCsZ|j|j|}|d}|r'|jj|j||d}|d|d|d}|sd|d<|S)zAutomatically make and combine multiple calls to list_parts. Call list_parts as necessary, combining the results in case multiple calls were required to get data on all available parts. Marker)markerrXN)r list_partsrextend)rrAresultradditional_resultr#r#r$r\szVault.list_all_partsr)NNNN)NN)NNNNNN)__name__ __module__ __qualname__r r? _MEGABYTEr.rr%r'r)r2r0r>r/ staticmethodrVrdrirrr~rrrorr\r#r#r#r$r )sD     -  (   7 r )r]boto.glacier.exceptionsrboto.glacier.jobrboto.glacier.writerrrrboto.glacier.concurrentrboto.glacier.utilsr r os.pathr+r _GIGABYTEMAXIMUM_ARCHIVE_SIZEMAXIMUM_NUMBER_OF_PARTSobjectr r#r#r#r$s