On Sat, 2006-08-07 at 17:46 -0230, Rocky Burt wrote:
> On Sat, 2006-08-07 at 15:30 -0400, Tres Seaver wrote:
> > -----BEGIN PGP SIGNED MESSAGE-----
> > Hash: SHA1
> > 
> > Rocky Burt wrote:
> > 
> > > I'm currently investigating registering DirectoryView's from regular
> > > python packages with GenericSetup+skins.xml.  After debugging through
> > > this somewhat I have discovered that minimal paths described in
> > > skins.xml are made relative to $INSTANCE_HOME/Products.  Obviously in a
> > > regular python package (living outside of Products) this means using
> > > minimal paths won't work.  And of course since the actual location of
> > > the py package will vary from deployment to deployment, the logical
> > > approach would be to make the minimal path relative to the package home.
> > > 
> > > Does anyone have any idea's on this?  So far it looks like all other
> > > major cmf functionality can be used outside in a regular python package
> > > (living outside of Products).  Perhaps I'm missing something?  If this
> > > is indeed the case ... would you all entertain a proposal/patch from me
> > > providing a way to use skins from py packages that is b/w compatible
> > > with the current approach?
> > 
> > Hmmm, I thought this was landed already:  I worked that out back in
> > November / December, I think, on the 'tseaver-pkg_resources' branch.
> 
> I just briefly inspected the tseaver-pkg_resources branch and I have a
> few questions/comments:
> 
>  1. was this ever merged into trunk for cmf2.1 inclusion (my brief
> comparisons leads me to believe it was not) ?
> 
>  2. it looks like the branch was put in place to make it so the cmf
> files themselves uses pkg_resources so they can be loaded from eggs and
> the like -- not that the paths pointed to by DirectoryViews could exist
> outside of Products (relative paths I mean)
> 
> Perhaps I'm missing something?
> 
> I'd welcome a technical explanation as to what exactly the branch tried
> to do and the ETA on inclusion into trunk.


Perhaps a patch from my side would more adequately explain what it is
I'm trying to accomplish.

I've attached the patch to this message.  The only thing that is missing
(for me) is tests at this point.


-- 
Rocky Burt
ServerZen Software -- http://www.serverzen.com
News About The Server (blog) -- http://www.serverzen.net

Index: DirectoryView.py
===================================================================
--- DirectoryView.py	(revision 69033)
+++ DirectoryView.py	(working copy)
@@ -16,7 +16,7 @@
 """
 
 import re
-from os import path, listdir, stat
+from os import path, listdir, stat, sep
 from sys import platform
 import logging
 from warnings import warn
@@ -62,6 +62,20 @@
              in listdir(path)
              if name not in ignore and not ignore_re.match(name) ]
 
+def _get_package_path(package):
+    dot = package.rfind('.')
+    if dot > -1:
+        module = __import__(package, globals(), {}, package[dot+1:])
+    else:
+        module = __import__(package, globals(), {})
+    
+    pkg_path = module.__file__
+    # get rid of regular __init__.pyc stuff
+    slash = pkg_path.rfind(sep)
+    pkg_path = pkg_path[:slash]
+    
+    return pkg_path
+
 class _walker:
     def __init__(self, ignore=ignore):
         # make a dict for faster lookup
@@ -394,8 +408,9 @@
     _dirpath = None
     _properties = None
     _objects = ()
+    _package = ''
 
-    def __init__(self, id, dirpath='', fullname=None, properties=None):
+    def __init__(self, id, dirpath='', fullname=None, properties=None, package=None):
         if properties:
             # Since props come from the filesystem, this should be
             # safe.
@@ -404,10 +419,19 @@
         self.id = id
         self._dirpath = dirpath
         self._properties = properties
+        self._package = package
 
     def __of__(self, parent):
         dirpath = self._dirpath
-        info = _dirreg.getDirectoryInfo(dirpath)
+        if self._package:
+            base = _get_package_path(self._package)
+            full = path.join(base, dirpath)
+            if path.exists(full):
+                info = _dirreg.getDirectoryInfo(full)
+            else:
+                info = None
+        else:
+            info = _dirreg.getDirectoryInfo(dirpath)
         if info is None:
             # for DirectoryViews created with CMF versions before 1.5
             # this is basically the old minimalpath() code
@@ -473,10 +497,11 @@
     manage_propertiesForm = DTMLFile( 'dirview_properties', _dtmldir )
 
     security.declareProtected(ManagePortal, 'manage_properties')
-    def manage_properties( self, dirpath, REQUEST=None ):
+    def manage_properties( self, dirpath, package='', REQUEST=None ):
         """ Update the directory path of the DirectoryView.
         """
         self.__dict__['_real']._dirpath = dirpath
+        self.__dict__['_real']._package = package
         if REQUEST is not None:
             REQUEST['RESPONSE'].redirect( '%s/manage_propertiesForm'
                                         % self.absolute_url() )
@@ -502,6 +527,10 @@
     def getDirPath(self):
         return self.__dict__['_real']._dirpath
 
+    security.declareProtected(AccessContentsInformation, 'getPackage')
+    def getPackage(self):
+        return self.__dict__['_real']._package
+
     security.declarePublic('getId')
     def getId(self):
         return self.id
Index: dtml/dirview_properties.dtml
===================================================================
--- dtml/dirview_properties.dtml	(revision 69033)
+++ dtml/dirview_properties.dtml	(working copy)
@@ -19,6 +19,13 @@
  </tr>
 
  <tr>
+  <th> Relative package: </th>
+  <td>
+   <input type="text" name="package" size="40" value="&dtml-getPackage;">
+  </td>
+ </tr>
+
+ <tr>
   <td> <br> </td>
   <td>
    <input type="submit" value=" Update ">
Index: exportimport/skins.py
===================================================================
--- exportimport/skins.py	(revision 69033)
+++ exportimport/skins.py	(working copy)
@@ -44,12 +44,14 @@
         """
         node = self._getObjectNode('object')
         node.setAttribute('directory', self.context.getDirPath())
+        node.setAttribute('package', self.context.getPackage())
         return node
 
     def _importNode(self, node):
         """Import the object from the DOM node.
         """
-        self.context.manage_properties(str(node.getAttribute('directory')))
+        self.context.manage_properties(str(node.getAttribute('directory')),
+                                       str(node.getAttribute('package')))
 
     node = property(_exportNode, _importNode)
 

Attachment: signature.asc
Description: This is a digitally signed message part

_______________________________________________
Zope-CMF maillist  -  Zope-CMF@lists.zope.org
http://mail.zope.org/mailman/listinfo/zope-cmf

See http://collector.zope.org/CMF for bug reports and feature requests

Reply via email to