3 \�me� � @ sP d dl Z d dlZd dlmZmZmZ d dlmZ e je �Z G dd� dej�ZdS )� N)�handlers�subp�util)� PER_ALWAYSc @ s* e Zd ZdgZdd� Zdd� Zdd� ZdS ) �BootHookPartHandlerz#cloud-boothookc K s2 t jj| t� |jd�| _d | _|r.|j� | _d S )NZ boothooks)r �Handler�__init__r Z get_ipath�boothook_dir�instance_idZget_instance_id)�self�pathsZ datasourceZ_kwargs� r �/usr/lib/python3.6/boot_hook.pyr s zBootHookPartHandler.__init__c C sJ t j|�}tjj| j|�}t jt j|�| jd d�}t j ||j � d� |S )Nr )�prefixi� )r Zclean_filename�os�path�joinr Zstrip_prefix_suffixZdos2unix�prefixesZ write_file�lstrip)r �payload�filename�filepath�contentsr r r �_write_part s zBootHookPartHandler._write_partc C s� |t jkrd S | j||�}yBtjj� }| jd k r>t| j�|d<