ó .Åt_c@sªdZddlmZddlmZmZddlZddlZddlZddlZddl Z de fd„ƒYZ de fd „ƒYZ d „Zd „ZdS( s Command - runs commands and manages their results $Id: //eng/vdo-releases/magnesium/src/python/vdo/utils/Command.py#3 $ i(tLoggeriÿÿÿÿ(tPopentPIPENt CommandErrorcBsDeZdZd„Zd„Zd„Zd„Zd„Zd„ZRS(s˜Exception raised to indicate an error running a command. Arguments: exitCode (int): The exit code of the command stdout (string): The output from the command stderr (string): The error output from the command message (string): The (localized) error text; will be formatted with the remaining arguments args: Arguments for formatting the message cCs|jS(N(t _exitCode(tself((s5/usr/lib/python2.7/site-packages/vdo/utils/Command.pyt getExitCode0scCs|jS(N(t_stderr(R((s5/usr/lib/python2.7/site-packages/vdo/utils/Command.pytgetStandardError4scCs||jƒ||jƒdS(sLog the outputs of the failed command which generated this exception. Arguments: logMethod (callable): The method to log with N(t_stdoutR(Rt logMethod((s5/usr/lib/python2.7/site-packages/vdo/utils/Command.pyt logOutputs8s cGs|j|Œ|_dS(sèSet the error message in this exception. Arguments: message (string): The (localized) message text; will be formatted with *args args: Values to pass to the format of message N(tformatt_message(Rtmessagetargs((s5/usr/lib/python2.7/site-packages/vdo/utils/Command.pyt setMessageBscGsBtt|ƒjƒ||_||_||_|j||ƒdS(N(tsuperRt__init__RR RR(RtexitCodetstdouttstderrRR((s5/usr/lib/python2.7/site-packages/vdo/utils/Command.pyROs    cCs|jS(N(R (R((s5/usr/lib/python2.7/site-packages/vdo/utils/Command.pyt__str__Ws( t__name__t __module__t__doc__RRR RRR(((s5/usr/lib/python2.7/site-packages/vdo/utils/Command.pyR"s    tCommandcBsŸeZdZeZdZejej dƒZ e d„ƒZ e eed„ƒZ d„Zd„Zd d„Zd„Zdd d d „Zd „Zd „ZRS(sVCommand encapsulates shell commands, runs them, and manages the result. Attributes: noRun (bool): if True, don't run the command, and always succeed shell (bool): if True, run this command using shell -c verbose (int): if > 0, print commands to stdout before executing them _commandList (list): command and its arguments is.CommandcCs|jS(s+Returns True iff Commands default to noRun.(t defaultNoRun(tcls((s5/usr/lib/python2.7/site-packages/vdo/utils/Command.pyt noRunModekscCs1|r||_t|_n|r-||_ndS(s±Sets the verbose and noRun default values. Arguments: verbose: (boolean) If True, operate verbosely. noRun: (boolean) If True, do not actually execute. N(RtTruetdefaultVerbose(RtverbosetnoRun((s5/usr/lib/python2.7/site-packages/vdo/utils/Command.pyt setDefaultsqs   cCs |jdS(s3Returns an identifier (argv[0]) for error messages.i(t _commandList(R((s5/usr/lib/python2.7/site-packages/vdo/utils/Command.pyt commandName€scKsÊ|jddƒ}|jdd ƒ}|jsE|jdtƒ|_n|jƒ}|dkry|jjdj|ƒƒnyxt|ƒD]}|dkrº|jjdj||ƒƒn|j dkråd|GH|jj |ƒn|j ròd Sy3|j |ƒ}|jd tƒr |j ƒS|SWq‰tk rŽ}||dkr~|dkru|jtd ƒ|jƒ|ƒn|‚ntjdƒq‰Xq‰WWn/tk rÅ}|jd tƒr¼d S|‚nXd S(sRun a command. Returns the output of running the command. Arguments: noThrow: If True, will return an empty string instead of throwing on error. retries: The number of times to try the command before giving up. Defaults to 1. shell: Indicate that this is a shell command stdin: If not None, the stream from which the command should take its input, defaults to None. strip: If True, strip leading and trailing whitespace from the command output before returning it. Exceptions: CommandError: if the command failed and noThrow is False tretriesitstdintshellsWaiting for '{0}'s ... {0}/{1}is Ntstrips {0}: timed out after {1} secondstnoThrowt(tgettNoneR'tFalset_getCommandLinetlogtdebugR trangeR tinfoR!t_executeR(RRt_R$ttimetsleep(RtkwargsR%R&t commandLinetcounttoutputte((s5/usr/lib/python2.7/site-packages/vdo/utils/Command.pytrun…s<      $  cCs’tt|ƒjƒtj|_t|_tj|_||_ |r…t j t j ƒ|_x3|jƒD]\}}||j|s     9µ