[Zope3-checkins] CVS: Zope3/utilities/fssync - update.py:1.4
Guido van Rossum
guido@python.org
Mon, 5 May 2003 17:51:00 -0400
Update of /cvs-repository/Zope3/utilities/fssync
In directory cvs.zope.org:/tmp/cvs-serv2733
Modified Files:
update.py
Log Message:
Facelift. Get rid of string module.
=== Zope3/utilities/fssync/update.py 1.3 => 1.4 ===
--- Zope3/utilities/fssync/update.py:1.3 Mon May 5 17:20:53 2003
+++ Zope3/utilities/fssync/update.py Mon May 5 17:51:00 2003
@@ -12,7 +12,7 @@
#
##############################################################################
-import string, os, commands
+import os, commands
from common import getZODBPath, createTempfile, getObject
from common import mapFS, traverseFS, checkConflictData, getApplicationRoot
@@ -22,9 +22,7 @@
env = os.environ
-def update(fspath
- , dbpath
- , siteconfpath):
+def update(fspath, dbpath, siteconfpath):
"""Updates the checked out objects in the file system from a ZODB
updates the files in the sandbox based on the file system path given
@@ -41,8 +39,9 @@
fspath = os.path.join(fspath, module)
updateSettings(fspath, root)
else:
- return 'sync [update aborted] : @@Zope administrative folder not found in %s' \
- %(fspath)
+ return ('sync [update aborted] : '
+ '@@Zope administrative folder not found in %s' %
+ fspath)
else:
updateSettings(fspath, root)
else:
@@ -57,16 +56,17 @@
else:
admin_dir = os.path.join(os.path.dirname(fspath),'@@Zope')
if not os.path.exists(admin_dir):
- return 'sync [update aborted] : @@Zope administrative folder not found in %s'\
- %(fspath)
+ return ('sync [update aborted] : '
+ '@@Zope administrative folder not found in %s' %
+ fspath)
mappings = {}
mapping_paths = {}
mapping_paths.update(traverseFS(fspath, mapping_paths))
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 checkConflictData(sandbox_path, zopedb_path):
print 'C', zopedb_path[1:]
else:
@@ -75,55 +75,54 @@
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 ' ' in dir:
+ fmt_sandbox_path = os.path.join(fmt_sandbox_path,
+ "'"+dir+"'")
else:
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 ' ' in dir:
+ 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)
- diff3_cmd = """diff3 -a %s %s %s""" %(fmt_sandbox_path
- , fmt_original_path
- , zopedb_temp_file)
+ diff3_cmd = "diff3 -a %s %s %s" % (fmt_sandbox_path,
+ fmt_original_path,
+ zopedb_temp_file)
diff3_res = commands.getoutput(diff3_cmd)
- if len(string.strip(diff3_res))>1:
- diffverify=string.strip(diff3_res[0:5])
- if diffverify=='====1':
+ if len(diff3_res.strip()) > 1:
+ diffverify = diff3_res[0:5].strip()
+ if diffverify == '====1':
print 'M', zopedb_path[1:]
- elif diffverify=='====2':
+ elif diffverify == '====2':
doUpdate('C', ob, zopedb_path, sandbox_path)
print 'M', zopedb_path[1:]
- elif diffverify=='====3':
+ elif diffverify == '====3':
doUpdate('U', ob, zopedb_path, sandbox_path)
- elif diffverify=='====':
- diff3_cmd = """diff3 -a -m %s %s %s;echo $?""" %(fmt_sandbox_path
- , fmt_original_path
- , zopedb_temp_file)
+ elif diffverify == '====':
+ diff3_cmd = ("diff3 -a -m %s %s %s; echo $?" %
+ (fmt_sandbox_path, fmt_original_path,
+ zopedb_temp_file))
diff3_res = commands.getoutput(diff3_cmd)
- diff3_res = string.replace(diff3_res
- , zopedb_temp_file
- , zopedb_path)
- if diff3_res[-1]=='0':
+ diff3_res = diff3_res.replace(zopedb_temp_file,
+ zopedb_path)
+ if diff3_res[-1] == '0':
print 'Merging changes in', zopedb_path[1:]
else:
print 'C Merging changes in', zopedb_path[1:]
f = open(sandbox_path, 'w')
- f.write(string.strip(diff3_res[:-1]))
+ f.write(diff3_res[:-1].strip())
f.close()
- doUpdate('C'
- , ob
- , zopedb_path
- , sandbox_path)
+ doUpdate('C', ob, zopedb_path, sandbox_path)
if os.path.exists(zopedb_temp_file):
os.remove(zopedb_temp_file)
@@ -131,24 +130,16 @@
if os.path.isdir(fspath):
objectroot = getZODBPath(fspath)
fsroot = getFSRoot(fspath)
- mapFS(mappings
- , root
- , objectroot
- , fsroot)
-
-
+ mapFS(mappings, root, objectroot, fsroot)
-def doUpdate(mode
- , ob
- , zopedb_path
- , sandbox_path):
+def doUpdate(mode, ob, zopedb_path, sandbox_path):
"""Updates data
"""
sandbox_path = os.path.dirname(sandbox_path)
- ob_name = string.split(zopedb_path,'/')[-1]
- if mode=='U':
+ ob_name = zopedb_path.split('/')[-1]
+ if mode == 'U':
if ob is not None:
toFS(ob, ob_name, sandbox_path)
- elif mode=='C':
+ elif mode == 'C':
if ob is not None:
toFS(ob, ob_name, sandbox_path, mode)