o .&a@sddlZddlZddlZddlZddlZddlZddlmZddlm Z ddl m Z Gddde Z ddZ d d ZGd d d eZdS) N) S3Transfer) BasicCommand)human_readable_sizec@sHeZdZdZdZddddddddd dd dd d d dgZddZdS)UploadBuildCommandz upload-buildz#Upload a new build to AWS GameLift.nameTzThe name of the build)rrequired help_textz build-versionzThe version of the buildz build-rootz8The path to the directory containing the build to uploadzoperating-systemFz&The operating system the build runs onc Csh|jjd|j|j|jd}t|jstj d|jdS|j |j d}|j r,|j |d<|j di|}|dd}|j|d }|d }|d d }|d d } |d} |d} |d} |jjd| | | |j|jd} t| }z-td|\}}t||j|j||| t|d|jdddWt|t|n t|t|wtj d|j|fdS)Ngamelift) region_name endpoint_urlverifyzHFail to upload %s. The build root directory is empty or does not exist. )NameVersionOperatingSystemBuildBuildId)rUploadCredentialsStorageLocationBucketKey AccessKeyIdSecretAccessKey SessionTokens3)aws_access_key_idaws_secret_access_keyaws_session_tokenr r z%s.zipz Uploading :)label)callbackz6Successfully uploaded %s to AWS GameLift Build ID: %s r)_session create_clientregionr verify_sslvalidate_directory build_rootsysstderrwriter build_versionoperating_system create_buildrequest_upload_credentialsrtempfilemkstemp zip_directory upload_fileProgressPercentageoscloseremovestdout)selfargsparsed_globalsgamelift_clientcreate_build_kwargsresponsebuild_idupload_credentialsbucketkey access_key secret_key session_token s3_clients3_transfer_mgrfdtemporary_zipfiler!r!L/usr/lib/python3/dist-packages/awscli/customizations/gamelift/uploadbuild.py _run_main)sp          zUploadBuildCommand._run_mainN)__name__ __module__ __qualname__NAME DESCRIPTION ARG_TABLErJr!r!r!rIrs" rc Cstj|}t|dS}t|dtjd}t|,}t |D]\}}}|D]}tj ||} tj | |} | | | q'q Wdn1sIwYWddSWddS1sawYdS)NwbwT) r4pathabspathopenzipfileZipFile ZIP_DEFLATED contextlibclosingwalkjoinrelpathr*) zipfile_name source_rootfzip_filezfrootdirsfilesfilename full_path relative_pathr!r!rIr1ns"   "r1cCs,|sdSt|D] \}}}|rdSq dS)NFT)r4r[)r_rSrdrer!r!rIr&{sr&c@seZdZdddZddZdS)r3NcCsD||_||_|jdur|j|_ttj||_d|_t |_ dS)Nr) _filename_labelfloatr4rSgetsize_size _seen_so_far threadingLock_lock)r8rfrr!r!rI__init__s zProgressPercentage.__init__cCs|j=|j|7_|jdkr8|j|jd}tjd|jt|jt|j|ftjWddSWddS1sCwYdS)Nrdz %s %s / %s (%.2f%%)) rqrnrmr(r7r*rjrflush)r8 bytes_amount percentager!r!rI__call__s    "zProgressPercentage.__call__)N)rKrLrMrrrwr!r!r!rIr3s  r3)rorYr4r/r(rV s3transferrawscli.customizations.commandsrawscli.customizations.s3.utilsrrr1r&objectr3r!r!r!rIs    T