fZdZddlZddlZddlZddlmZddlmZddlm Z dZ eje Z dZdZd Zdd Zdd Zd Zd Ze dk(rej*eyy)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-datacg}g}t|D]\}\}}}|j}t||tj}|j dd|z|j j} | tvrd| d|dzd} |j| |j|t} |D]} | j| | |fS)NzContent-Dispositionzattachment; filename="%s"z content type z for attachment z may be incorrect!) enumeratereadrsysgetdefaultencoding add_headerget_content_typelowerget_content_typesappendrattach) files sub_messageserrorsifhfilename format_typecontents sub_message content_typemsgcombined_messages ?/usr/lib/python3/dist-packages/cloudinit/cmd/devel/make_mime.pycreate_mime_messagersL F*3E*: )& &B+779xc6L6L6NO  !#>(#K #335;;= 02 2AC MM# K( )%%$% f %%c |jdd\}}t|d||jfS#t$r}t j |d|z|d}~wwxYw)z@Return file content type by reading the first line of the input.:rrzInvalid value for %rN)splitopenstrip ValueErrorargparse ArgumentError)textrres rfile_content_typer,.sj!%C!3,Xs#X|/A/A/CDD $$ (D1  s14 AAAc |stj}t|_t|_|j dddtdgdd|j dd d d d |j ddd d d |S)aBuild 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--attachrrz:z3attach the given file as the specified content-type)desttypeactiondefaultmetavarhelpz-lz --list-types store_trueFz&List support cloud-init content types.)r0r1r3z-fz--forcez$Ignore unknown content-type warnings)r(ArgumentParser__doc__ descriptionEPILOGepilog add_argumentr,)parsers r get_parserr<9s ((* FFM    ' B    5    3  Mr c ttjDcgc]}|r|jddn|c}Scc}w)zReturn a list of cloud-init supported content types. Optionally strip out the leading 'text/' of the type if strip_prefix=True. ztext/)sortedrvaluesreplace) strip_prefixctypes rrrasI -335 +7EMM'2 &E A   sAc|jr%tdjtdyt |j \}}|rh|j rdnd}|D]'}tjj|d|d)tjjd|j sy t|y) 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)rBrWARNINGERRORz: z-Invalid content-types, override with --force r) list_typesprintjoinrrrforcer stderrwrite)nameargsrrlevelerrors r handle_argsrRms  dii)t<=>24::>f !ZZ W 4E JJ  wbr2 3 4 IJzz  r cRtj}tt|SN)r< parse_argsrRNAME)rOs rmainrWs < " " $D tT ""r __main__rT)F)r6r(loggingr email.mime.multipartremail.mime.textrcloudinit.handlersrrV getLogger__name__LOGr8rr,r<rrRrWexitr rrbs{ 7 .$2g!- &.%P  2#  z CHHTVr