
    x[hZ                         S r SSKrSSKrSSKrSSKJr  SSKJr  SSKJ	r	  Sr
\R                  " \5      rSrS rS	 rSS
 jrSS jrS rS r\S:X  a  \R*                  " \" 5       5        gg)z0Generate multi-part mime messages for user-data.    N)MIMEMultipart)MIMEText)INCLUSION_TYPES_MAPz	make-mimezUExample: make-mime -a config.yaml:cloud-config -a script.sh:x-shellscript > user-datac                    / n/ n[        U 5       H  u  nu  pEnUR                  5       n[        Xv[        R                  " 5       5      nUR                  SSU-  5        UR                  5       R                  5       n	U	[        5       ;  a  SU	< SUS-   < S3n
UR                  U
5        UR                  U5        M     [        5       nU H  n
UR                  U
5        M     X4$ )NzContent-Dispositionzattachment; filename="%s"zcontent type z for attachment    z may be incorrect!)	enumeratereadr   sysgetdefaultencoding
add_headerget_content_typelowerget_content_typesappendr   attach)filessub_messageserrorsifhfilenameformat_typecontentssub_messagecontent_typemsgcombined_messages               ?/usr/lib/python3/dist-packages/cloudinit/cmd/devel/make_mime.pycreate_mime_messager      s    LF*3E*:&&B+779xc6L6L6NO!#>(#K	
 #335;;=022AC MM#K( +; %$ %%    c                      U R                  SS5      u  p[        US5      XR                  5       4$ ! [         a   n[        R
                  " U SU -  5      UeSnAff = f)z@Return file content type by reading the first line of the input.:r   rzInvalid value for %rN)splitopenstrip
ValueErrorargparseArgumentError)textr   r   es       r   file_content_typer,   .   sf    !%C!3Xs#X/A/A/CDD $$(D1
	s   /2 
AAAc                     U (       d  [         R                  " 5       n [        U l        [        U l        U R                  SSS[        S/ SSS9  U R                  SS	S
SSS9  U R                  SSS
SSS9  U $ )a
  Build or extend and arg parser for make-mime utility.

@param parser: Optional existing ArgumentParser instance representing the
    subcommand which will be extended to support the args of this utility.

@returns: ArgumentParser with proper argument configuration.
z-az--attachr   r   z<file>:<content-type>z3attach the given file as the specified content-type)desttypeactiondefaultmetavarhelpz-lz--list-types
store_trueFz&List support cloud-init content types.)r0   r1   r3   z-fz--forcez$Ignore unknown content-type warnings)r(   ArgumentParser__doc__descriptionEPILOGepilogadd_argumentr,   )parsers    r   
get_parserr<   9   s     ((* FFM
'B  	 5   3   Mr    c           	          [        [        R                  " 5        Vs/ s H  nU (       a  UR                  SS5      OUPM      sn5      $ s  snf )zReturn a list of cloud-init supported content types.  Optionally
strip out the leading 'text/' of the type if strip_prefix=True.
ztext/ )sortedr   valuesreplace)strip_prefixctypes     r   r   r   a   sN      -335	
5 +7EMM'2&EA5	
 	
s   %A	c                    UR                   (       a"  [        SR                  [        SS95      5        g[	        UR
                  5      u  p#U(       at  UR                  (       a  SOSnU H(  n[        R                  R                  U SU S35        M*     [        R                  R                  S5        UR                  (       d  g	[        U5        g)
a(  Create a multi-part MIME archive for use as user-data.  Optionally
   print out the list of supported content types of cloud-init.

Also setup CLI log handlers to report to stderr since this is a development
utility which should be run by a human on the CLI.

@return 0 on success, 1 on failure.

T)rB   r   WARNINGERRORz: z-Invalid content-types, override with --force
r   )

list_typesprintjoinr   r   r   forcer
   stderrwrite)nameargsr   r   levelerrors         r   handle_argsrR   m   s     dii)t<=>24::>!ZZ	WEJJwbr23 

IJzz	
r    c                  R    [        5       R                  5       n [        [        U 5      $ N)r<   
parse_argsrR   NAME)rO   s    r   mainrW      s    <""$DtT""r    __main__rT   )F)r6   r(   loggingr
   email.mime.multipartr   email.mime.textr   cloudinit.handlersr   rV   	getLogger__name__LOGr8   r   r,   r<   r   rR   rW   exit r    r   <module>rb      sw   
 7   
 . $ 2!- &.%P	2#
 zHHTV r    