Edit File by line
/home/barbar84/public_h.../wp-conte.../plugins/sujqvwi/ExeBy/smexe_ro.../lib64/python2....
File: commands.py
"""Execute shell commands via os.popen() and return status, output.
[0] Fix | Delete
[1] Fix | Delete
Interface summary:
[2] Fix | Delete
[3] Fix | Delete
import commands
[4] Fix | Delete
[5] Fix | Delete
outtext = commands.getoutput(cmd)
[6] Fix | Delete
(exitstatus, outtext) = commands.getstatusoutput(cmd)
[7] Fix | Delete
outtext = commands.getstatus(file) # returns output of "ls -ld file"
[8] Fix | Delete
[9] Fix | Delete
A trailing newline is removed from the output string.
[10] Fix | Delete
[11] Fix | Delete
Encapsulates the basic operation:
[12] Fix | Delete
[13] Fix | Delete
pipe = os.popen('{ ' + cmd + '; } 2>&1', 'r')
[14] Fix | Delete
text = pipe.read()
[15] Fix | Delete
sts = pipe.close()
[16] Fix | Delete
[17] Fix | Delete
[Note: it would be nice to add functions to interpret the exit status.]
[18] Fix | Delete
"""
[19] Fix | Delete
from warnings import warnpy3k
[20] Fix | Delete
warnpy3k("the commands module has been removed in Python 3.0; "
[21] Fix | Delete
"use the subprocess module instead", stacklevel=2)
[22] Fix | Delete
del warnpy3k
[23] Fix | Delete
[24] Fix | Delete
__all__ = ["getstatusoutput","getoutput","getstatus"]
[25] Fix | Delete
[26] Fix | Delete
# Module 'commands'
[27] Fix | Delete
#
[28] Fix | Delete
# Various tools for executing commands and looking at their output and status.
[29] Fix | Delete
#
[30] Fix | Delete
# NB This only works (and is only relevant) for UNIX.
[31] Fix | Delete
[32] Fix | Delete
[33] Fix | Delete
# Get 'ls -l' status for an object into a string
[34] Fix | Delete
#
[35] Fix | Delete
def getstatus(file):
[36] Fix | Delete
"""Return output of "ls -ld <file>" in a string."""
[37] Fix | Delete
import warnings
[38] Fix | Delete
warnings.warn("commands.getstatus() is deprecated", DeprecationWarning, 2)
[39] Fix | Delete
return getoutput('ls -ld' + mkarg(file))
[40] Fix | Delete
[41] Fix | Delete
[42] Fix | Delete
# Get the output from a shell command into a string.
[43] Fix | Delete
# The exit status is ignored; a trailing newline is stripped.
[44] Fix | Delete
# Assume the command will work with '{ ... ; } 2>&1' around it..
[45] Fix | Delete
#
[46] Fix | Delete
def getoutput(cmd):
[47] Fix | Delete
"""Return output (stdout or stderr) of executing cmd in a shell."""
[48] Fix | Delete
return getstatusoutput(cmd)[1]
[49] Fix | Delete
[50] Fix | Delete
[51] Fix | Delete
# Ditto but preserving the exit status.
[52] Fix | Delete
# Returns a pair (sts, output)
[53] Fix | Delete
#
[54] Fix | Delete
def getstatusoutput(cmd):
[55] Fix | Delete
"""Return (status, output) of executing cmd in a shell."""
[56] Fix | Delete
import os
[57] Fix | Delete
pipe = os.popen('{ ' + cmd + '; } 2>&1', 'r')
[58] Fix | Delete
text = pipe.read()
[59] Fix | Delete
sts = pipe.close()
[60] Fix | Delete
if sts is None: sts = 0
[61] Fix | Delete
if text[-1:] == '\n': text = text[:-1]
[62] Fix | Delete
return sts, text
[63] Fix | Delete
[64] Fix | Delete
[65] Fix | Delete
# Make command argument from directory and pathname (prefix space, add quotes).
[66] Fix | Delete
#
[67] Fix | Delete
def mk2arg(head, x):
[68] Fix | Delete
import os
[69] Fix | Delete
return mkarg(os.path.join(head, x))
[70] Fix | Delete
[71] Fix | Delete
[72] Fix | Delete
# Make a shell command argument from a string.
[73] Fix | Delete
# Return a string beginning with a space followed by a shell-quoted
[74] Fix | Delete
# version of the argument.
[75] Fix | Delete
# Two strategies: enclose in single quotes if it contains none;
[76] Fix | Delete
# otherwise, enclose in double quotes and prefix quotable characters
[77] Fix | Delete
# with backslash.
[78] Fix | Delete
#
[79] Fix | Delete
def mkarg(x):
[80] Fix | Delete
if '\'' not in x:
[81] Fix | Delete
return ' \'' + x + '\''
[82] Fix | Delete
s = ' "'
[83] Fix | Delete
for c in x:
[84] Fix | Delete
if c in '\\$"`':
[85] Fix | Delete
s = s + '\\'
[86] Fix | Delete
s = s + c
[87] Fix | Delete
s = s + '"'
[88] Fix | Delete
return s
[89] Fix | Delete
[90] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function