HEX
Server: Apache
System: Linux msm5694.mjhst.com 3.10.0-1160.119.1.el7.x86_64 #1 SMP Tue Jun 4 14:43:51 UTC 2024 x86_64
User: camjab_ssh (1000)
PHP: 5.3.29
Disabled: NONE
Upload Files
File: //lib/python2.7/site-packages/vdo/utils/Command.pyo
ó
.Åt_c@sªdZddlmZddlmZmZddlZddlZddlZddlZddl	Z	de
fd„ƒYZde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.pytgetExitCode0scCs|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__RRRRRR(((s5/usr/lib/python2.7/site-packages/vdo/utils/Command.pyR"s
			
	
	tCommandcBsŸeZdZeZdZejej	dƒZ
ed„ƒZeeed„ƒ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.pytsetDefaultsqs
	cCs|jdS(s3Returns an identifier (argv[0]) for error messages.i(t_commandList(R((s5/usr/lib/python2.7/site-packages/vdo/utils/Command.pytcommandName€scKsÊ|jddƒ}|jdd	ƒ}|jsE|jdtƒ|_n|jƒ}|dkry|jjdj|ƒƒnyxt|ƒD]}|dkrº|jjdj||ƒƒn|j	dkråd|GH|jj
|ƒn|jrò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&tcommandLinetcounttoutputte((s5/usr/lib/python2.7/site-packages/vdo/utils/Command.pytrun…s<			$	cCs’tt|ƒjƒtj|_t|_tj|_||_	|r…t
jtj
ƒ|_x3|jƒD]\}}||j|<qeWn	d|_dS(N(RRRRR!R-R'RR R#tcopytdeepcopytostenvirontenvtitemsR,(RtcommandListtenvironmenttvartvalue((s5/usr/lib/python2.7/site-packages/vdo/utils/Command.pyR»s		cCsdj|jƒdS(Nt (tjoinR#(R((s5/usr/lib/python2.7/site-packages/vdo/utils/Command.pyRÉsR*cCsåz©|dkr8|jjtdƒj|jƒƒƒ|S|dkrPtdƒn	tdƒ}tdƒj|jƒ|t|ƒƒ}|jj|ƒt||||ƒ‚Wd|jjd|jƒƒ|jjd|jƒƒXdS(	s£Sets the result values of this object. Raises an exception if there was
    an error, or returns the output of the command if there was not.

    Arguments:
      exitCode (int):    the process exit code
      stdout (str):      the standard output
      stderr (str):      the standard error
      logResults (bool): if True, the results will be logged

    Exceptions:
      CommandError: if exitCode is non-zero
    is{0}: command succeededsexit statustsignals{0}: command failed, {1} {2}Nsstdout: sstderr: (R/R0R4RR$tabsRtrstrip(RRRRtfailureTypetstatus((s5/usr/lib/python2.7/site-packages/vdo/utils/Command.pyt
_checkResultsÏs
%$cCs$|jr|jƒn|j}ywt|dtdtdtdtd|jd|jƒ}|j|ƒ\}}|j|j	dj
|ƒdj
|ƒƒSWnˆtk
rØ}|j|jddj
|j
ƒ|jgƒƒnHtk
r}|jjtjƒd	}|r|j|ƒn|‚nXd
S(sóExecute the command once.

    Returns the output of the command.

    Arguments:
      stdin:  If not None, the stream from which the command should take its
              input.

    Exceptions:
      CommandError: if the command failed
    R&RRt	close_fdsRAR'R*s: iN(R'R.R#RRRRAtcommunicateRNt
returncodeRHtOSErrorterrnoR$tstrerrorRRtsplitR?tlinesepR(RR&tcommandtpt
stdoutdatat
stderrdataR;terror((s5/usr/lib/python2.7/site-packages/vdo/utils/Command.pyR3ìs 	"cCs.dj|jr|jnttj|jƒƒS(s.Returns the appropriately quoted command line.RG(RHR'R#tmaptpipestquote(R((s5/usr/lib/python2.7/site-packages/vdo/utils/Command.pyR.
sN(RRRR-RRtloggingt	getLoggerRtmynameR/tclassmethodRR"R$R<R,RRRNR3R.(((s5/usr/lib/python2.7/site-packages/vdo/utils/Command.pyR[s		6		cKs"t||jddƒƒj|S(s`Run a command.

  Returns the output of the command (but see Keyword Arguments).

  Arguments:
    commandList: The command as a list of strings.

  Keyword Arguments:
    environment: A dict of environment variables and their values to use for
                 the command.
    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
  RDN(RtpopR,R<(RCR7((s5/usr/lib/python2.7/site-packages/vdo/utils/Command.pyt
runCommandscKs~d}|jdtƒ}x;|D]3}yt||SWqtk
rQ}|}qXqW|red}n|dk	rz|‚ndS(s$Try each of a series of commands in turn until one succeeds. If all the
  commands fail, give up and raise an exception.

  Arguments:
    commands: A list of command lists

  Keyword Arguments:
    Supports all of the arguments which may be passed to runCommand().

  Returns:
    the output of the first successful command

  Exceptions:
    CommandError: if none of the commands succeeds and the noThrow keyword
                  option is False (or omitted); the error will be the one
                  raised by the last command in the list
  R)N(R,RcR-RdR(tcommandsR7R[R)RWR;((s5/usr/lib/python2.7/site-packages/vdo/utils/Command.pyttryCommandsUntilSuccess+s
	(RRt
subprocessRRR=R_R?R]R5t	ExceptionRtobjectRRdRf(((s5/usr/lib/python2.7/site-packages/vdo/utils/Command.pyt<module>s9µ