[Zope-Checkins] CVS: Zope2 - Application.py:1.151

chrism@serenade.digicool.com chrism@serenade.digicool.com
Mon, 18 Jun 2001 16:52:34 -0400


Update of /cvs-repository/Zope2/lib/python/OFS
In directory serenade:/home/chrism/NewZopeOrg/SoftwareHome/lib/python/OFS

Modified Files:
	Application.py 
Log Message:
Changed product import and install code.

Now, when products are installed, they are installed in alphabetical order by product name, regardless of which Products directory (e.g. INSTANCE_HOME or SOFTWARE_HOME) that they're in EXCEPT FOR PluginIndexes, which are always first, due to the requirement that they register interfaces with the product context machinery before ZCatalog is initialized.




--- Updated File Application.py in package Zope2 --
--- Application.py	2001/06/01 19:51:16	1.150
+++ Application.py	2001/06/18 20:52:33	1.151
@@ -500,31 +500,30 @@
                     error=sys.exc_info())
                 get_transaction().abort()
 
+def get_products():
+    """ Return a list of tuples in the form:
+    [(priority, dir_name, base_dir), ...] for each Product directory
+    found, sort before returning """
+    products = []
+    for product_dir in Products.__path__:
+        product_names=os.listdir(product_dir)
+        for name in product_names:
+            priority = (name != 'PluginIndexes') # import PluginIndexes 1st
+            products.append((priority, name, product_dir))
+    products.sort()
+    return products
 
 def import_products():
     # Try to import each product, checking for and catching errors.
     done={}
-
-    for product_dir in Products.__path__:
-
-        product_names=os.listdir(product_dir)
-        product_names.sort()
 
-        # Hack !!!
-        # We must initialize the PluginIndexes first before
-        # all other products (ajung)
+    products = get_products()
 
-        if "PluginIndexes" in product_names:
-            product_names.remove("PluginIndexes")
-            product_names.insert(0,"PluginIndexes")
+    for priority, product_name, product_dir in products:
+        if done.has_key(product_name): continue
+        done[product_name]=1
+        import_product(product_dir, product_name)
 
-        for product_name in product_names:
-
-            if done.has_key(product_name): continue
-            done[product_name]=1
-            import_product(product_dir, product_name)
-
-
 def import_product(product_dir, product_name, raise_exc=0, log_exc=1):
     path_join=os.path.join
     isdir=os.path.isdir
@@ -578,29 +577,18 @@
     get_transaction().note('Prior to product installs')
     get_transaction().commit()
 
-    for product_dir in Products.__path__:
-
-        product_names=os.listdir(product_dir)
-        product_names.sort()
+    products = get_products()
 
-        # Hack !!!
-        # We must initialize the PluginIndexes first before
-        # all other products (ajung)
-
-        if "PluginIndexes" in product_names:
-            product_names.remove("PluginIndexes")
-            product_names.insert(0,"PluginIndexes")
-
-        for product_name in product_names:
-            # For each product, we will import it and try to call the
-            # intialize() method in the product __init__ module. If
-            # the method doesnt exist, we put the old-style information
-            # together and do a default initialization.
-            if done.has_key(product_name):
-                continue
-            done[product_name]=1
-            install_product(app, product_dir, product_name, meta_types,
-                            folder_permissions)
+    for priority, product_name, product_dir in products:
+        # For each product, we will import it and try to call the
+        # intialize() method in the product __init__ module. If
+        # the method doesnt exist, we put the old-style information
+        # together and do a default initialization.
+        if done.has_key(product_name):
+            continue
+        done[product_name]=1
+        install_product(app, product_dir, product_name, meta_types,
+                        folder_permissions)
 
     Products.meta_types=Products.meta_types+tuple(meta_types)
     Globals.default__class_init__(Folder.Folder)