f2 BdZddlZddlZddlZddlZddlZddlmZddlm Z ddl m Z m Z ejeZej dddgZd ZGd d eZd e e ee effd Zdddddddddd d e eee ee efdefdZddZddZdZddZy)z9Common utility functions for interacting with subprocess.N)ENOEXEC) TextIOWrapper)ListUnion SubpResultstdoutstderrcg}g}g}|D]}t|tr&|d|dd}nl|d|k7rd|jd|nQt|tr&|j |ds-|j |n|j t||j ||r't jd||dj||r+tdj|dj||S) aEnsure 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})nameerrors) isinstancelistinsertstr startswithappendLOGwarningjoin TypeErrorformat) base_commandcommandswarningsrfixed_commandscommands 0/usr/lib/python3/dist-packages/cloudinit/subp.pyprepend_base_commandr!s "H FN ' gt $qz!!!"+|+q,/  %%%a&89( MM#g, ' g& ' /   IIh    BBH&!$))F*;CIC  cXeZdZdZdZ d dZdZ d deee fdeee ffdZ y) ProcessExecutionErrorzr%(description)s Command: %(cmd)s Exit code: %(exit_code)s Reason: %(reason)s Stdout: %(stdout)s Stderr: %(stderr)s-Nc 4|xs |j|_|r||_n|s|tk(rd|_nd|_t |t r|n |j|_|s| |jn||_n|j||_|s| |jn||_ n|j||_ |xs |j|_ |r||_ |j|j|j|j|j|j|j |j|j|j|j|j|jdz}tj||y)Nz(Exec format error. Missing #! in script?z'Unexpected error while running command.) descriptioncmd exit_coderr reason) empty_attrr(r'rrintr)r _indent_textrr*errno MESSAGE_TMPL_ensure_stringIOError__init__) selfrr r)r(r'r*r.messages r r2zProcessExecutionError.__init__PsQ)$// *D u/ID HD $Is3I -3^$//DK++F3DK-3^$//DK++F3DK/ DJ##..t/?/?@&&txx0,,T^^<))$++6))$++6))$++6 '   w'r"cFt|tr|jS|S)z1 if data is bytes object, decode rbytesdecode)r3texts r r0z$ProcessExecutionError._ensure_strings!+4 7t{{}ATAr"r9returnct|ts'|jdjddd|zzS|jdjddd|zzS)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   )rr7rstripreplace)r3r9 indent_levels r r-z"ProcessExecutionError._indent_textsZ$&;;t$,,T4# :L3LM M{{5!))% 9L1LMMr")NNNNNNN)) __name__ __module__ __qualname__r/r+r2r0rrr7r-r"r r$r$Ese J -(^B56 N#u*% N sEz  Nr"r$argsc|D]E}t|trt|dr!tj d|t |d|y)zcheck 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)rr7hasattrrrr$)rF components r raise_on_invalid_commandrKsO 9e, 80L KK5t <'#