[Zope-Checkins] CVS: Zope2 - ObjectManager.py:1.121.4.13

Andreas Jung andreas@dhcp165.digicool.com
Mon, 9 Apr 2001 13:01:15 -0400


Update of /cvs-repository/Zope2/lib/python/OFS
In directory yetix:/work/zope/Zope2/lib/python/OFS

Modified Files:
      Tag: zope-2_3-branch
	ObjectManager.py 
Log Message:
merged ftp changes into 2.3 branch



--- Updated File ObjectManager.py in package Zope2 --
--- ObjectManager.py	2001/04/03 15:22:55	1.121.4.12
+++ ObjectManager.py	2001/04/09 17:01:13	1.121.4.13
@@ -102,14 +102,16 @@
 import App.Common
 from AccessControl import getSecurityManager
 from zLOG import LOG, ERROR
-import sys
+import string
+import sys,fnmatch,copy
+import translationset
 
 import XMLExportImport
 customImporters={
     XMLExportImport.magic: XMLExportImport.importXML,
     }
 
-bad_id=ts_regex.compile('[^a-zA-Z0-9-_~\,\. ]').search #TS
+bad_id=ts_regex.compile('[^a-zA-Z0-9-_~\,\. ]' ).search # TS
 
 # Global constants: __replaceable__ flags:
 NOT_REPLACEABLE = 0
@@ -269,8 +271,10 @@
         return default
 
     def _setObject(self,id,object,roles=None,user=None, set_owner=1):
+
         v=self._checkId(id)
         if v is not None: id=v
+ 
         try:    t=object.meta_type
         except: t=None
 
@@ -583,6 +587,7 @@
     
     def manage_FTPlist(self, REQUEST):
         "Directory listing for FTP"
+
         out=()
 
         # check to see if we are being acquiring or not
@@ -595,11 +600,32 @@
             ob=ob.aq_parent
         
         files=self.objectItems()
+
+        # recursive ride through all subfolders (ls -R) (ajung)
+
+        if REQUEST.environ.get('FTP_RECURSIVE',0) == 1:
+
+            all_files = copy.copy(files)
+            for f in files:
+                if f[1].meta_type == "Folder":
+                    all_files.extend(findChilds(f[1]))
+                else:
+                    all_files.append(f)
+            
+            files = all_files
+
         try:
             files.sort()
         except AttributeError:
             files=list(files)
             files.sort()
+
+        # Perform globbing on list of files (ajung)
+           
+        globbing = REQUEST.environ.get('GLOBBING','')
+        if globbing is not None:
+            files = filter(lambda x,g=globbing: fnmatch.fnmatch(x[0],g) , files)
+
             
         if not (hasattr(self,'isTopLevelPrincipiaApplicationObject') and
                 self.isTopLevelPrincipiaApplicationObject):
@@ -608,10 +634,11 @@
             # Note that we have to tolerate failure here, because
             # Broken objects won't stat correctly. If an object fails
             # to be able to stat itself, we will ignore it.
-            try:    stat=marshal.loads(v.manage_FTPstat(REQUEST))
+            try:   stat=marshal.loads(v.manage_FTPstat(REQUEST))
             except: stat=None
             if stat is not None:
                 out=out+((k,stat),)
+
         return marshal.dumps(out)   
 
     def manage_FTPstat(self,REQUEST):
@@ -634,8 +661,11 @@
         owner=group='Zope'
         for user, roles in self.get_local_roles():
             if 'Owner' in roles:
-                owner=user
+                # We remove spaces from the username because breaks
+                # the directory listing of some scrubby FTP clients (ajung)
+                owner = string.replace(user," ","")
                 break
+        
         return marshal.dumps((mode,0,0,1,owner,group,0,mtime,mtime,mtime))
 
 
@@ -648,6 +678,21 @@
             if request.maybe_webdav_client and not method in ('GET', 'POST'):
                 return NullResource(self, key, request).__of__(self)
         raise KeyError, key
+
+
+def findChilds(obj,dirname=''):
+    """ recursive walk through the object hierarcy to
+    find all childs of an object (ajung)
+    """
+
+    lst =[] 
+    for name,child in obj.objectItems():
+        if child.meta_type=="Folder":
+            lst.extend(findChilds(child,dirname+ obj.id + '/'))
+        else:
+            lst.append( (dirname + obj.id + "/" + name,child) )
+
+    return lst
 
 
 Globals.default__class_init__(ObjectManager)