ó
è?F[c           @   s°   d  d l  m Z d  d l m Z d  d l m Z d  d l m Z d  d l Z d  d l	 Z	 d  d l
 Z
 d  d l m Z d e f d „  ƒ  YZ e d	 k r¬ e ƒ  Z e j ƒ  n  d S(
   iÿÿÿÿ(   t   OptionParser(   t
   ServiceDef(   t	   Submitter(   t   ResultProcessorN(   t   StringIOt   BSc           B   s   e  Z d  Z i d d 6d d 6d d 6d d 6d	 d
 6d d 6Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z	 d „  Z
 d „  Z d „  Z RS(   s*   usage: %prog [options] config_file commands#   Clear input queue and output buckett   resets!   Submit local files to the servicet   submits   Start the servicet   starts6   Report on the status of the service buckets and queuest   statuss$   Retrieve output generated by a batcht   retrieves0   List all batches stored in current output_domaint   batchesc         C   s°  d  |  _ t d |  j ƒ |  _ |  j j d d d d d d d ƒ|  j j d	 d
 d d d d d d ƒ|  j j d d d d d d d d ƒ|  j j d d d d d d d d d d ƒ|  j j d d d d d d d d d d ƒ|  j j d d d d d d d d ƒ|  j j d t ƒ |  j j d d d d d d d d  d d! ƒ|  j j d  d" ƒ |  j j d# d$ d d% d d d d& d d' ƒ|  j j d( d) d d d d d d* d d+ ƒd  S(,   Nt   usages   --help-commandst   actiont
   store_truet   destt   help_commandst   helps'   provides help on the available commandss   -as   --access-keyt   storet   typet   strings   your AWS Access Keys   -ss   --secret-keys   your AWS Secret Access Keys   -ps   --patht   paths3   the path to local directory for submit and retrieves   -ks	   --keypairt   keypairs.   the SSH keypair used with launched instance(s)s   -ls   --leavet   leaves>   leave the files (don't retrieve) files during retrieve commands   -ns   --num-instancest   num_instancess"   the number of launched instance(s)i   s   -is   --ignore-dirst   appendt   ignores4   directories that should be ignored by submit commands   -bs
   --batch-idt   batchs1   batch identifier required by the retrieve command(   t   Nonet   service_nameR    t   Usaget   parsert
   add_optiont   set_defaultst   False(   t   self(    (    s/   lib/python2.7/site-packages/boto/services/bs.pyt   __init__)   s,    	$$$$$c         C   s9   d GHx- |  j  j ƒ  D] } d | |  j  | f GHq Wd  S(   Ns
   
Commands:s     %s		%s(   t   Commandst   keys(   R#   t   key(    (    s/   lib/python2.7/site-packages/boto/services/bs.pyt   print_command_helpA   s    c         C   sñ   |  j  j d ƒ } | rk d GHd } | j ƒ  } x- | r^ | d 7} | j | ƒ | j ƒ  } q2 Wd | GHn  |  j  j d ƒ } |  j  j d ƒ } | rí | r± | j | j k r± d  Sd GHd } x" | D] } | d 7} | j ƒ  qÃ Wd	 | GHn  d  S(
   Nt   input_queues   clearing out input queuei    i   s   deleted %d messagest   output_buckett   input_buckets'   delete generated files in output buckets   deleted %d keys(   t   sdt   get_objt   readt   delete_messaget   namet   delete(   R#   t   iqt   it   mt   obt   ibt   k(    (    s/   lib/python2.7/site-packages/boto/services/bs.pyt   do_resetF   s*    	

c         C   s´   |  j  j s |  j j d ƒ n  t j j |  j  j ƒ sT |  j j d |  j  j ƒ n  t |  j ƒ } | j |  j  j d  |  j  j
 d  d  t |  j  j ƒ } d | d GHd | d GHd  S(   Ns   No path provideds   Invalid path (%s)s"   A total of %d files were submittedi   s   Batch Identifier: %si    (   t   optionsR   R   t   errort   ost   existsR   R,   t   submit_pathR   R   t   True(   R#   t   st   t(    (    s/   lib/python2.7/site-packages/boto/services/bs.pyt	   do_submit]   s    c   
      C   se  |  j  j d ƒ } |  j  j d d ƒ } |  j  j d d ƒ } | sU |  j j d ƒ n  t j ƒ  } |  j  j d ƒ s¸ |  j  j d ƒ |  j  j d d | j	 ƒ |  j  j d d	 | j
 ƒ n  t ƒ  } |  j  j | ƒ | j | g ƒ } | d
 } | j d | j ƒ  d |  j j d |  j j d | d | g ƒ } d | GHd | j GHx | j D] }	 d |	 j GHqKWd  S(   Nt   ami_idt   instance_types   m1.smallt   security_groupt   defaults3   ami_id option is required when starting the servicet   Credentialst   aws_access_key_idt   aws_secret_access_keyi    t	   user_datat   key_namet	   max_countt   security_groupss   Starting AMI: %ss0   Reservation %s contains the following instances:s   	%s(   R,   t   getR   R:   t   botot   connect_ec2t   has_sectiont   add_sectiont   setRG   RH   R   t   writet   get_all_imagest   runt   getvalueR9   R   R   t   idt	   instances(
   R#   RB   RC   RD   t   ec2R?   t   rst   imgt   rR3   (    (    s/   lib/python2.7/site-packages/boto/services/bs.pyt   do_starth   s,    	
!	c         C   s³   |  j  j d ƒ } | r3 d | j | j ƒ  f GHn  |  j  j d ƒ } |  j  j d ƒ } | r¯ | ry | j | j k ry d  Sd } x | D] } | d 7} q† Wd | j | f GHn  d  S(   NR)   s7   The input_queue (%s) contains approximately %s messagesR*   R+   i    i   s'   The output_bucket (%s) contains %d keys(   R,   R-   RW   t   countR0   (   R#   R2   R5   R6   t   totalR7   (    (    s/   lib/python2.7/site-packages/boto/services/bs.pyt	   do_status€   s    c         C   s¯   |  j  j s |  j j d ƒ n  t j j |  j  j ƒ sT |  j j d |  j  j ƒ n  |  j  j ss |  j j d ƒ n  t |  j  j |  j ƒ } | j	 |  j  j d |  j  j
 ƒd  S(   Ns   No path provideds   Invalid path (%s)s1   batch identifier is required for retrieve commandt   get_file(   R9   R   R   R:   R;   R<   R   R   R,   t   get_resultsR   (   R#   R?   (    (    s/   lib/python2.7/site-packages/boto/services/bs.pyt   do_retrieveŽ   s    c         C   s`   |  j  j d ƒ } | rL d GH| j d ƒ } x- | D] } d | j GHq3 Wn |  j j d ƒ d  S(   Nt   output_domains   Available Batches:s   ['type'='Batch']s     %ss&   No output_domain specified for service(   R,   R-   t   queryR0   R   R:   (   R#   t   dRZ   t   item(    (    s/   lib/python2.7/site-packages/boto/services/bs.pyt
   do_batches˜   s    c         C   sì   |  j  j ƒ  \ |  _ |  _ |  j j rA |  j ƒ  t j d ƒ n  t |  j ƒ d k ri |  j  j	 d ƒ n  |  j d |  _
 t |  j
 ƒ |  _ |  j d |  _ t |  d |  j ƒ rÑ t |  d |  j ƒ } | ƒ  n |  j  j	 d |  j ƒ d  S(   Ni    i   s$   config_file and command are requiredi   s   do_%ss   command (%s) not recognized(   R   t
   parse_argsR9   t   argsR   R(   t   syst   exitt   lenR:   t   config_fileR   R,   t   commandt   hasattrt   getattr(   R#   t   method(    (    s/   lib/python2.7/site-packages/boto/services/bs.pyt   main¢   s    

(   t   __name__t
   __module__R   R%   R$   R(   R8   RA   R]   R`   Rc   Rh   Rs   (    (    (    s/   lib/python2.7/site-packages/boto/services/bs.pyR      s    

							
	
t   __main__(   t   optparseR    t   boto.services.servicedefR   t   boto.services.submitR   t   boto.services.resultR   RN   Rk   R;   t   boto.compatR   t   objectR   Rt   t   bsRs   (    (    (    s/   lib/python2.7/site-packages/boto/services/bs.pyt   <module>   s   ”	