12 """Escape the given command line argument for the shell."""
13 #XXX There is a *lot* more that we should escape here.
14 return arg
.replace('"', r
'\"')
18 r
"""Join an arglist to a string appropriate for running.
20 >>> _joinArgv(['foo', 'bar "baz'])
26 cmdstr
+= '"%s"' % _escapeArg(arg
)
28 cmdstr
+= _escapeArg(arg
)
30 if cmdstr
.endswith(' '): cmdstr
= cmdstr
[:-1] # strip trailing space
35 """Prepare and run the given arg vector, 'argv', and return the
36 results. Returns (<stdout lines>, <stderr lines>, <return value>).
37 Note: 'argv' may also just be the command string.
39 if type(argv
) in (types
.ListType
, types
.TupleType
):
43 if sys
.platform
.startswith('win'):
44 i
, o
, e
= os
.popen3(cmd
)
52 # IOError is raised iff the spawned app returns -1. Go
59 p
= popen2
.Popen3(cmd
, 1)
60 i
, o
, e
= p
.tochild
, p
.fromchild
, p
.childerr
66 retval
= (p
.wait() & 0xFF00) >> 8
67 if retval
> 2**7: # 8-bit signed 1's-complement conversion
69 return output
, error
, retval
72 def _rmtreeOnError(rmFunction
, filePath
, excInfo
):
73 if excInfo
[0] == OSError:
74 # presuming because file is read-only
75 os
.chmod(filePath
, 0777)
80 shutil
.rmtree(dirname
, 0, _rmtreeOnError
)