o
    x[h"  ã                   @   s‚   d dl Z d dlZd dlZd dlmZmZ e  e¡ZG dd„ de	ƒZ
G dd„ dƒZG dd„ dƒZG d	d
„ d
eƒZG dd„ deƒZdS )é    N)ÚsubpÚutilc                   @   s   e Zd ZdS )ÚCustomScriptNotFoundN)Ú__name__Ú
__module__Ú__qualname__© r   r   ú[/usr/lib/python3/dist-packages/cloudinit/sources/helpers/vmware/imc/config_custom_script.pyr      s    r   c                   @   s*   e Zd ZdZdZej ee¡ZdZ	dZ
dS )ÚCustomScriptConstantz/root/.customizationzcustomize.shz)/.guest-customization-post-reboot-pendingzpost-customize-guest.shN)r   r   r   ÚCUSTOM_TMP_DIRÚCUSTOM_SCRIPT_NAMEÚosÚpathÚjoinÚCUSTOM_SCRIPTÚPOST_CUSTOM_PENDING_MARKERÚPOST_CUSTOM_SCRIPT_NAMEr   r   r   r	   r
      s    r
   c                   @   s   e Zd Zdd„ Zdd„ ZdS )ÚRunCustomScriptc                 C   s    || _ || _tj ||¡| _d S ©N)Ú
scriptnameÚ	directoryr   r   r   Ú
scriptpath)Úselfr   r   r   r   r	   Ú__init__!   s   zRunCustomScript.__init__c                 C   sp   t j | j¡std| j ƒ‚t tj¡ t	 
dtj¡ t | jtj¡ t tj¡ dd¡}tjtj|dd� d S )Nz3Script %s not found!! Cannot execute custom script!zCopying custom script to %súÚ id  )Úmode)r   r   Úexistsr   r   r   Ú
ensure_dirr
   r   ÚLOGÚdebugr   ÚcopyÚload_text_fileÚreplaceÚ
write_file)r   Úcontentr   r   r	   Úprepare_script&   s&   ÿÿÿÿþ
ÿzRunCustomScript.prepare_scriptN)r   r   r   r   r&   r   r   r   r	   r       s    r   c                   @   s   e Zd Zdd„ ZdS )ÚPreCustomScriptc                 C   s&   t  d¡ |  ¡  t tjdg¡ dS )z7Executing custom script with precustomization argument.z"Executing pre-customization scriptÚprecustomizationN)r   r    r&   r   r
   r   )r   r   r   r	   Úexecute>   s   
zPreCustomScript.executeN)r   r   r   r)   r   r   r   r	   r'   =   s    r'   c                       s$   e Zd Z‡ fdd„Zdd„ Z‡  ZS )ÚPostCustomScriptc                    s.   t t| ƒ ||¡ || _tj |tj¡| _	d S r   )
Úsuperr*   r   ÚccScriptsDirr   r   r   r
   r   ÚccScriptPath)r   r   r   r,   ©Ú	__class__r   r	   r   F   s
   
ÿzPostCustomScript.__init__c                 C   sn   |   ¡  t d| j¡ t tj | j	t
j¡| j¡ t | j¡}t | j|jtjB ¡ t d¡ t t
j¡ dS )z¤
        This method copy the post customize run script to
        cc_scripts_per_instance directory and let this
        module to run post custom script.
        z'Copying post customize run script to %sz*Creating post customization pending markerN)r&   r   r    r-   r   r!   r   r   r   r   r
   r   ÚstatÚchmodÚst_modeÚS_IEXECÚinfoÚensure_filer   )r   Ústr   r   r	   r)   M   s   ÿü
zPostCustomScript.execute)r   r   r   r   r)   Ú__classcell__r   r   r.   r	   r*   E   s    r*   )Úloggingr   r0   Ú	cloudinitr   r   Ú	getLoggerr   r   Ú	Exceptionr   r
   r   r'   r*   r   r   r   r	   Ú<module>   s   
