܍~cdZddlZddlZddlmZddlmZddlmZddl m Z ddl m Z dZ eje Zd Zd Zd Zdd ZddZdZdZedkrejedSdS)z0Generate multi-part mime messages for user-data.N) MIMEMultipart)MIMEText)log)addLogHandlerCLI)INCLUSION_TYPES_MAPz make-mimezUExample: make-mime -a config.yaml:cloud-config -a script.sh:x-shellscript > user-datac g}g}t|D]\}\}}}|}t||tj}|dd|z|} | tvr!d| d|dzd} | | | |t} |D]} | | | |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_messager!s-L F*3E*:*: ) )& &B+7799xc6L6N6NOO  !#>(#K   #3355;;== 022 2 2 2q1uuu&C MM#   K(((($%%$$$$ f %%c |dd\}}t|d||fS#t$r}t j|d|z|d}~wwxYw)z@Return file content type by reading the first line of the input.:r rzInvalid value for %rN)splitopenstrip ValueErrorargparse ArgumentError)textrres r file_content_typer..s!%C!3!3,Xs##X|/A/A/C/CDD $ (D1   s=A A( A##A(c  |stj}t|_t|_|dddtdgdd|dd d d d |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.)r2r3r5z-fz--forcez$Ignore unknown content-type warnings)r*ArgumentParser__doc__ descriptionEPILOGepilog add_argumentr.)parsers r get_parserr>9s +(** FFM    ' B      5    3  Mr"Fc\tfdtjDS)zReturn a list of cloud-init supported content types. Optionally strip out the leading 'text/' of the type if strip_prefix=True. cDg|]}r|ddn|S)ztext/)replace).0ctype strip_prefixs r z%get_content_types..fsA   +7 AEMM'2 & & &E   r")sortedrvaluesrEs`r rrasF     ,355     r"ctt|jr tjn tj|jr2tdtddSt|j \}}|r]|j rdnd}|D]'}tj|d|d(tjd|j sd St|dS) 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.  TrIrWARNINGERRORz: z-Invalid content-types, override with --force r )rLOGdebugrDEBUGrL list_typesprintjoinrr!rforcer stderrwrite)nameargsrrlevelerrors r handle_argsr[msStzB#))s{CCC  dii)t<<<==>>>q24:>>f !Z4 W 4 4E J  22222 3 3 3 3 IJJJz 1  1r"clt}tt|SN)r> parse_argsr[NAME)rXs r mainr`s' << " " $ $D tT " ""r"__main__r])F)r8r*r email.mime.multipartremail.mime.textr cloudinitrcloudinit.cmd.develrcloudinit.handlersrr_ getLoggerrNr:r!r.r>rr[r`__name__exitr"r rks1 76 ......$$$$$$000000222222cmD- &&&,%%%%P       4###  z CHTTVVr"