[Zope3-checkins] CVS: Zope3/src/zope/fssync - fssync.py:1.25
Guido van Rossum
guido@python.org
Sun, 25 May 2003 02:10:06 -0400
Update of /cvs-repository/Zope3/src/zope/fssync
In directory cvs.zope.org:/tmp/cvs-serv19677
Modified Files:
fssync.py
Log Message:
commands.mkarg() doesn't work for Windows. Write our own. :-(
=== Zope3/src/zope/fssync/fssync.py 1.24 => 1.25 ===
--- Zope3/src/zope/fssync/fssync.py:1.24 Tue May 20 15:09:15 2003
+++ Zope3/src/zope/fssync/fssync.py Sun May 25 02:10:03 2003
@@ -27,7 +27,6 @@
import filecmp
import htmllib
import httplib
-import commands
import tempfile
import urlparse
import formatter
@@ -378,8 +377,8 @@
return
print "Index:", target
sys.stdout.flush()
- os.system("diff %s %s %s" %
- (diffopts, commands.mkarg(orig), commands.mkarg(target)))
+ cmd = ("diff %s %s %s" % (diffopts, quote(orig), quote(target)))
+ os.system(cmd)
def dirdiff(self, target, mode=1, diffopts=""):
assert isdir(target)
@@ -495,3 +494,23 @@
extra = fsutil.getextra(target)
if isdir(extra):
self.status(extra, True)
+
+def quote(s):
+ """Helper to put quotes around arguments passed to shell if necessary."""
+ if os.name == "posix":
+ meta = "\\\"'*?[&|()<>`#$; \t\n"
+ else:
+ meta = " "
+ needquotes = False
+ for c in meta:
+ if c in s:
+ needquotes = True
+ break
+ if needquotes:
+ if os.name == "posix":
+ # use ' to quote, replace ' by '"'"'
+ s = "'" + s.replace("'", "'\"'\"'") + "'"
+ else:
+ # (Windows) use " to quote, replace " by ""
+ s = '"' + s.replace('"', '""') + '"'
+ return s