
    x[h@	                         d dl Z d dlZd dlmZ d dlmZ d dlmZmZm	Z	  e j                  e      Zedede	diZd Zd	 Zd
 Z G d de      Zy)    N)util)Handler)
PER_ALWAYSPER_INSTANCEPER_ONCEzper-bootzper-instancezper-oncec                     dt         |     }|S )Nztext/x-shellscript-)path_map)freq	mime_types     N/usr/lib/python3/dist-packages/cloudinit/handlers/shell_script_by_frequency.pyget_mime_type_by_frequencyr      s    %htn%56I    c                 X    t         |    }t        j                  j                  ||      }|S )z]Return the frequency-specific subfolder for a given frequency constant
    and parent folder.)r	   ospathjoin)r
   scripts_dirfreqPathfolders       r   get_script_folder_by_frequencyr      s&     ~HWW\\+x0FMr   c                    t         j                  j                  |       }t        j                  |      }t        ||      }t         j                  j                  ||      }t        j                  |      }t        j                  ||d       y)z|Given a filename, a payload, a frequency, and a scripts folder, write
    the payload to the correct frequency-specific pathi  N)	r   r   basenamer   clean_filenamer   r   dos2unix
write_file)script_pathpayload	frequencyr   filenamer   r   s          r   write_script_by_frequencyr    #   sf     ww,H""8,H+I{CF77<<)DmmG$GOOD'5)r   c                       e Zd ZdZd Zd Zy)ShellScriptByFreqPartHandlerz=Common base class for the frequency-specific script handlers.c                     t        j                  | t               t        |      g| _        || _        |j                  d      | _        d|v r|j                  |d         | _        y y )Nscriptsr   )r   __init__r   r   prefixesscript_frequency	get_cpathr   )selfr'   paths_kwargss       r   r%   z%ShellScriptByFreqPartHandler.__init__1   s^    z*34DEF 0 ??95G#$w}/EFD $r   c                     |Wt         j                  j                  |      }t        j                  |      }t        ||| j                  | j                         y y )N)r   r   r   r   r   r    r'   r   )r)   datactyper   r   r   r   s          r   handle_partz(ShellScriptByFreqPartHandler.handle_part9   sN    "ww''4H**84H%Wd&;&;T=M=M #r   N)__name__
__module____qualname____doc__r%   r/    r   r   r"   r"   .   s    GGr   r"   )loggingr   	cloudinitr   cloudinit.handlersr   cloudinit.settingsr   r   r   	getLoggerr0   LOGr	   r   r   r    r"   r4   r   r   <module>r;      s\     	  & A Ag! 
.j
*7 r   