[Zope-CVS] CVS: Products/Basket - monkeypatches.py:1.1 __init__.py:1.25 basket.py:1.6

Chris McDonough chrism at plope.com
Sat Nov 26 16:41:14 EST 2005


Update of /cvs-repository/Products/Basket
In directory cvs.zope.org:/tmp/cvs-serv16148

Modified Files:
	__init__.py basket.py 
Added Files:
	monkeypatches.py 
Log Message:
Add five product tests, external method tests, and fix a bug where StringIO was not properly imported and pkg_module was not passed in to a function which only used it in an error condition.

Rocky Burt contributed all external method fixes.


=== Added File Products/Basket/monkeypatches.py ===
from App import Extensions
import os

def patch_externalmethod(thebasket):
    """In an effort to make External Methods work with Basket, this function
    replaces App.Extensions.getPath with a custom getPath function.  See
    the getPath doc string for extra details. (Thanks to Rocky Burt)
    """
    
    _originalGetPath = Extensions.getPath
    
    def getPath(prefix, name, checkProduct=1, suffixes=('',)):
        """This getPath implementation checks the real getPath function for
        a result before it does any of its work.  If result returned is None
        it then proceeds to return the result of getEggedPath. (The original
        getPath only checked physical Product directories in the instance
        home).
        """

        result = _originalGetPath(prefix, name, checkProduct, suffixes)
        
        if result is None and checkProduct:
            result = getEggedPath(thebasket, prefix, name, suffixes)
        
        return result
    
    Extensions.getPath = getPath

def getEggedPath(basket, prefix, name, suffixes):
    """
    Checks all exploded Basket egg dirs for the path defined by the given
    args.
    """

    result = None

    l = name.find('.')
    if l > 0:
        realPrefix = os.path.join(name[:l], prefix)
        realName = name[l + 1:]

        # lets check all of the recorded tempdirs for exploded eggs
        for tempdir in basket.tempdirs:
            # now lets check the actual exploded egg dirs
            for product_dir in os.listdir(tempdir):
                product_dir = os.path.join(tempdir, product_dir)
                
                result = Extensions._getPath(product_dir, realPrefix, 
                                             realName, suffixes)
                if result is not None:
                    break
            if result is not None:
                break
    
    return result
    



=== Products/Basket/__init__.py 1.24 => 1.25 ===
--- Products/Basket/__init__.py:1.24	Fri Nov 11 15:50:29 2005
+++ Products/Basket/__init__.py	Sat Nov 26 16:40:44 2005
@@ -30,6 +30,10 @@
 from Products.Basket.basket import Basket
 
 the_basket = Basket()
+# do required monkeypatches
+import monkeypatches
+monkeypatches.patch_externalmethod(the_basket)
+
 the_basket.preinitialize()
 initialize = the_basket.initialize
 


=== Products/Basket/basket.py 1.5 => 1.6 ===
--- Products/Basket/basket.py:1.5	Fri Nov 11 15:50:29 2005
+++ Products/Basket/basket.py	Sat Nov 26 16:40:44 2005
@@ -6,6 +6,7 @@
 import shutil
 import tempfile
 import unzip
+from StringIO import StringIO
 
 import zLOG
 
@@ -74,7 +75,8 @@
                     continue
                 
             productname = product_pkg.__name__.split('.')[-1]
-            initializer = get_initializer(point, productname, debug_mode)
+            initializer = get_initializer(point, productname, product_pkg,
+                                          debug_mode)
             context = EggProductContext(productname, initializer, app,
                                         product_pkg, eggtitle)
             returned = context.install(debug_mode)
@@ -162,7 +164,7 @@
         return None
     return get_containing_package(new)
 
-def get_initializer(point, productname, debug_mode):
+def get_initializer(point, productname, product_pkg, debug_mode):
     initializer = None
     try:
         # this will raise an import error if the initializer can't
@@ -173,7 +175,8 @@
                  error = sys.exc_info())
         f = StringIO()
         limit = 100 # limit to 100 stack trace entries
-        product_pkg.__import_error__ = traceback.print_exc(limit, f).getvalue()
+        traceback.print_exc(limit, f)
+        product_pkg.__import_error__ = f.getvalue()
         if debug_mode:
             raise
     return initializer



More information about the Zope-CVS mailing list