o .&a)@sddlZddlZddlZddlZddlZddlmZddlmZddlm Z ddl m Z ddl m Z ddlmZdZd eZGd d d e ZdS) N)datetime) ClientError)six)validate_s3_location) BasicCommand)ZIP_COMPRESSION_MODEic @seZdZdZdZddddddd dd dd d d d dddd d d ddddddddddgZddZddZdd Ze j d,d!d"Z d#d$Z d%d&Z d'd(Zd)d*Zd+S)-PushpushaBundles and uploads to Amazon Simple Storage Service (Amazon S3) an application revision, which is a zip archive file that contains deployable content and an accompanying Application Specification file (AppSpec file). If the upload is successful, a message is returned that describes how to call the create-deployment command to deploy the application revision from Amazon S3 to target Amazon Elastic Compute Cloud (Amazon EC2) instances.zapplication-namez--application-name TzdRequired. The name of the AWS CodeDeploy application to be associated with the application revision.)namesynopsisrequired help_textz s3-locationz!--s3-location s3:///aRequired. Information about the location of the application revision to be uploaded to Amazon S3. You must specify both a bucket and a key that represent the Amazon S3 bucket name and the object key name. Content will be zipped before uploading. Use the format s3://\/\zignore-hidden-files store_trueFzOptional. Set the --ignore-hidden-files flag to not bundle and upload hidden files to Amazon S3; otherwise, set the --no-ignore-hidden-files flag (the default) to bundle and upload hidden files to Amazon S3.)r actiondefault group_namerzno-ignore-hidden-files)r rrrsourcez--source .zOptional. The location of the deployable content and the accompanying AppSpec file on the development machine to be zipped and uploaded to Amazon S3. If not specified, the current directory is used.)r r rr descriptionz--description zOptional. A comment that summarizes the application revision. If not specified, the default string "Uploaded by AWS CLI 'time' UTC" is used, where 'time' is the current system time in Coordinated Universal Time (UTC).)r r rcCsH|||jjd|j|j|jd|_|jjd|jd|_||dS)N codedeploy) region_name endpoint_urlverifys3)r) _validate_args_session create_clientregionr verify_sslrr_push)self parsed_argsparsed_globalsr$G/usr/lib/python3/dist-packages/awscli/customizations/codedeploy/push.py _run_mainms zPush._run_maincCs@t|d|jr|jrtd|jsdt|_dSdS)N s3_locationzKYou cannot specify both --ignore-hidden-files and --no-ignore-hidden-files.zUploaded by AWS CLI {0} UTC) rignore_hidden_filesno_ignore_hidden_files RuntimeErrorrformatrutcnow isoformat)r!r"r$r$r%r{s  zPush._validate_argsc Cs||j|j<}z|||}|ddd|_d|vr"|d|_Wnty<}z td|j|j t |fd}~wwWdn1sGwY| |d|vr\d |j}nd}d |j |j|j|}tjd |j|dS) NETag" VersionIdz!Failed to upload '%s' to '%s': %sversionz ,version={0}z;--s3-location bucket={0},key={1},bundleType=zip,eTag={2}{3}zTo deploy with this revision, run: aws deploy create-deployment --application-name {0} {1} --deployment-group-name --deployment-config-name --description ) _compressrr( _upload_to_s3replaceeTagr2 Exceptionr*r'str_register_revisionr+bucketkeysysstdoutwriteapplication_name)r!paramsbundleupload_responseeversion_strings3location_stringr$r$r%r sV    z Push._pushc cs(tj|}tjj|dg}tdu}tj|ddd}z[d}tj |ddD]B\}} } |rAdd | D} d d | D| dd<| D]&} tj|| } tj| } | t |d d} | |krbd}| | | t qCq(|stt d |W|n|w|VWddS1swYdS) Nz appspec.ymlzw+bwT) allowZip64F)topdowncSg|] }|ds|qSr startswith).0fnr$r$r% z"Push._compress..cSrIrJrK)rMdnr$r$r%rOrPz{0} was not found)ospathabspathsepjointempfile TemporaryFilezipfileZipFilewalklenr>rr*r+close)r!rr( source_path appspec_pathtfzfcontains_appspecrootdirsfilesrNfilenamearcnamer$r$r%r3s6   "zPush._compresscCs6||}|tkr|jj|j|j|dS||||S)N)BucketKeyBody) _bundle_sizeMULTIPART_LIMITr put_objectr:r;_multipart_upload_to_s3)r!r@rAsize_remainingr$r$r%r4s zPush._upload_to_s3cCs"|dd|}|d|S)Nr)seektell)r!rAsizer$r$r%rls  zPush._bundle_sizec Cs|jj|j|jd}|d}zId}g}|d|dkrI|t}|jj|j|j||t |d} | || dd|d7}|t |8}|dks|jj |j|j|d|id WSt yp} z |jj|j|j|d | d} ~ ww) N)rirjUploadIdrRr)rirjru PartNumberrkr.)rvr.Parts)rirjruMultipartUpload)rirjru)rcreate_multipart_uploadr:r;rrreadrm upload_partrBytesIOappendr]complete_multipart_uploadrabort_multipart_upload) r!r@rArpcreate_response upload_idpart_nummultipart_listdatarBrCr$r$r%rosP   zPush._multipart_upload_to_s3cCsJd|j|jd|jdd}d|vr|j|dd<|jj|j||jddS)NS3zip)r:r; bundleTyper6) revisionType s3Locationr2r)applicationNamerevisionr)r:r;r6r2rregister_application_revisionr?r)r!r@rr$r$r%r9s  zPush._register_revisionN)F)__name__ __module__ __qualname__NAME DESCRIPTION ARG_TABLEr&rr contextlibcontextmanagerr3r4rlror9r$r$r$r%r !sX     ?,  'r )rSr<rZrXrrbotocore.exceptionsr awscli.compatr&awscli.customizations.codedeploy.utilsrawscli.customizations.commandsrrONE_MBrmr r$r$r$r%s