ó
č?F[c           @   s{   d  d l  Z d  d l Z d  d l Z d  d l Z d  d l Z d  d l Z d  d l m Z d e j j	 j
 f d     YZ
 d S(   iĸĸĸĸN(   t   getpwnamt	   Installerc           B   sb   e  Z d  Z d d d d d d d
 d  Z d   Z d   Z d   Z d   Z d   Z	 d	   Z
 RS(   s5   
    Base Installer class for Ubuntu-based AMI's
    t   *t   rootc
      	   C   sĖ   | d k r$ t  t j d   } n  | d k rH t  t j d   } n  t d | d  }
 |	 r x4 |	 j   D]# \ } } |
 j d | | f  qn Wn  |
 j d | | | | | | | f  |
 j   d S(	   sÐ   
        Write a file to /etc/cron.d to schedule a command
            env is a dict containing environment variables you want to set in the file
            name will be used as the name of the file
        t   randomi<   i   s   /etc/cron.d/%st   ws   %s=%s
s   %s %s %s %s %s %s %s
N(   t   strR   t	   randranget   opent   itemst   writet   close(   t   selft   namet   commandt   minutet   hourt   mdayt   montht   wdayt   whot   envt   fpt   keyt   value(    (    sE   lib/python2.7/site-packages/boto/pyami/installers/ubuntu/installer.pyt   add_cron"   s    &c         C   sq   t  j j d |  } t | d  } | j |  | j   t  j | t j t j	 Bt j
 B |  j d |  d S(   s7   
        Add this file to the init.d directory
        s   /etc/init.dR   s!   /usr/sbin/update-rc.d %s defaultsN(   t   ost   patht   joinR   R
   R   t   chmodt   statt   S_IREADt   S_IWRITEt   S_IEXECt   run(   R   t   fileR   t   f_patht   f(    (    sE   lib/python2.7/site-packages/boto/pyami/installers/ubuntu/installer.pyt   add_init_script3   s    
!c         C   s   t  j j d | | f  t j j d  sH |  j d d t d t n  t d d  } | j	 d | | f  | j
   | t j | <d	 S(
   s   
        Add an environemnt variable
        For Ubuntu, the best place is /etc/environment.  Values placed here do
        not need to be exported.
        s   Adding env variable: %s=%ss   /etc/environment.origs)   cp /etc/environment /etc/environment.origt   notifyt   exit_on_errors   /etc/environmentt   as   
%s="%s"N(   t   botot   logt   infoR   R   t   existsR"   t   FalseR   R
   R   t   environ(   R   R   R   R   (    (    sE   lib/python2.7/site-packages/boto/pyami/installers/ubuntu/installer.pyt   add_env>   s    
c         C   s   |  j  d |  d  S(   Ns   /etc/init.d/%s stop(   R"   (   R   t   service_name(    (    sE   lib/python2.7/site-packages/boto/pyami/installers/ubuntu/installer.pyt   stopL   s    c         C   s   |  j  d |  d  S(   Ns   /etc/init.d/%s start(   R"   (   R   R1   (    (    sE   lib/python2.7/site-packages/boto/pyami/installers/ubuntu/installer.pyt   startO   s    c         C   s!   |  j  d |  t |  } | S(   s3   
        Create a user on the local system
        s   useradd -m %s(   R"   R    (   R   t   usert   usr(    (    sE   lib/python2.7/site-packages/boto/pyami/installers/ubuntu/installer.pyt   create_userR   s    c         C   s
   t   d S(   s>   
        This is the only method you need to override
        N(   t   NotImplementedError(   R   (    (    sE   lib/python2.7/site-packages/boto/pyami/installers/ubuntu/installer.pyt   installZ   s    N(   t   __name__t
   __module__t   __doc__t   NoneR   R&   R0   R2   R3   R6   R8   (    (    (    sE   lib/python2.7/site-packages/boto/pyami/installers/ubuntu/installer.pyR      s   					(   t   boto.pyami.installersR*   R   t   os.pathR   R   t   pwdR    t   pyamit
   installersR   (    (    (    sE   lib/python2.7/site-packages/boto/pyami/installers/ubuntu/installer.pyt   <module>   s   