[Zope3-checkins] CVS: Zope3/utilities/fssync - commit.py:1.4
Guido van Rossum
guido@python.org
Mon, 5 May 2003 17:33:15 -0400
Update of /cvs-repository/Zope3/utilities/fssync
In directory cvs.zope.org:/tmp/cvs-serv390
Modified Files:
commit.py
Log Message:
Facelift; get rid of string module.
=== Zope3/utilities/fssync/commit.py 1.3 => 1.4 ===
--- Zope3/utilities/fssync/commit.py:1.3 Mon May 5 17:20:53 2003
+++ Zope3/utilities/fssync/commit.py Mon May 5 17:33:15 2003
@@ -12,7 +12,7 @@
#
##############################################################################
-import os, string, commands
+import os, commands
from zope.app.fssync.syncer import fromFS
from common import getZODBPath, createTempfile, getObject
@@ -22,10 +22,7 @@
env = os.environ
-def commit(fspath
- , dbpath
- , siteconfpath
- , mode=None):
+def commit(fspath, dbpath, siteconfpath, mode=None):
"""Checks in from file system to ZODB
Saves the unconflict files in ZODB as Zope objects from the
@@ -48,13 +45,13 @@
else:
mapping_paths = traverseFS(fspath, {})
for sandbox_path in mapping_paths.keys():
- original_path = string.strip(mapping_paths[sandbox_path][0])
- zopedb_path = string.strip(mapping_paths[sandbox_path][1])
+ original_path = mapping_paths[sandbox_path][0].strip()
+ zopedb_path = mapping_paths[sandbox_path][1].strip()
if isNewObject(sandbox_path):
- fsroot = os.path.abspath(sandbox_path[:string.find(sandbox_path
- , zopedb_path)])
+ fsroot = sandbox_path[:sandbox_path.find(zopedb_path)]
+ fsroot = os.path.abspath(fsroot)
path = ''
- for object in string.split(zopedb_path,'/')[1:]:
+ for object in zopedb_path.split('/')[1:]:
path = os.path.join(path,object)
newobjpath = os.path.join(fsroot,path)
if isNewObject(newobjpath):
@@ -65,48 +62,48 @@
vpath = newobjpath
break
else:
- if string.find(sandbox_path,vpath)==-1:
+ if sandbox_path.find(vpath) < 0:
fmt_sandbox_path = ''
fmt_original_path = ''
- for dir in string.split(sandbox_path,os.sep):
- if string.find(dir, ' ')<>-1:
- fmt_sandbox_path = os.path.join(fmt_sandbox_path
- , '\''+dir+'\'')
+ for dir in sandbox_path.split(os.sep):
+ if dir.find(' ') >= 0:
+ fmt_sandbox_path = os.path.join(fmt_sandbox_path,
+ "'"+dir+"'")
else:
- fmt_sandbox_path = os.path.join(fmt_sandbox_path
- , dir)
+ fmt_sandbox_path = os.path.join(fmt_sandbox_path,
+ dir)
- for dir in string.split(original_path,os.sep):
- if string.find(dir, ' ')<>-1:
- fmt_original_path = os.path.join(fmt_original_path
- , '\''+dir+'\'')
+ for dir in original_path.split(os.sep):
+ if dir.find(' ') >= 0:
+ fmt_original_path = os.path.join(fmt_original_path,
+ "'"+dir+"'")
else:
- fmt_original_path = os.path.join(fmt_original_path
- , dir)
+ fmt_original_path = os.path.join(fmt_original_path,
+ dir)
fmt_sandbox_path = os.sep + fmt_sandbox_path
fmt_original_path = os.sep + fmt_original_path
ob = getObject(zopedb_path, root)
zopedb_temp_file = createTempfile(ob, zopedb_path)
- diff_cmd1 = """diff -q -b %s %s;echo $?""" \
- %(fmt_original_path, zopedb_temp_file)
+ diff_cmd1 = ("diff -q -b %s %s; echo $?" %
+ fmt_original_path, zopedb_temp_file)
diff_res1 = commands.getoutput(diff_cmd1)
isConflict = int(diff_res1[-1])
- diff_cmd2 = """diff -q -b %s %s;echo $?""" \
- %(fmt_sandbox_path, fmt_original_path)
+ diff_cmd2 = ("diff -q -b %s %s; echo $?" %
+ fmt_sandbox_path, fmt_original_path)
diff_res2 = commands.getoutput(diff_cmd2)
isCommitRequired = int(diff_res2[-1])
if checkConflictData(sandbox_path, zopedb_path):
isConflict = 1
if isConflict:
- msg = "%s Conflict, Uptodate checkin failed" \
- %(zopedb_path)
+ msg = ("%s Conflict, Uptodate checkin failed" %
+ zopedb_path)
print msg
else:
if not (isCommitRequired == isConflict == 0):
- msg = "%s <-- %s" \
- %(zopedb_path, string.split(zopedb_path,'/')[-1])
+ msg = ("%s <-- %s" %
+ (zopedb_path, zopedb_path.split('/')[-1]))
err = doCommit(sandbox_path, root)
if err is not None:
return err
@@ -121,35 +118,33 @@
def doCommit(fspath, root, mode=None):
container = ''
objpath = getZODBPath(fspath)
- objname = string.split(objpath, '/')[-1]
- path = string.split(objpath, '/')[:-1]
+ objname = objpath.split('/')[-1]
+ path = objpath.split('/')[:-1]
for item in path:
if item:
- container = container +'[\''+item+'\']'
+ container = container +"['"+item+"']"
try:
if container:
container=eval('root'+container)
else:
container=root
- except:
- return 'sync [commit aborted] : invalid object path --- %s' \
- %(objpath)
+ except: # XXX which exception are we trying to catch?
+ return 'sync [commit aborted] : invalid object path --- %s' % objpath
- #copying to ZODB
+ # Copying to ZODB
fromFS(container, objname , os.path.dirname(fspath), mode)
get_transaction().commit()
if mode is None:
- #copying to original
+ # Copying to original
f = open(fspath, 'r')
data = f.read()
f.close()
- original_path = os.path.join(os.path.dirname(fspath)
- ,'@@Zope'
- ,'Original'
- ,os.path.basename(fspath))
+ original_path = os.path.join(os.path.dirname(fspath),
+ '@@Zope', 'Original',
+ os.path.basename(fspath))
f = open(original_path, 'w')
- f.write(string.strip(data))
+ f.write(data.strip())
f.close()
return None