[Zope3-checkins] CVS: Zope3/utilities/fssync - add.py:1.3

Guido van Rossum guido@python.org
Mon, 5 May 2003 17:17:59 -0400


Update of /cvs-repository/Zope3/utilities/fssync
In directory cvs.zope.org:/tmp/cvs-serv30532

Modified Files:
	add.py 
Log Message:
Minor facelift.  No more string module or setPrint().


=== Zope3/utilities/fssync/add.py 1.2 => 1.3 ===
--- Zope3/utilities/fssync/add.py:1.2	Mon May  5 14:01:03 2003
+++ Zope3/utilities/fssync/add.py	Mon May  5 17:17:58 2003
@@ -12,46 +12,38 @@
 #
 ##############################################################################
 
-import string, os
+import os
 
-from common import getZODBPath, getApplicationRoot, getObject
-from common import getObjectAdapter, setPrint, IObjectDirectory
-from zope.app.fssync.classes import FSAddRequest
-from zope.component import getView, queryView
 from zope.app.content.folder import Folder
+from zope.app.fssync.classes import FSAddRequest
 from zope.app.fssync.syncer import toFS, fromFS
-from zope.xmlpickle.xmlpickle import loads
-
+from zope.app.interfaces.fssync import IObjectDirectory
+from zope.component import getView, queryView
 from zope.component.view import viewService
+from zope.xmlpickle.xmlpickle import loads
 
+from common import getZODBPath, getApplicationRoot, getObject, getObjectAdapter
 
-env = os.environ
-
-def add(fspath
-        , dbpath
-        , siteconfpath
-        , newobjecttype
-        , newobjectname):
-
-    """Adds objects to File system
+def add(fspath, dbpath, siteconfpath, newobjecttype, newobjectname):
+    """Add objects to File system
 
-    Creates an object in the file system based on the object type
+    Create an object in the file system based on the object type
     passed with -t  option.
     """
     fspath = os.path.abspath(fspath)
     if not os.path.isdir(fspath):
-        return 'sync [add aborted] : %s is not a directory' %(fspath)
+        return 'sync [add aborted] : %s is not a directory' % fspath
 
     if not os.path.exists(os.path.join(fspath, '@@Zope')):
-        return 'sync [add aborted] : @@Zope administrative folder not found in %s' \
-               %(fspath)
+        return ('sync [add aborted] : '
+                '@@Zope administrative folder not found in %s' % fspath)
 
     objpath = getZODBPath(fspath)
     root = getApplicationRoot(dbpath, siteconfpath)
     container = getObject(objpath, root)
     if container is None:
         container, name, path = getObject(objpath, root, 'Y')
-        fsroot = os.path.abspath(fspath[:string.find(fspath, objpath)])
+        fsroot = os.path.abspath(fspath[:fspath.find(objpath)])
         location = os.path.abspath(os.path.join(fsroot, path[1:]))
         fromFS(container, name, location, 'T')
 
@@ -62,56 +54,51 @@
     if newobjecttype:
         newobjecttype = '.'+newobjecttype
         for file in newobjectname:
-            entries_path = os.path.join(os.path.join(fspath, os.path.dirname(file)),'@@Zope','Entries.xml')
+            entries_path = os.path.join(fspath,
+                                        os.path.dirname(file),
+                                        '@@Zope', 'Entries.xml')
             entries = {}
             if os.path.exists(entries_path):
                 entries = loads(open(entries_path).read())
             if getObject(objpath+'/'+file, root) is not None:
-                setPrint('Object already exist in the ZODB : %s' \
-                          %(os.path.join(fspath,file)))
+                print 'Object already exist in the ZODB :',
+                print os.path.join(fspath, file)
             elif entries.has_key(os.path.basename(file)):
-                setPrint('Object already exist in sandbox : %s' \
-                          %(os.path.join(fspath,file)))
+                print 'Object already exist in sandbox :',
+                print os.path.join(fspath, file)
             else:
                 err = addObject(adapter, fspath, newobjecttype, file, objpath)
                 if err is not None:
-                    setPrint(err)
+                    print err
                     break
     else:
         for file in newobjectname:
-            entries_path = os.path.join(os.path.join(fspath, os.path.dirname(file)),'@@Zope','Entries.xml')
+            entries_path = os.path.join(fspath, os.path.dirname(file),
+                                        '@@Zope', 'Entries.xml')
             entries = {}
             if os.path.exists(entries_path):
                 entries = loads(open(entries_path).read())
             if getObject(objpath+'/'+file, root) is not None:
-                setPrint('Object already exist in the ZODB : %s' \
-                          %(os.path.join(fspath,file)))
+                print 'Object already exist in the ZODB :',
+                print os.path.join(fspath, file)
             elif entries.has_key(os.path.basename(file)):
-                setPrint('Object already exist in sandbox : %s' \
-                          %(os.path.join(fspath,file)))
+                print 'Object already exist in sandbox :',
+                print os.path.join(fspath, file)
             else:
-                newobjecttype = '.'+string.split(file,'.')[-1]
-                err = addObject(adapter
-                                , fspath
-                                , newobjecttype
-                                , file
-                                , objpath)
+                newobjecttype = '.'+file.split('.')[-1]
+                err = addObject(adapter, fspath, newobjecttype, file, objpath)
                 if err is not None:
-                    setPrint(err)
+                    print err
     return None
 
-def addObject(adapter
-              , fspath
-              , newobjecttype
-              , newobjectname
-              , objpath):
-
+def addObject(adapter, fspath, newobjecttype, newobjectname, objpath):
     mode = 'N'
     if IObjectDirectory.isImplementedBy(adapter):
         request = FSAddRequest()
         view = queryView(adapter, newobjecttype, request)
         if view is not None:
-            newobjectpath = os.path.abspath(os.path.join(fspath, newobjectname))
+            newobjectpath = os.path.abspath(os.path.join(fspath,
+                                                         newobjectname))
             if not os.path.exists(os.path.dirname(newobjectpath)):
                 return 'Nothing known about : %s'%(newobjectpath)
             newobject = view.create()
@@ -123,10 +110,12 @@
             keys.sort()
             for sl_no in keys:
                 ob = Folder()
-                toFS(ob, dir_list[sl_no][2], dir_list[sl_no][0], mode, dir_list[sl_no][1])
+                toFS(ob, dir_list[sl_no][2], dir_list[sl_no][0], mode,
+                     dir_list[sl_no][1])
             toFS(newobject, objectname, newobjectpath, mode, objpath)
         else:
-            newobjectpath = os.path.abspath(os.path.join(fspath, newobjectname))
+            newobjectpath = os.path.abspath(os.path.join(fspath,
+                                                         newobjectname))
             if not os.path.exists(newobjectpath):
                 return 'Nothing known about : %s'%(newobjectpath)
             view = getView(adapter, '.', request)
@@ -134,7 +123,7 @@
             objpath = os.path.abspath(objpath+'/'+newobjectname)
             objectname = os.path.basename(newobjectpath)
             newobjectpath = os.path.dirname(newobjectpath)
-            path_list = string.split(newobjectname, os.sep)
+            path_list = newobjectname.split(os.sep)
             if len(path_list) > 1:
                 if path_list[-1] != objectname:
                     return 'Nothing known about : %s'%(path_list[-1])
@@ -144,7 +133,8 @@
                 keys.sort()
                 for sl_no in keys:
                     ob = Folder()
-                    toFS(ob, dir_list[sl_no][2], dir_list[sl_no][0], mode, dir_list[sl_no][1])
+                    toFS(ob, dir_list[sl_no][2], dir_list[sl_no][0], mode,
+                         dir_list[sl_no][1])
             toFS(newobject, objectname, newobjectpath, mode, objpath)
 
     else:
@@ -153,24 +143,27 @@
 
 def createAdminFolder(fspath, objpath, name=None, data={}):
     if name is not None:
-        data[len(string.split(objpath, '/'))] = (fspath, objpath, name)
+        data[len(objpath.split('/'))] = (fspath, objpath, name)
     if not os.path.exists(os.path.join(fspath, '@@Zope')):
-        return createAdminFolder(os.path.dirname(fspath), os.path.dirname(objpath), os.path.basename(fspath))
+        return createAdminFolder(os.path.dirname(fspath),
+                                 os.path.dirname(objpath),
+                                 os.path.basename(fspath))
     return data
 
-def addTypes(dbpath
-             , siteconfpath):
+def addTypes(dbpath, siteconfpath):
     root = getApplicationRoot(dbpath, siteconfpath)
     f = Folder()
     adapter = getObjectAdapter(f)
     request = FSAddRequest()
     allviews = viewService.all()['default']
-    setPrint("\nALL AVAILABLE TYPES")
-    setPrint("====================================================\n")
+    print
+    print "ALL AVAILABLE TYPES"
+    print "===================================================="
+    print
     for view in allviews:
         try:
             if len(view)>1 and view[0] == '.':
                 doc = getView(adapter, view, request).__doc__
-                setPrint(' %s  \n %s \n\n' % (view, doc))
-        except:
+                print ' %s  \n %s \n\n' % (view, doc)
+        except: # XXX which exception are we trying to catch?
             pass