[BZR Tree!] Updated shelf

John Arbash Meinel john at arbash-meinel.com
Fri Jun 17 16:19:08 BST 2005


Aaron Bentley wrote:

> John Arbash Meinel wrote:
>
> >     print >>sys.stderr, "Reapplying shelved patches"
> >-    pipe = os.popen('patch -d %s -s -p1' % root, 'w')
> >+    pipe = os.popen('patch -d "%s" -s -p1' % root, 'w')
>
>
> This is better, but it's still not quite right, because root may contain
> quote marks or characters that may be interpreted by the shell.
>
> To prevent the shell from evaluating the input, use a sequence instead
> of a string.
>
> pipe = os.popen(('patch', '-d', root, '-s', '-p1'), 'w')
>
> This doesn't work for os.system.  The simplest thing I've found is to
> prepend a backslash to every character, e.g.
>
> os.system(" ".join(["".join(['\\'+g for g in f]) for f in args]))
>
> Aaron

I didn't realize that popen supported sequences. Good to know.
Actually, if you wanted to do it correct, you would use the new
"subprocess" module, which does the right thing for all of these cases.
It is comes with python2.4, but there is a package you can install for
2.3 (for non win32 it is pure python, so could be bundled. for win32,
though, you have to compile a small extension).

John
=:->

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 253 bytes
Desc: OpenPGP digital signature
Url : https://lists.ubuntu.com/archives/bazaar/attachments/20050617/7e08c1eb/attachment.pgp 


More information about the bazaar mailing list