0 &Äa '¡Dgp1ã @sdZddlZddlZddlZddlZddlmZddlmZddl m Z m Z m Z ddl mZe e¡Ze ddd g¡Zd d „ZGd d „d eƒZe e ee efdœdd„Zddddddddddœ e eee ee efedœdd„Zd!dd„Zd"e edœdd„Zdd„Zd#dd „ZdS)$z9Common utility functions for interacting with subprocess.éN)ÚENOEXEC)Ú TextIOWrapper)ÚListÚOptionalÚUnion)Ú performanceÚ SubpResultÚstdoutÚstderrcCsÎg}g}g}|D]‚}t|tƒrR|ddur8|dd…}qˆ|d|krˆ| d|¡n6t|tƒrx| |›d�¡sˆ| |¡n| t|ƒ¡q| |¡q|r®t d||d |¡¡|rÊt dj |d |¡d�ƒ‚|S) a�Ensure user-provided commands start with base_command; warn otherwise. Each command is either a list or string. Perform the following: - If the command is a list, pop the first element if it is None - If the command is a list, insert base_command as the first element if not present. - When the command is a string not starting with 'base-command', warn. Allow flexibility to provide non-base-command environment/config setup if needed. @commands: List of commands. Each command element is a list or string. @return: List of 'fixed up' commands. @raise: TypeError on invalid config item type. rNéú z Non-%s commands in %s config: %sÚ zHInvalid {name} config. These commands are not a string or list: {errors})ÚnameÚerrors) Ú isinstanceÚlistÚinsertÚstrÚ startswithÚappendÚLOGÚwarningÚjoinÚ TypeErrorÚformat)Z base_commandZcommandsÚwarningsrZfixed_commandsZcommand©rú2/usr/lib/python3.9/site-packages/cloudinit/subp.pyÚprepend_base_commands:      ü þÿrc@sHeZdZdZdZd dd„Zdd„Zd eee feee fd œd d „Z dS)ÚProcessExecutionErrorzr%(description)s Command: %(cmd)s Exit code: %(exit_code)s Reason: %(reason)s Stdout: %(stdout)s Stderr: %(stderr)sú-Nc Cs|p|j|_|r||_n|s,|tkr,d|_nd|_t|tƒr@|n|j|_|sb|durZ|jn||_n | |¡|_|sˆ|dur€|jn||_ n | |¡|_ |pœ|j|_ |rª||_ |j |  |j¡|  |j¡|  |j¡|  |j ¡|  |j¡|  |j ¡dœ}t ||¡dS)Nz(Exec format error. Missing #! in script?z'Unexpected error while running command.)Ú descriptionÚcmdÚ exit_coder r Úreason)Ú empty_attrr"r!rrÚintr#r Ú _indent_textr r$ÚerrnoÚ MESSAGE_TMPLÚ_ensure_stringÚIOErrorÚ__init__) Úselfr r r#r"r!r$r(Úmessagerrrr,Qs4  ÿ         úzProcessExecutionError.__init__cCst|tƒr| ¡S|S)z1 if data is bytes object, decode ©rÚbytesÚdecode)r-Útextrrrr*€sz$ProcessExecutionError._ensure_stringé)r2ÚreturncCs>t|tƒs$| d¡ ddd|¡S| d¡ ddd|¡S)z¼ indent text on all but the first line, allowing for easy to read output remove any newlines at end of text first to prevent unneeded blank line in output r r ó ó )rr0ÚrstripÚreplace)r-r2Z indent_levelrrrr'†s z"ProcessExecutionError._indent_text)NNNNNNN)r3) Ú__name__Ú __module__Ú __qualname__r)r%r,r*rrr0r'rrrrrFs"ÿø /ÿ  þr)ÚargscCs@|D]6}t|tƒst|dƒst d|¡t|d|›�d�‚qdS)zùcheck argument types to ensure that subp() can run the argument Throw a user-friendly exception which explains the issue. args: list of arguments passed to subp() raises: ProcessExecutionError with information explaining the issue ÚencodezRunning invalid command: %szRunning invalid command: )r"r$N)rr0Úhasatt