[Zope] FTP for ZClass hierarchies

Tres Seaver tseaver@digicool.com
Thu, 07 Dec 2000 22:34:52 -0500


This is a multi-part message in MIME format.
--------------C1ED89E9794973BDAA31E20A
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit

Robin Becker <robin@jessikat.fsnet.co.uk> wrote:
> 
> M. Adam Kendall <mak@kha0s.org> writes
> >In the past few days I have been working on a patch that will
> >let you edit ZClasses via FTP without the need for typing in
> >actual pathnames to get to the methods (mainly so I can edit
> >ZClasses with HTML-Kit).  Strangely enough, even with the 
> >modifications, I see this same thing.
> >
> >I've included this patch in case anyone wants to play around
> >with it.  It's not the greatest, and definitely needs to be
> >modified (some of the security mechanisms are bound to be 
> >broken).  But it is a start anyway. ;)  
>
> Does this let you write the methods back?

I was just able to change a DTML method in a ZClass (after patching
a single indentation error).  Adam, you rock!

I am attaching my emended patch.

Tres.
-- 
===============================================================
Tres Seaver                                tseaver@digicool.com
Digital Creations     "Zope Dealers"       http://www.zope.org
--------------C1ED89E9794973BDAA31E20A
Content-Type: text/plain; charset=us-ascii;
 name="ZClass_FTP.patch"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
 filename="ZClass_FTP.patch"

Index: Method.py
===================================================================
RCS file: /cvs-repository/Zope2/lib/python/ZClasses/Method.py,v
retrieving revision 1.18
diff -u -r1.18 Method.py
--- Method.py	2000/08/14 14:34:23	1.18
+++ Method.py	2000/12/08 03:43:29
@@ -92,6 +92,8 @@
 import ZClassOwner
 from AccessControl.PermissionMapping import aqwrap, PermissionMapper
 
+import marshal
+
 _marker=[]
 class ZClassMethodsSheet(
     OFS.PropertySheets.PropertySheet,
@@ -104,6 +106,13 @@
     icon='p_/Methods_icon'
 
     def tpURL(self): return 'propertysheets/methods'
+
+    def manage_FTPstat(self,REQUEST):
+        "Psuedo stat used for FTP listings"
+        mode=0040000|0770
+        mtime=self.bobobase_modification_time().timeTime()
+        owner=group='Zope'
+        return marshal.dumps((mode,0,0,1,owner,group,0,mtime,mtime,mtime))
 
     ######################################################################
     # Hijinks to let us create factories and classes within classes.
Index: ZClass.py
===================================================================
RCS file: /cvs-repository/Zope2/lib/python/ZClasses/ZClass.py,v
retrieving revision 1.50
diff -u -r1.50 ZClass.py
--- ZClass.py	2000/11/01 22:59:34	1.50
+++ ZClass.py	2000/12/08 03:43:31
@@ -91,8 +91,9 @@
 from ExtensionClass import Base
 from App.FactoryDispatcher import FactoryDispatcher
 from ComputedAttribute import ComputedAttribute
-import OFS.PropertySheets
 
+import marshal
+
 if not hasattr(Products, 'meta_types'):
     Products.meta_types=()
 
@@ -281,6 +282,28 @@
          ('', '__call__', 'index_html', 'createInObjectManager')),
         )
 
+    def manage_FTPlist(self,REQUEST):
+        "Directory listing for FTP"
+        out=()
+        files=self.__dict__.items()
+        if not (hasattr(self,'isTopLevelPrincipiaApplicationObject') and
+                self.isTopLevelPrincipiaApplicationObject):
+             files.insert(0,('..',self.aq_parent))
+        for k,v in files:
+            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):
+        "Psuedo stat used for FTP listings"
+        mode=0040000|0770
+        mtime=self.bobobase_modification_time().timeTime()
+        owner=group='Zope'
+        return marshal.dumps((mode,0,0,1,owner,group,0,mtime,mtime,mtime))
+
     def __init__(self, id, title, bases, zope_object=1):
         """Build a Zope class
 
@@ -640,6 +663,28 @@
     views       = Basic.ZClassViewsSheet('views')
     basic       = Basic.ZClassBasicSheet('basic')
     permissions = Basic.ZClassPermissionsSheet('permissions')
+
+    def manage_FTPlist(self,REQUEST):
+        "Directory listing for FTP"
+        out=()
+        files=self.__dict__.items()
+        if not (hasattr(self,'isTopLevelPrincipiaApplicationObject') and
+                self.isTopLevelPrincipiaApplicationObject):
+             files.insert(0,('..',self.aq_parent))
+        for k,v in files:
+            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):
+        "Psuedo stat used for FTP listings"
+        mode=0040000|0770
+        mtime=self.bobobase_modification_time().timeTime()
+        owner=group='Zope'
+        return marshal.dumps((mode,0,0,1,owner,group,0,mtime,mtime,mtime))
 
     def __init__(self):
         self.methods=Method.ZClassMethodsSheet('methods')

--------------C1ED89E9794973BDAA31E20A--