o ckF[@sddlmZddlmZddlmZddlmZddlZddl Z ddl Z ddl m Z Gddde Zed kr?eZedSdS) ) OptionParser) ServiceDef) Submitter)ResultProcessorN)StringIOc@sjeZdZdZdddddddZd d Zd d Zd dZddZddZ ddZ ddZ ddZ ddZ dS)BSz*usage: %prog [options] config_file commandz#Clear input queue and output bucketz!Submit local files to the servicezStart the servicez6Report on the status of the service buckets and queuesz$Retrieve output generated by a batchz0List all batches stored in current output_domain)resetsubmitstartstatusretrievebatchescCsd|_t|jd|_|jjddddd|jjddd d d d |jjd dd d dd |jjddd d ddd|jjddd d ddd|jjdddddd|jjdd|jjdd d d d!d"d|jjd#d$|jjd%d&d'd d(d)d|jjd*d+d d d,d-ddS).N)usagez--help-commands store_true help_commandsz'provides help on the available commands)actiondesthelpz-az --access-keystorestringzyour AWS Access Key)rtyperz-sz --secret-keyzyour AWS Secret Access Keyz-pz--pathpathz3the path to local directory for submit and retrieve)rrrrz-kz --keypairkeypairz.the SSH keypair used with launched instance(s)z-lz--leaveleavez>leave the files (don't retrieve) files during retrieve commandF)rz-nz--num-instances num_instancesz"the number of launched instance(s))rz-iz --ignore-dirsappendignorez4directories that should be ignored by submit commandz-bz --batch-idbatchz1batch identifier required by the retrieve command) service_namerUsageparser add_option set_defaults)selfr%2/usr/lib/python3/dist-packages/boto/services/bs.py__init__)s>  z BS.__init__cCs2td|jD] }td||j|fq dS)Nz Commands:z %s %s)printCommandskeys)r$keyr%r%r&print_command_helpAszBS.print_command_helpcCs|jd}|r)tdd}|}|r#|d7}|||}|std||jd}|jd}|r\|rA|j|jkrAdStdd}|D] }|d7}|qItd |dSdS) N input_queuezclearing out input queuerrzdeleted %d messages output_bucket input_bucketz'delete generated files in output bucketzdeleted %d keys)sdget_objr(readdelete_messagenamedelete)r$iqimobibkr%r%r&do_resetFs.      z BS.do_resetc Cs|jjs |jdtj|jjs|jd|jjt|j}||jjd|jj ddd|jj}t d|dt d|ddS)NNo path providedInvalid path (%s)Tz"A total of %d files were submittedrzBatch Identifier: %sr) optionsrr!errorosexistsrr0 submit_pathrr()r$str%r%r& do_submit]s   z BS.do_submitc Cs|jd}|jdd}|jdd}|s|jdt}|jds>|jd|jdd|j |jdd |j t }|j || |g}|d }|j||jj|jj||gd }td |td |j|jD] } td| jqrdS)Nami_id instance_typezm1.smallsecurity_groupdefaultz3ami_id option is required when starting the service Credentialsaws_access_key_idaws_secret_access_keyr) user_datakey_name max_countrHsecurity_groupszStarting AMI: %sz0Reservation %s contains the following instances:z %s)r0getr!r@boto connect_ec2 has_section add_sectionsetrLrMrwriteget_all_imagesrungetvaluer?rrr(id instances) r$rGrHrIec2rDrsimgrr7r%r%r&do_starths0        z BS.do_startcCs|jd}|rtd|j|f|jd}|jd}|rA|r+|j|jkr+dSd}|D]}|d7}q/td|j|fdSdS)Nr-z7The input_queue (%s) contains approximately %s messagesr.r/rrz'The output_bucket (%s) contains %d keys)r0r1r(r\countr4)r$r6r9r:totalr;r%r%r& do_statuss    z BS.do_statuscCsx|jjs |jdtj|jjs|jd|jj|jjs&|jdt|jj|j}|j |jj|jj ddS)Nr=r>z1batch identifier is required for retrieve command)get_file) r?rr!r@rArBrrr0 get_resultsr)r$rDr%r%r& do_retrieves  zBS.do_retrievecCsN|jd}|rtd|d}|D] }td|jqdS|jddS)N output_domainzAvailable Batches:z['type'='Batch']z %sz&No output_domain specified for service)r0r1r(queryr4r!r@)r$dr_itemr%r%r& do_batchess  z BS.do_batchescCs|j\|_|_|jjr|tdt|jdkr#|j d|jd|_ t |j |_ |jd|_ t|d|j rJt|d|j }|dS|j d|j dS)Nrz$config_file and command are requiredrzdo_%szcommand (%s) not recognized)r! parse_argsr?argsrr,sysexitlenr@ config_filerr0commandhasattrgetattr)r$methodr%r%r&mains      zBS.mainN)__name__ __module__ __qualname__r r)r'r,r<rFrbrerhrmryr%r%r%r&rs$  r__main__)optparserboto.services.servicedefrboto.services.submitrboto.services.resultrrSrqrA boto.compatrobjectrrzbsryr%r%r%r&s